Browse Source

Added basic building connectors data

James Peret 2 years ago
parent
commit
9476663608

+ 3 - 1
Runtime/BuildingTemplate.cs

@@ -18,6 +18,8 @@ namespace KairoEngine.VoxelBuildingSystem
         [BoxGroup("Properties")] public Sprite icon;
         [BoxGroup("Properties"), TextArea(2, 8), HideLabel, PropertySpace(4, 4)] public string description;
 
-        [PropertySpace(1, 1)] public List<Stockpile> cost = new List<Stockpile>();
+        public List<VoxelConnectorData> connectors = new List<VoxelConnectorData>();
+
+        public List<Stockpile> cost = new List<Stockpile>();
     }
 }

+ 69 - 1
Runtime/VoxelBuildingSystem.cs

@@ -27,6 +27,8 @@ namespace KairoEngine.VoxelBuildingSystem
         [ReadOnly] public int currentRotationIndex;
 
         [ReadOnly] public VoxelBuildingTool tool = VoxelBuildingTool.Build;
+
+        [ReadOnly] public List<Vector3Int> rotationList = new List<Vector3Int>();
         public ChunkSystem<VoxelBuildData> chunkSystem;
         [HideInInspector] public Dictionary<Vector3Int, BuildingBehaviour> buildings = new Dictionary<Vector3Int, BuildingBehaviour>();
         [HideInInspector] public List<BuildingBehaviour> buildingList = new List<BuildingBehaviour>();
@@ -188,7 +190,6 @@ namespace KairoEngine.VoxelBuildingSystem
             return positionList;
         }
 
-        public List<Vector3Int> rotationList = new List<Vector3Int>();
         private void SetupRotationList()
         {
             rotationList = new List<Vector3Int>
@@ -212,6 +213,73 @@ namespace KairoEngine.VoxelBuildingSystem
             }
         }
         
+        public Vector3Int GetConnectorPositionOffset(VoxelConnectorData connector, Vector3Int size, int rotationIndex)
+        {
+            Vector3Int pos = connector.position;
+            switch (rotationIndex)
+            {
+                default:
+                case 0:  return connector.position;
+                case 1:  return new Vector3Int(pos.z, pos.y, (pos.x * -1) + size.x - 1);
+                case 2:  return new Vector3Int((pos.x * -1) + size.x - 1, pos.y, (pos.z * -1) + size.z - 1);
+                case 3:  return new Vector3Int((pos.z * -1) + size.z - 1, pos.y, pos.x);
+            }
+            // switch (connector.direction)
+            // {
+            //     default:
+            //     case TargetDirection.Back:  return connector.position;
+            //     case TargetDirection.Left:  return new Vector3Int(pos.z, pos.y, (pos.x * -1) + size.x - 1);
+            //     case TargetDirection.Front:    return new Vector3Int((pos.x * -1) + size.x - 1, pos.y, (pos.z * -1) + size.z - 1);
+            //     case TargetDirection.Right: return new Vector3Int((pos.z * -1) + size.z - 1, pos.y, pos.x);
+            //     case TargetDirection.Up:  return new Vector3Int(pos.x, (pos.y * -1) + size.y - 1, pos.z);
+            //     case TargetDirection.Down:  return new Vector3Int(pos.x, pos.y * -1, pos.z);
+            // }
+        }
+
+        public Vector3Int GetPositionOffsetFromDirection(int rotationIndex, VoxelConnectorData connector)
+        {
+            switch (rotationIndex)
+            {
+                default:
+                case 0:  
+                    switch (connector.direction)
+                    {
+                        default:
+                        case TargetDirection.Down:  return new Vector3Int(0, 0, -1);
+                        case TargetDirection.Left:  return new Vector3Int(-1, 0, 0);
+                        case TargetDirection.Up:    return new Vector3Int(0, 0, 1);
+                        case TargetDirection.Right: return new Vector3Int(1, 0, 0);
+                    }
+                case 1:  
+                    switch (connector.direction)
+                    {
+                        default:
+                        case TargetDirection.Down:  return new Vector3Int(-1, 0, 0);
+                        case TargetDirection.Left:  return new Vector3Int(0, 0, 1);
+                        case TargetDirection.Up:    return new Vector3Int(1, 0, 0);
+                        case TargetDirection.Right: return new Vector3Int(0, 0, -1);
+                    }
+                case 2:    
+                    switch (connector.direction)
+                    {
+                        default:
+                        case TargetDirection.Down:  return new Vector3Int(0, 0, 1);
+                        case TargetDirection.Left:  return new Vector3Int(1, 0, 0);
+                        case TargetDirection.Up:    return new Vector3Int(0, 0, -1);
+                        case TargetDirection.Right: return new Vector3Int(-1, 0, 0);
+                    }
+                case 3: 
+                    switch (connector.direction)
+                    {
+                        default:
+                        case TargetDirection.Down:  return new Vector3Int(1, 0, 0);
+                        case TargetDirection.Left:  return new Vector3Int(0, 0, -1);
+                        case TargetDirection.Up:    return new Vector3Int(-1, 0, 0);
+                        case TargetDirection.Right: return new Vector3Int(0, 0, 1);
+                    }
+            }
+        }
+
     }
 
     public enum VoxelBuildingTool

+ 29 - 0
Runtime/VoxelConnectorData.cs

@@ -0,0 +1,29 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using Sirenix.OdinInspector;
+
+namespace KairoEngine.VoxelBuildingSystem
+{
+    [System.Serializable]
+    public class VoxelConnectorData
+    {
+        [HideLabel, HorizontalGroup("connector", 0.3f)] public string title = "new connector";
+        [HideLabel, HorizontalGroup("connector", 0.2f)] public Vector3Int position;
+        //[HideLabel, HorizontalGroup("connector", 0.2f)] public Vector3Int target;
+        [HideLabel, HorizontalGroup("connector", 0.15f)] public TargetDirection direction;
+        [HideLabel, HorizontalGroup("connector", 0.15f)] public int group;
+
+    }
+
+    public enum TargetDirection
+    {
+            Back,
+            Front,
+            Left,
+            Right,
+            Up,
+            Down
+        }
+}
+

+ 11 - 0
Runtime/VoxelConnectorData.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b54cf3eb2605cf8419689c74c5391ab9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: