コード例 #1
0
    public bool Use()
    {
        var newInstance = history.NewInstance <List <ISelectable> >();

        newInstance.mInitial = SelectionManager.Instance.hashSelectable.ToList();
        history.undoList.Add(newInstance);
        return(true);
    }
コード例 #2
0
    //IAction, need an ActionUpdate function.
    void Update()
    {
        if (ActionManager.Instance.selectedAction != null && ActionManager.Instance.selectedAction.Result != this)
        {
            return;
        }

        if (EventSystem.current.currentSelectedGameObject != null)
        {
            return;
        }

        if (Input.GetKey(KeyCode.LeftAlt))
        {
            return;
        }

        if (!canUse)
        {
            return;
        }

        // If we press the left mouse button, begin selection and remember the location of the mouse
        if (Input.GetMouseButtonDown(0))
        {
            isSelecting    = true;
            mousePosition1 = Input.mousePosition;

            /*
             * var iSelectables = InterfaceHelper.FindObjects<ISelectable>();
             *
             * foreach ( var selectableObject in iSelectables )
             *  SelectionManager.Instance.Deselect(selectableObject);
             */

            if (!Input.GetKey(KeyCode.LeftShift))
            {
                SelectionManager.Instance.Clear();
            }
        }

        // If we let go of the left mouse button, end selection
        if (Input.GetMouseButtonUp(0))
        {
            var iSelectables    = InterfaceHelper.FindObjects <ISelectable>();
            var selectedObjects = new List <ISelectable>();

            foreach (var selectableObject in iSelectables)
            {
                if (!SelectionManager.Instance.hashSelectable.Contains(selectableObject))
                {
                    if (IsWithinSelectionBounds(selectableObject.gameObject))
                    {
                        /*
                         * if (Input.GetKey(KeyCode.LeftControl))
                         * {
                         *  Block block = selectableObject.gameObject.transform.parent.GetComponent<Block>();
                         *
                         *  foreach (Face face in block.faces)
                         *  {
                         *      if (face.gameObject != selectableObject.gameObject)
                         *      {
                         *          SelectionManager.Instance.Select(face);
                         *          selectedObjects.Add(face);
                         *      }
                         *  }
                         * }
                         */

                        if (!SelectionManager.Instance.hashSelectable.Contains(selectableObject))
                        {
                            SelectionManager.Instance.Select(selectableObject);
                            selectedObjects.Add(selectableObject);
                        }
                    }
                }
            }

            if (selectedObjects.Count > 0)
            {
                var instance = history.NewInstance <List <ISelectable> >();
                instance.mInitial = selectedObjects;
                history.undoList.Add(instance);
                HistoryManager.Instance.AddAction(myAction);
            }

            isSelecting = false;
        }
    }