Exemple #1
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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Instantiate a cell with a prefab as model.
        /// </summary>
        /// <param name="prefab">The prefab to instantiate as a cell.</param>
        /// <param name="grid">The grid the cell will belongs.</param>
        /// <param name="index"> The index of the cell.</param>
        /// <returns>The cell component associated to the gameobject.</returns>
        public static Core.Cell InstantiateCell(GameObject prefab, Grid3D grid, Vector3Int index)
        {
            GameObject gameObject = PrefabUtility.InstantiatePrefab(prefab, grid.transform) as GameObject;

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

            Core.Cell cell = gameObject.GetComponent <Core.Cell>();
            if (cell == null)
            {
                cell = gameObject.AddComponent <Core.Cell>();
            }
            grid.AddCell(index, cell);
            cell.ResetTransform();
            /***** my code ******/
            cell.tileX = index.x;
            cell.tileY = index.z;
            /********************/
            Undo.RegisterCreatedObjectUndo(cell.gameObject, "Cell created");
            return(cell);
        }