예제 #1
0
        /// <summary>
        /// Deletes the given object.
        /// </summary>
        public void DeleteObject(GameObject obj,
                                 LevelEditorAction.ActionType actionType)
        {
            // Get database index of object
            byte deletedObjectIndex = (byte)ObjectIndexOfObject(obj);
            int  levelIndex         = LevelIndexOfObject(obj);

            // Update undo/redo stack
            var deleteAction = new DeleteObjectAction(obj, deletedObjectIndex);

            switch (actionType)
            {
            case LevelEditorAction.ActionType.Normal:
            case LevelEditorAction.ActionType.Redo:
                undoStack.Push(deleteAction);
                break;

            case LevelEditorAction.ActionType.Undo:
                redoStack.Push(
                    new CreateObjectAction(deletedObjectIndex, obj));
                break;
            }

            // Delete object from level
            loadedLevel.DeleteObject(levelIndex);

            // Delete spawner
            objectCounts[deletedObjectIndex]--;
            loadedSpawners.Remove(obj.GetComponent <ObjectSpawner>());
            DestroyLoadedObject(obj);
            dirty = true;
        }
예제 #2
0
        /// <summary>
        /// Sets an object's 3D scale.
        /// </summary>
        public void SetObject3DScale(GameObject obj, Vector3 scale,
                                     LevelEditorAction.ActionType actionType)
        {
            var attribs = AttributesOfObject(obj);

            attribs.Set3DScale(scale);
            obj.transform.localScale = scale;
        }
예제 #3
0
        /// <summary>
        /// Sets an object's Euler rotation.
        /// </summary>
        public void SetObjectEulerRotation(GameObject obj, Vector3 rot,
                                           LevelEditorAction.ActionType actionType)
        {
            var attribs = AttributesOfObject(obj);

            attribs.SetEulerRotation(rot);
            obj.transform.localRotation = Quaternion.Euler(rot);
        }
예제 #4
0
        /// <summary>
        /// Sets the position of an object.
        /// </summary>
        public void SetObjectPosition(GameObject obj, Vector3 pos,
                                      LevelEditorAction.ActionType actionType)
        {
            var attribs = AttributesOfObject(obj);

            attribs.SetPosition(pos);
            obj.transform.position = pos;
        }
예제 #5
0
        /// <summary>
        /// Crates an object with the given index.
        /// </summary>
        public void CreateObject(byte index, Vector3 position,
                                 LevelEditorAction.ActionType actionType)
        {
            // Warn if invalid index
            if (index < 0 || index >= byte.MaxValue)
            {
                throw new IndexOutOfRangeException("Invalid index! " + index);
            }

            // Add object to level file
            loadedLevel.AddObject((int)index, position,
                                  currentPlacementYRotation);

            if (Application.isEditor || Debug.isDebugBuild)
            {
                Debug.Log(currentPlacementYRotation);
            }

            // Create spawner
            GameObject spawner = CreateSpawner(index);

            spawner.transform.SetParent(loadedLevelObject.transform);
            spawner.transform.position      = position;
            spawner.transform.localRotation = Quaternion.Euler(0f,
                                                               currentPlacementYRotation, 0f);
            loadedSpawners.Add(spawner.GetComponent <ObjectSpawner>());
            objectCounts[(int)index]++;
            dirty = true;

            // Update undo/redo stack
            switch (actionType)
            {
            case LevelEditorAction.ActionType.Normal:
            case LevelEditorAction.ActionType.Redo:
                undoStack.Push(new CreateObjectAction(index, spawner));
                break;

            case LevelEditorAction.ActionType.Undo:
                redoStack.Push(new DeleteObjectAction(spawner, index));
                break;
            }
        }
예제 #6
0
        /// <summary>
        /// Moves an object.
        /// </summary>
        public void MoveObject(GameObject obj, Vector3 oldPos, Vector3 newPos,
                               LevelEditorAction.ActionType actionType)
        {
            var moveAction = new MoveObjectAction(obj, oldPos, newPos);

            switch (actionType)
            {
            case LevelEditorAction.ActionType.Normal:
            case LevelEditorAction.ActionType.Redo:
                undoStack.Push(moveAction);
                break;

            case LevelEditorAction.ActionType.Undo:
                redoStack.Push(new MoveObjectAction(obj, newPos, oldPos));
                break;
            }

            //var attribs = AttributesOfObject(obj);
            SetObjectPosition(obj, newPos, actionType);
        }
예제 #7
0
        /// <summary>
        /// Recrods a change to a standard attribute.
        /// </summary>
        public void RecordAttributeChange(GameObject obj,
                                          ChangeObjectNormalAttributeAction.AttributeChanged attrib,
                                          Vector3 oldValue, Vector3 newValue,
                                          LevelEditorAction.ActionType actionType)
        {
            switch (actionType)
            {
            case LevelEditorAction.ActionType.Normal:
            case LevelEditorAction.ActionType.Redo:
                undoStack.Push(
                    new ChangeObjectNormalAttributeAction(
                        obj, attrib, newValue));
                break;

            case LevelEditorAction.ActionType.Undo:
                redoStack.Push(
                    new ChangeObjectNormalAttributeAction(
                        obj, attrib, oldValue));
                break;
            }
        }