Esempio n. 1
0
    void Erase()
    {
        if (Skip)
        {
            Skip = false;
        }
        else
        {
            Cursor.SetCursor(MouseIcons[1], Vector2.zero, CursorMode.Auto);
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //distance = 3 + Input.mousePosition.x/10;

            RaycastHit2D destroyObj = new RaycastHit2D();
            foreach (RaycastHit2D obj in Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), ray.direction))
            {
                if (obj.collider.tag == "Tile")
                {
                    if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
                    {
                        Ray tileRay = new Ray(obj.transform.position - Vector3.forward, Vector3.forward);

                        foreach (RaycastHit2D obj2 in Physics2D.RaycastAll(obj.transform.position - Vector3.forward, tileRay.direction))
                        {
                            if (obj2.collider.gameObject.layer == 8)
                            {
                                //Add to undo handler
                                //UndoHandler.instance.AddEraseAction<Vector3>(obj2.collider.gameObject, obj2.transform.position);
                                UndoHandlerWebGL.instance.OnErased <Vector3>(obj2.collider.gameObject);

                                destroyObj = obj2;
                            }
                        }
                    }
                }
            }
            if (destroyObj.collider != null)
            {
                if ((Vector2)destroyObj.transform.position == (Vector2)control.SelectedHighlight.transform.position)
                {
                    control.RemoveSelected();
                }
                if ((Vector2)destroyObj.transform.position == (Vector2)control.CopyingHighlight.transform.position)
                {
                    control.RemoveCopying();
                }
                if (destroyObj.collider.GetComponent <ObjectRequiresConnection>())
                {
                    destroyObj.collider.GetComponent <ObjectRequiresConnection>().dotTile.Blocked       = false;
                    destroyObj.collider.GetComponent <ObjectRequiresConnection>().dotTile.ObjectUnderMe = null;
                }
                //IF actually destroy
                //Destroy(destroyObj.collider.gameObject);

                //temp hide in case of undo
                destroyObj.collider.gameObject.GetComponent <PlaceableObject>().SetActive(false);
            }
        }
    }
Esempio n. 2
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;
        }
    }