Esempio n. 1
0
    public void Undo()
    {
        if (ActionIndexCount > 0)
        {
            /*print(Actions[ActionIndexCount-1].TypeOfAction);
            *  print(Actions[ActionIndexCount-1].PreviousValue);
            *  print(Actions[ActionIndexCount - 1].NewValue);
            *  print(Actions[ActionIndexCount - 1].gameObject);*/

            //if the gameobject doesnt exist remove the action

            if (Actions[ActionIndexCount - 1].gameObject == null && Actions[ActionIndexCount - 1].GameObjects.Count <= 0)
            {
                Actions.RemoveAt(ActionIndexCount - 1);
                --ActionIndexCount;
                return;
            }
            //if action is erase
            if (Actions[ActionIndexCount - 1].TypeOfAction == Action.ActionType.Erase)
            {
                if (Actions[ActionIndexCount - 1].gameObject != null)
                {
                    SetObjectsActive(true, Actions[ActionIndexCount - 1].gameObject);                //psudo-"recreate" it
                    var testVect = Actions[ActionIndexCount - 1].PreviousValue;
                    Actions[ActionIndexCount - 1].gameObject.transform.position = (Vector3)testVect; //reset its position
                }
                else
                {
                    foreach (GameObject obj in Actions[ActionIndexCount - 1].GameObjects)
                    {
                        SetObjectsActive(true, obj);   //psudo-"recreate" it
                    }
                }
            }
            //if action is Move
            if (Actions[ActionIndexCount - 1].TypeOfAction == Action.ActionType.Move)
            {
                var testVect = Actions[ActionIndexCount - 1].PreviousValue;
                Actions[ActionIndexCount - 1].gameObject.transform.position = (Vector3)testVect;            //reset its position
            }
            //if action is Place
            if (Actions[ActionIndexCount - 1].TypeOfAction == Action.ActionType.Place)
            {
                if (Actions[ActionIndexCount - 1].gameObject != null)
                {
                    SetObjectsActive(false, Actions[ActionIndexCount - 1].gameObject);                                         //psudo-"delete" it
                    if (objectEditor.GetComponent <ObjectEditor>().SelectedObject == Actions[ActionIndexCount - 1].gameObject) //remove as selected if it is selected
                    {
                        control.RemoveSelected();
                    }
                }
                else
                {
                    print(Actions[ActionIndexCount - 1].GameObjects.Count);
                    foreach (GameObject obj in Actions[ActionIndexCount - 1].GameObjects)
                    {
                        SetObjectsActive(false, obj);                                         //psudo-"delete" it
                        if (objectEditor.GetComponent <ObjectEditor>().SelectedObject == obj) //remove as selected if it is selected
                        {
                            control.RemoveSelected();
                        }
                    }
                }
            }
            //if action is ValueChange
            if (Actions[ActionIndexCount - 1].TypeOfAction == Action.ActionType.ValueChange)
            {
                Actions[ActionIndexCount - 1].gameObject.GetComponent <EditableObject>().ValueChanged(Actions[ActionIndexCount - 1].VariableObject, Actions[ActionIndexCount - 1].PreviousValue, false); //return variable to old value
                control.SetSelected(Actions[ActionIndexCount - 1].gameObject);                                                                                                                           //set as selected
            }
            --ActionIndexCount;
        }
    }
Esempio n. 2
0
 void MoveObject()
 {
     if (MoveGameObject.GetComponent <MoveObjectScript>().MoveObject == null)
     {
         Cursor.SetCursor(MouseIcons[5], Vector2.zero, CursorMode.Auto);
     }
     else
     {
         Cursor.SetCursor(MouseIcons[2], Vector2.zero, CursorMode.Auto);
     }
     if (Input.GetMouseButtonDown(0) && MoveGameObject.GetComponent <MoveObjectScript>().MoveObject == null)
     {
         Collider2D col = TestMove();
         if (col != null)
         {
             MoveGameObject.GetComponent <MoveObjectScript>().SetMoveObject(col.gameObject);
             Color color = col.gameObject.GetComponent <SpriteRenderer>().color;
             col.gameObject.GetComponent <SpriteRenderer>().color = new Color(color.r, color.g, color.b, color.a / 2);
         }
     }
     else if (Input.GetMouseButtonDown(0) && MoveGameObject.GetComponent <MoveObjectScript>().MoveObject != null)
     {
         GameObject obj = null;
         foreach (Collider2D col in Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition)))
         {
             if (col.gameObject.layer == 8 && ControlScript.CurrentMode == ControlScript.Mode.Build)
             {
                 obj = null;
                 break;
             }
             else if (col.gameObject.layer == 10 && ControlScript.CurrentMode == ControlScript.Mode.Connect)
             {
                 obj = null;
                 break;
             }
             if ((MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.layer == 8 || MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.tag == "Player") &&
                 ControlScript.CurrentMode == ControlScript.Mode.Build)
             {
                 if (col.tag == "Tile")
                 {
                     obj = col.gameObject;
                 }
             }
             else if (MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.layer == 10 && ControlScript.CurrentMode == ControlScript.Mode.Connect)
             {
                 if (col.tag == "DotTile")
                 {
                     obj = col.gameObject;
                 }
             }
         }
         if (obj != null)
         {
             Vector3 v = new Vector3(obj.transform.position.x, obj.transform.position.y, MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.transform.position.z);
             UndoHandlerWebGL.instance.AddMoveAction <Vector3>(MoveGameObject, MoveGameObject.transform.position, v);
             if ((Vector2)MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.transform.position == (Vector2)control.SelectedHighlight.transform.position)
             {
                 control.SetSelected(v);
             }
             if ((Vector2)MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.transform.position == (Vector2)control.CopyingHighlight.transform.position)
             {
                 control.SetCopying(v);
             }
             if (MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.tag == "Player")
             {
                 control.PlayerStartPos = v;
             }
             Color color = MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.GetComponent <SpriteRenderer>().color;
             MoveGameObject.GetComponent <MoveObjectScript>().MoveObject.GetComponent <SpriteRenderer>().color = new Color(color.r, color.g, color.b, color.a * 2);
             MoveGameObject.GetComponent <MoveObjectScript>().PlaceMoveObject(v);
         }
     }
 }