Преглед на файлове

Before changes 2023-02-15

Axel Nordh преди 3 години
родител
ревизия
f26e9b33c9

+ 2 - 2
Assets/Prefabs/Building/ScriptableObjects/Ghost.cs

@@ -4,7 +4,6 @@ using UnityEngine;
 
 public class Ghost : MonoBehaviour {
     private Transform visual;
-    private PlacedObjectTypeSO placedObjectTypeSO;
 
     private void Start() {
         RefreshVisual();
@@ -19,8 +18,9 @@ public class Ghost : MonoBehaviour {
     private void LateUpdate() {
         Vector3 targetPosition = GroundGridControllerScript.Instance.GetMouseWorldSnappedPosition();
         targetPosition.y = 1f;
-        transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * 15f);
+        Vector2Int rotationOffset = GroundGridControllerScript.Instance.GetPlacedObjectRotationOffset();
 
+        transform.position = Vector3.Lerp(transform.position, targetPosition + new Vector3(rotationOffset.x, 0, rotationOffset.y) * GroundGridControllerScript.Instance.GetGridXZ().GetCellSize(), Time.deltaTime * 15f);
         transform.rotation = Quaternion.Lerp(transform.rotation, GroundGridControllerScript.Instance.GetPlacedObjectRotation(), Time.deltaTime * 15f);
     }
 

+ 2 - 0
Assets/Prefabs/Building/ScriptableObjects/PlacedObjectTypeSO.cs

@@ -31,6 +31,8 @@ public class PlacedObjectTypeSO : ScriptableObject {
     public string ButtonText;
     public ObjectCategory category;
 
+    public bool sameNodeBuldable = false;
+
     public enum ObjectCategory {
         Wall,
         Decoration

+ 1 - 1
Assets/Prefabs/Building/Wall/WallGameObject.prefab

@@ -27,7 +27,7 @@ Transform:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 4351236791469182115}
   m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068}
-  m_LocalPosition: {x: 0.5, y: 0.5, z: -0}
+  m_LocalPosition: {x: 0.5, y: 0.5, z: 0}
   m_LocalScale: {x: 1, y: 0.1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []

+ 25 - 1
Assets/Scripts/Ground/BuildingGridNode.cs

@@ -23,9 +23,33 @@ public class BuildingGridNode {
         grid.TriggerGridObjectChanged(x, z);
     }
 
-    public bool CanBuild() {
+    // Needs to be aböe to replace with corner transfom depending on other placed transform and the new one
+    public bool CanBuild(PlacedObjectTypeSO newObject) {
         if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) return false; // Check if over UI element
+
+        /* This is not working, can't compare the rotations yet
+          BuildingGridNode bgn = grid.GetGridObject(x, z);
+          if (bgn != null) {
+              Debug.Log("building Grid Node rotation" + bgn +
+              " new Object Visual Rotation " + newObject.visual.rotation +
+              " new Object Prefab Rotation " + newObject.prefab.rotation);
+          }
+
+          Debug.Log(transform != null ? transform.gameObject.GetType() : "");
+          if (transform != null) {
+              if (transform.childCount > 0) {
+                  for (int i = 0; i < transform.childCount; i++) {
+                      if (transform.GetChild(i).rotation == newObject.prefab.transform.rotation) {
+                          Debug.Log("transform rotation " + transform.GetChild(i).rotation + " newObject rotation " + newObject.prefab.rotation);
+                          return false;
+                      }
+                  }
+                  return true;
+              }
+          }
+          */
         return transform == null;
+
     }
 
     public override string ToString() {

+ 3 - 3
Assets/Scripts/Ground/GroundGridControllerScript.cs

@@ -70,7 +70,7 @@ public class GroundGridControllerScript : MonoBehaviour {
             if (x >= 0 && z >= 0) {
                 List<Vector2Int> gridPositionList = activePlacedObjectTypeSO.GetGridPositionList(new Vector2Int(x, z), dir);
 
-                if (gridPositionList.TrueForAll(p => ((BuildingGridNode)grid.GetGridObject(p.x, p.y)).CanBuild())) {
+                if (gridPositionList.TrueForAll(p => ((BuildingGridNode)grid.GetGridObject(p.x, p.y)).CanBuild(activePlacedObjectTypeSO))) {
                     Vector2Int rotationOffset = activePlacedObjectTypeSO.GetRotationOffset(dir);
                     Vector3 placedObejctWorldPosition = grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, 0, rotationOffset.y) * grid.GetCellSize();
 
@@ -87,7 +87,7 @@ public class GroundGridControllerScript : MonoBehaviour {
                     UtilsClass.CreateWorldTextPopup("Connot build here!", GetMousePosition3d());
                 }
             }
-        } else if (Input.GetMouseButtonDown(1)) {
+        } else if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Escape)) {
             DeselectObjectType();
         }
 
@@ -101,7 +101,7 @@ public class GroundGridControllerScript : MonoBehaviour {
         OnSelectedChanged?.Invoke(this, EventArgs.Empty);
     }
 
-    private Vector3 GetMousePosition3d() {
+    public Vector3 GetMousePosition3d() {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         Physics.Raycast(ray, out RaycastHit raycastHit, 999f, mousePlaneLayerMask);
 

+ 14 - 0
ProjectSettings/BurstAotSettings_Android.json

@@ -0,0 +1,14 @@
+{
+  "MonoBehaviour": {
+    "Version": 4,
+    "EnableBurstCompilation": true,
+    "EnableOptimisations": true,
+    "EnableSafetyChecks": false,
+    "EnableDebugInAllBuilds": false,
+    "CpuMinTargetX32": 0,
+    "CpuMaxTargetX32": 0,
+    "CpuMinTargetX64": 0,
+    "CpuMaxTargetX64": 0,
+    "OptimizeFor": 0
+  }
+}

+ 16 - 0
ProjectSettings/BurstAotSettings_StandaloneWindows.json

@@ -0,0 +1,16 @@
+{
+  "MonoBehaviour": {
+    "Version": 4,
+    "EnableBurstCompilation": true,
+    "EnableOptimisations": true,
+    "EnableSafetyChecks": false,
+    "EnableDebugInAllBuilds": false,
+    "CpuMinTargetX32": 0,
+    "CpuMaxTargetX32": 0,
+    "CpuMinTargetX64": 0,
+    "CpuMaxTargetX64": 0,
+    "CpuTargetsX32": 6,
+    "CpuTargetsX64": 72,
+    "OptimizeFor": 0
+  }
+}

+ 6 - 0
ProjectSettings/CommonBurstAotSettings.json

@@ -0,0 +1,6 @@
+{
+  "MonoBehaviour": {
+    "Version": 4,
+    "DisabledWarnings": ""
+  }
+}

+ 4 - 2
ProjectSettings/ProjectSettings.asset

@@ -154,7 +154,8 @@ PlayerSettings:
   resetResolutionOnWindowResize: 0
   androidSupportedAspectRatio: 1
   androidMaxAspectRatio: 2.1
-  applicationIdentifier: {}
+  applicationIdentifier:
+    Standalone: com.DefaultCompany.RoomBuilder
   buildNumber:
     Standalone: 0
     iPhone: 0
@@ -718,7 +719,8 @@ PlayerSettings:
   gcIncremental: 1
   assemblyVersionValidation: 1
   gcWBarrierValidation: 0
-  apiCompatibilityLevelPerPlatform: {}
+  apiCompatibilityLevelPerPlatform:
+    Standalone: 6
   m_RenderingPath: 1
   m_MobileRenderingPath: 1
   metroPackageName: Template_3D

+ 16 - 0
ProjectSettings/TimelineSettings.asset

@@ -0,0 +1,16 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!114 &1
+MonoBehaviour:
+  m_ObjectHideFlags: 61
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  assetDefaultFramerate: 60
+  m_DefaultFrameRate: 60