コード例 #1
0
    public void OnPointerClick(PointerEventData pointerEventData)
    {
        // Get sceneObjects script
        SceneObjects scene = sideMenu.GetComponent <SceneObjects>();

        string     objectName       = gameObject.GetComponent <Text>().text;
        GameObject editorGameObject = objectsList.transform.Find(objectName).gameObject;

        // Set last selected object in SceneObject script & Higlight gameobject in editor
        scene.SelectGameObject(gameObject, editorGameObject);
    }
コード例 #2
0
        /// <summary>
        /// Called every frame to perform all necessary updates.
        /// </summary>
        private void Update()
        {
            // Check if the left mouse button was pressed in the current frame.
            if (Input.GetMouseButtonDown(0) &&
                RTGizmosEngine.Get.HoveredGizmo == null)
            {
                // Pick a game object
                GameObject pickedObject = PickGameObject();

                if (pickedObject != null)
                {
                    // Get name of picked object
                    string     objectName = pickedObject.name;
                    GameObject objectList = scene.GetObjectListContent();

                    // Find sidemenu object by name in objectList
                    GameObject listGameObject = null;
                    if (objectList.transform.Find(objectName) != null)
                    {
                        listGameObject = objectList.transform.Find(objectName).gameObject;
                    }

                    if (listGameObject != null)
                    {
                        // Set last selected object in SceneObject script & Higlight gameobject in editor
                        scene.SelectGameObject(listGameObject, pickedObject);
                    }
                }
                else
                {
                    if (!EventSystem.current.IsPointerOverGameObject())
                    {
                        // If we reach this point, it means no object was picked. This means that we clicked
                        // in thin air, so we just clear the selected objects list.
                        RemoveHighlights(_selectedObjects);
                        _selectedObjects.Clear();

                        // The selection has changed
                        OnSelectionChanged();
                    }
                }
            }

            // TODO add giant if to check if you are in an input field as to not make mistakes by deleting or copying objects
            if (AllowKeyboardInputs)
            {
                // If the Ctrl + C key was pressed we add the currently selected objects to the clipboard list
                // If the Ctrl + V key was pressed we add the objects currently in the clipboard list to the scene
                if (Application.isEditor)                   // this works when you are using the editor
                {
                    if (Input.GetKeyDown(KeyCode.C))
                    {
                        if (_selectedObjects.Count != 0)
                        {
                            CopyToClipboard(_selectedObjects);
                        }
                        else
                        {
                            _clipboard.Clear();
                        }
                    }
                    else if (Input.GetKeyDown(KeyCode.V))
                    {
                        if (_clipboard.Count != 0)
                        {
                            RemoveHighlights(_selectedObjects);
                            _selectedObjects.Clear();
                            foreach (var newObj in Paste())
                            {
                                if (!_selectedObjects.Contains(newObj))
                                {
                                    _selectedObjects.Add(newObj);
                                }
                            }
                            OnSelectionChanged();
                        }
                    }
                }
                else                     // This works when you are not using the editor
                {
                    if (Input.GetKeyDown(KeyCode.C) && Input.GetKey(KeyCode.LeftControl))
                    {
                        if (_selectedObjects.Count != 0)
                        {
                            CopyToClipboard(_selectedObjects);
                        }
                        else
                        {
                            _clipboard.Clear();
                        }
                    }
                    else if (Input.GetKeyDown(KeyCode.V) && Input.GetKey(KeyCode.LeftControl))
                    {
                        if (_clipboard.Count != 0)
                        {
                            RemoveHighlights(_selectedObjects);
                            _selectedObjects.Clear();
                            foreach (var newObj in Paste())
                            {
                                if (!_selectedObjects.Contains(newObj))
                                {
                                    _selectedObjects.Add(newObj);
                                }
                            }
                            OnSelectionChanged();
                        }
                    }
                }

                if (Input.GetKey(KeyCode.Delete))
                {
                    if (_selectedObjects.Count != 0)
                    {
                        RemoveHighlights(_selectedObjects);
                        DeleteObjectList(_selectedObjects);
                        _selectedObjects.Clear();
                        OnSelectionChanged();
                    }
                }
                // If the G key was pressed, we change the transform space to Global. Otherwise,
                // if the L key was pressed, we change it to Local.
                if (Input.GetKeyDown(KeyCode.G))
                {
                    SetTransformSpace(GizmoSpace.Global);
                }
                else if (Input.GetKeyDown(KeyCode.L))
                {
                    SetTransformSpace(GizmoSpace.Local);
                }

                // We will change the pivot type when the P key is pressed
                if (Input.GetKeyDown(KeyCode.P))
                {
                    // Retrieve the current transform pivot and activate the other one instead.
                    GizmoObjectTransformPivot currentPivot = _objectMoveGizmo.TransformPivot;
                    if (currentPivot == GizmoObjectTransformPivot.ObjectGroupCenter)
                    {
                        SetTransformPivot(GizmoObjectTransformPivot.ObjectMeshPivot);
                    }
                    else
                    {
                        SetTransformPivot(GizmoObjectTransformPivot.ObjectGroupCenter);
                    }
                }

                // Switch between different gizmo types using the W,E,R,T keys.
                if (Input.GetKeyDown(KeyCode.W))
                {
                    SetWorkGizmoId(GizmoId.Move);
                }
                else if (Input.GetKeyDown(KeyCode.E))
                {
                    SetWorkGizmoId(GizmoId.Rotate);
                }
                else if (Input.GetKeyDown(KeyCode.R))
                {
                    SetWorkGizmoId(GizmoId.Scale);
                }
                else if (Input.GetKeyDown(KeyCode.T))
                {
                    SetWorkGizmoId(GizmoId.Universal);
                }
            }
            OnSelectionChanged();
        }