Kaynağa Gözat

调整地图大小,鼠标中键拖动

wgl 8 ay önce
ebeveyn
işleme
2d2d2ffd06

+ 30 - 6
ActionTowerDefense/Assets/GameLevelEditor/GameMap/Sample/Scripts/Main.cs

@@ -9,6 +9,7 @@ public class Main : MonoBehaviour
 	#region properties
 
 	[SerializeField] public float tileSize = 32f;
+	[SerializeField] public float offset;
 	[SerializeField] public float ppu = 100f;
 
 	[Space]
@@ -18,6 +19,11 @@ public class Main : MonoBehaviour
 	[SerializeField] public GameObject[] npcFabs;
 	[SerializeField] public GameObject[] trapFabs;
 
+	[Space]
+	public Transform parent;
+	public float dragSpeed = 2.0f; // 拖动速度
+	[HideInInspector] public Vector3 dragOrigin; // 拖动起始点
+
 	[HideInInspector] public Transform floorContainer;
 	[HideInInspector] public Transform npcContainer;
 	[HideInInspector] public Transform trapContainer;
@@ -37,25 +43,43 @@ public class Main : MonoBehaviour
         {
 			LoadMap(0);
         }
-    }
 
-    // an example of how map data could be loaded
-    private void LoadMap(int mapIdx)
+		if (Input.GetMouseButtonDown(2))
+		{
+			dragOrigin = Input.mousePosition;
+			return;
+		}
+
+		if (Input.GetMouseButton(2))
+		{
+			Vector3 offset = Camera.main.ScreenToViewportPoint(dragOrigin - Input.mousePosition);
+			Vector3 move = dragSpeed * offset.x * Vector3.right;
+
+			Camera.main.transform.Translate(move, Space.World);
+
+
+			dragOrigin = Input.mousePosition;
+		}
+	}
+
+	// an example of how map data could be loaded
+	private void LoadMap(int mapIdx)
 	{
 		GameMap map = mapsAsset.maps[mapIdx];
 
 		float sz = tileSize / ppu;
 		float offsX = -((map.width / 2f * sz) - (sz / 2f));
-		offsX = 0;
-		float offsY = -((map.height / 2f * sz) - (sz / 2f));
-		offsY = 0;
+		float offsY = -offset;
 
         // create containers for the various map objects
         if (!floorContainer)
         {
 			floorContainer = new GameObject("Tiles").transform;
+			floorContainer.SetParent(parent, false);
 			npcContainer = new GameObject("NPCs").transform;
+			npcContainer.SetParent(parent, false);
 			trapContainer = new GameObject("Traps").transform;
+			trapContainer.SetParent(parent, false);
         }
         else
         {

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
ActionTowerDefense/Assets/GameLevelEditor/maps.asset


+ 37 - 2
ActionTowerDefense/Assets/Scenes/Editor.unity

@@ -2655,6 +2655,37 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   m_Padding: {x: -8, y: -5, z: -8, w: -5}
   m_Softness: {x: 0, y: 0}
+--- !u!1 &994432911
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 994432912}
+  m_Layer: 0
+  m_Name: Container
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &994432912
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 994432911}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 2
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &1020303518
 GameObject:
   m_ObjectHideFlags: 0
@@ -6863,7 +6894,7 @@ Camera:
   m_Enabled: 1
   serializedVersion: 2
   m_ClearFlags: 2
-  m_BackGroundColor: {r: 0.31617647, g: 0.22085857, b: 0.22085857, a: 1}
+  m_BackGroundColor: {r: 0.2784314, g: 0.2784314, b: 0.2784314, a: 1}
   m_projectionMatrixMode: 1
   m_GateFitMode: 2
   m_FOVAxisMode: 0
@@ -6957,7 +6988,8 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: bde5bd8db153fb4429aabdfecbf3e3c3, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  tileSize: 32
+  tileSize: 64
+  offset: 0.5
   ppu: 100
   mapsAsset: {fileID: 11400000, guid: bbf7388a54f14f842b7aecb67d709046, type: 2}
   playerFab: {fileID: 1105382562349734, guid: 97291c76034a8e34b8a667b05b74c993, type: 3}
@@ -6967,6 +6999,9 @@ MonoBehaviour:
   - {fileID: 1495283989979954, guid: 606d546f72896eb4eb1f4577b3b4738b, type: 3}
   trapFabs:
   - {fileID: 1773518891763322, guid: c85322fd118b50e429fd10d18407311b, type: 3}
+  parent: {fileID: 0}
+  dragSpeed: 10
+  dragOrigin: {x: 0, y: 0, z: 0}
   floorContainer: {fileID: 0}
   npcContainer: {fileID: 0}
   trapContainer: {fileID: 0}

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor