Beispiel #1
0
        /// <summary>
        /// Replace a cell with an other cell, and delete the old, component and gameobject.
        /// </summary>
        /// <param name="source">The source gameobject, can be a prefab or an existing gameObject.</param>
        /// <param name="grid">The grid of the old cell.</param>
        /// <param name="old">The old cell to replace.</param>
        /// <returns>The cell component of the new gameobject.</returns>
        public static Core.Cell ReplaceCell(GameObject source, Grid3D grid, Core.Cell old)
        {
            Undo.SetCurrentGroupName("Replace Cell");
            int group = Undo.GetCurrentGroup();

            GameObject prefab = source;

            if (IsGameObjectInstancePrefab(source))
            {
                prefab = GetPrefabFromInstance(source);
            }

            GameObject gameObject = PrefabUtility.InstantiatePrefab(prefab, grid.transform) as GameObject;

            Vector3Int index = old.GetIndex();

            gameObject.transform.position = old.transform.position;
            gameObject.name = gameObject.name + "_" + index.x + "_" + index.y + "_" + index.z;

            Core.Cell cell = gameObject.GetComponent <Core.Cell>();
            if (cell == null)
            {
                gameObject.AddComponent <Core.Cell>();
            }
            grid.ReplaceCell(index, cell);
            Undo.RegisterCreatedObjectUndo(cell.gameObject, "Cell replaced");
            Undo.DestroyObjectImmediate(old.gameObject);
            Undo.CollapseUndoOperations(group);
            /***** my code ******/
            cell.tileX = index.x;
            cell.tileY = index.z;
            /********************/
            return(cell);
        }
Beispiel #2
0
 public static void DebugEmptyCell(Core.Cell cell, GizmoType gizmoType)
 {
     if (LayerMask.NameToLayer("EmptyCell") == cell.gameObject.layer)
     {
         DebugCell(cell.GetIndex(), cell.GetGridParent(), DebugsColor.empty_cell, -0.01f);
     }
 }
Beispiel #3
0
        public CellDTO(Core.Cell cell)
        {
            GameObject prefab = FuncEditor.GetPrefabFromInstance(cell.gameObject);

            _pathPrefab    = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(prefab);
            _index         = cell.GetIndex();
            _localposition = cell.transform.localPosition;
            _localrotation = cell.transform.localRotation.eulerAngles;
            _localscale    = cell.transform.localScale;
        }
Beispiel #4
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            if (_cell.transform.hasChanged && _cell.GetGridParent() != null)
            {
                Grid3D grid = _cell.GetGridParent();
                _cell.Initialize(_cell.GetIndex(), grid);
            }
            if (GUILayout.Button("Reset transform"))
            {
                _cell.ResetTransform();
            }
            if (GUILayout.Button("Go parent"))
            {
                Selection.SetActiveObjectWithContext(_cell.transform.parent, null);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Gizmo for debuging the neighbours of a cell.
 /// </summary>
 /// <param name="cell">The cell use to compute neighbours.</param>
 /// <param name="color">Color of the gizmo.</param>
 /// <param name="offsetSize"> The scale amount add to the grid size cell.</param>
 public static void DebugNeigbours(Core.Cell cell, Color color, float offsetSize = 0.01f)
 {
     DebugNeigbours(cell.GetIndex(), cell.GetGridParent(), color, offsetSize);
 }