From 476a64517683b5fb43aaec80739a16163cf141b8 Mon Sep 17 00:00:00 2001
From: Adrian Paschkowski <git@wasdennnoch.me>
Date: Thu, 15 Apr 2021 12:56:45 +0200
Subject: [PATCH] Scale enemy previews with zoom

---
 Assets/Scenes/Forest.unity                   | 16 ++--------------
 Assets/Scripts/BaseCameraController.cs       |  2 +-
 Assets/Scripts/Store/EnemySpawnController.cs |  8 +++++++-
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/Assets/Scenes/Forest.unity b/Assets/Scenes/Forest.unity
index b3faf4b..a130338 100644
--- a/Assets/Scenes/Forest.unity
+++ b/Assets/Scenes/Forest.unity
@@ -1230,19 +1230,7 @@ MonoBehaviour:
   - eventID: 5
     callback:
       m_PersistentCalls:
-        m_Calls:
-        - m_Target: {fileID: 1642190547}
-          m_TargetAssemblyTypeName: EnemySpawnController, Assembly-CSharp
-          m_MethodName: OnEnemyDrag
-          m_Mode: 1
-          m_Arguments:
-            m_ObjectArgument: {fileID: 0}
-            m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-            m_IntArgument: 0
-            m_FloatArgument: 0
-            m_StringArgument: Bandit
-            m_BoolArgument: 0
-          m_CallState: 2
+        m_Calls: []
   - eventID: 13
     callback:
       m_PersistentCalls:
@@ -2908,7 +2896,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
-  m_AnchoredPosition: {x: 490, y: -374}
+  m_AnchoredPosition: {x: -766.8, y: 346.7}
   m_SizeDelta: {x: 100, y: 100}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1642190547
diff --git a/Assets/Scripts/BaseCameraController.cs b/Assets/Scripts/BaseCameraController.cs
index 8ff56f2..272657c 100644
--- a/Assets/Scripts/BaseCameraController.cs
+++ b/Assets/Scripts/BaseCameraController.cs
@@ -35,7 +35,7 @@ public class BaseCameraController : MonoBehaviour
     Interpolator yInputInterpolator;
     InterpolatorQueue xPositionInterpolator;
     InterpolatorQueue yPositionInterpolator;
-    float zoomRatio // Move slower when zoomed in
+    public float zoomRatio // Move slower when zoomed in
     {
         get => camera.orthographicSize / maxZoom;
     }
diff --git a/Assets/Scripts/Store/EnemySpawnController.cs b/Assets/Scripts/Store/EnemySpawnController.cs
index 1539dc2..e9fede1 100644
--- a/Assets/Scripts/Store/EnemySpawnController.cs
+++ b/Assets/Scripts/Store/EnemySpawnController.cs
@@ -8,18 +8,20 @@ public class EnemySpawnController : MonoBehaviour
 
     [SerializeField] List<Opponent> enemyList;
     [SerializeField] List<Image> enemySprites;
+    [SerializeField] GameObject dragObject;
 
     Dictionary<Opponent, Image> enemies = new Dictionary<Opponent, Image>();
 
     float mana;
 
     Opponent activeSpawn;
-    [SerializeField] GameObject dragObject;
     GameObject enemyImage;
+    BaseCameraController cameraController;
 
     private void Awake()
     {
         mana = -1;
+        cameraController = Camera.main.GetComponent<BaseCameraController>();
 
         for (int i = 0; i < enemyList.Count; i++)
         {
@@ -36,6 +38,7 @@ public class EnemySpawnController : MonoBehaviour
             mana = actualMana;
             ChangeActiveState();
         }
+        OnEnemyDrag();
     }
 
     void ChangeActiveState()
@@ -71,6 +74,7 @@ public class EnemySpawnController : MonoBehaviour
         {
             dragObject.GetComponent<Image>().sprite = activeSpawn.EnemySprite;
             enemyImage = Instantiate(dragObject, GetPreviewWorldPosition(), Quaternion.identity, transform);
+            OnEnemyDrag();
         }
     }
 
@@ -79,6 +83,8 @@ public class EnemySpawnController : MonoBehaviour
         if (enemyImage != null)
         {
             enemyImage.transform.position = GetPreviewWorldPosition();
+            var zoomRatio = 1 / cameraController.zoomRatio;
+            enemyImage.transform.localScale = new Vector3(zoomRatio, zoomRatio, zoomRatio);
         }
     }
 
-- 
GitLab