protected override void UpdateOverride()
        {
            base.UpdateOverride();
            if (RuntimeEditorApplication.IsActiveWindow(this))
            {
                if (InputController._GetKeyDown(RemoveKey))
                {
                    if (m_treeView.SelectedItem != null)
                    {
                        ProjectItem projectItem = (ProjectItem)m_treeView.SelectedItem;
                        if (projectItem.Parent == null)
                        {
                            PopupWindow.Show("Unable to Remove", "Unable to remove root folder", "OK");
                        }
                        else
                        {
                            PopupWindow.Show("Remove Selected assets", "You can not undo this action", "Delete", args =>
                            {
                                m_treeView.RemoveSelectedItems();
                            }, "Cancel");
                        }
                    }
                }
            }


            if (RuntimeEditorApplication.IsPointerOverWindow(this))
            {
                if (m_dragProjectItem != null)
                {
                    m_treeView.ExternalItemDrag(InputController._MousePosition);
                }
            }
        }
Beispiel #2
0
        private void UpdateUIState(bool isInPlayMode)
        {
            if (ProjectionButton != null)
            {
                ProjectionButton.gameObject.SetActive(!isInPlayMode);
            }

            EditorCamera.gameObject.SetActive(!isInPlayMode);
            PlayerCamera.gameObject.SetActive(isInPlayMode);
            SelectionController.gameObject.SetActive(!isInPlayMode);
            PlayButton.gameObject.SetActive(!isInPlayMode);

            HintButton.gameObject.SetActive(!isInPlayMode);
            SaveButton.gameObject.SetActive(!isInPlayMode);
            LoadButton.gameObject.SetActive(!isInPlayMode);
            StopButton.gameObject.SetActive(isInPlayMode);
            UndoButton.gameObject.SetActive(!isInPlayMode);
            RedoButton.gameObject.SetActive(!isInPlayMode);
            UI.gameObject.SetActive(!isInPlayMode);
            Grid.gameObject.SetActive(TogGrid.isOn && !isInPlayMode);
            LoadButton.interactable = m_sceneManager != null && m_saveFileExists;

            if (isInPlayMode)
            {
                RuntimeEditorApplication.ActivateWindow(RuntimeWindowType.GameView);
            }
            else
            {
                RuntimeEditorApplication.ActivateWindow(RuntimeWindowType.SceneView);
            }
        }
        private void OnItemsRemoving(object sender, ItemsCancelArgs e)
        {
            if (e.Items == null)
            {
                return;
            }

            if (!RuntimeEditorApplication.IsActiveWindow(this))
            {
                e.Items.Clear();
                return;
            }

            for (int i = e.Items.Count - 1; i >= 0; i--)
            {
                ProjectItem item = (ProjectItem)e.Items[i];
                if (m_project.IsStatic(item))
                {
                    e.Items.Remove(item);
                }
            }

            if (e.Items.Count == 0)
            {
                PopupWindow.Show("Can't remove folder", "Unable to remove folders exposed from editor", "OK");
            }
        }
Beispiel #4
0
        private void Update()
        {
            #if UNITY_EDITOR
            UnityEditorToolsListener.Update();
            #endif

            if (RuntimeTools.ActiveTool != null)
            {
                return;
            }


            bool isGameViewActive = RuntimeEditorApplication.IsActiveWindow(RuntimeWindowType.GameView);
            bool isLocked         = RuntimeTools.IsViewing || isGameViewActive;
            if (!isLocked)
            {
                if (InputController.GetKeyDown(ViewToolKey))
                {
                    RuntimeTools.Current = RuntimeTool.View;
                }
                else if (InputController.GetKeyDown(MoveToolKey))
                {
                    RuntimeTools.Current = RuntimeTool.Move;
                }
                else if (InputController.GetKeyDown(RotateToolKey))
                {
                    RuntimeTools.Current = RuntimeTool.Rotate;
                }
                else if (InputController.GetKeyDown(ScaleToolKey))
                {
                    RuntimeTools.Current = RuntimeTool.Scale;
                }

                if (InputController.GetKeyDown(PivotRotationKey))
                {
                    if (RuntimeTools.PivotRotation == RuntimePivotRotation.Local)
                    {
                        RuntimeTools.PivotRotation = RuntimePivotRotation.Global;
                    }
                    else
                    {
                        RuntimeTools.PivotRotation = RuntimePivotRotation.Local;
                    }
                }
                if (InputController.GetKeyDown(PivotModeKey) &&
                    !(InputController.GetKey(KeyCode.LeftControl) || InputController.GetKey(KeyCode.LeftShift)))
                {
                    if (RuntimeTools.PivotMode == RuntimePivotMode.Center)
                    {
                        RuntimeTools.PivotMode = RuntimePivotMode.Pivot;
                    }
                    else
                    {
                        RuntimeTools.PivotMode = RuntimePivotMode.Center;
                    }
                }
            }
        }
        protected override void UpdateOverride()
        {
            base.UpdateOverride();
            if (!RuntimeEditorApplication.IsPointerOverWindow(this))
            {
                return;
            }

            if (InputController.GetKeyDown(SelectAllKey))
            {
                if (InputController.GetKey(ModifierKey))
                {
                    if (RuntimeEditorApplication.IsActiveWindow(this))
                    {
                        m_treeView.SelectedItems = m_treeView.Items;
                    }
                }
            }

            if (RuntimeTools.SpawnPrefab == null)
            {
                return;
            }

            m_treeView.ExternalItemDrag(Input.mousePosition);

            if (Input.GetMouseButtonUp(0))
            {
                m_isSpawningPrefab = true;
                GameObject prefabInstance = RuntimeTools.SpawnPrefab.InstantiatePrefab(Vector3.zero, Quaternion.identity);
                prefabInstance.SetActive(true);

                ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>();
                if (exposeToEditor == null)
                {
                    exposeToEditor = prefabInstance.AddComponent <ExposeToEditor>();
                }

                exposeToEditor.SetName(RuntimeTools.SpawnPrefab.name);
                RuntimeUndo.BeginRecord();
                RuntimeUndo.RecordSelection();
                RuntimeUndo.BeginRegisterCreateObject(prefabInstance);
                RuntimeUndo.EndRecord();

                bool isEnabled = RuntimeUndo.Enabled;
                RuntimeUndo.Enabled = false;
                RuntimeSelection.activeGameObject = prefabInstance;
                RuntimeUndo.Enabled = isEnabled;

                RuntimeUndo.BeginRecord();
                RuntimeUndo.RegisterCreatedObject(prefabInstance);
                RuntimeUndo.RecordSelection();
                RuntimeUndo.EndRecord();

                RuntimeTools.SpawnPrefab = null;
            }
        }
 protected override void UpdateOverride()
 {
     base.UpdateOverride();
     if (InputController.GetKeyDown(DuplicateKey) && InputController.GetKey(ModifierKey))
     {
         if (RuntimeEditorApplication.IsActiveWindow(m_projectResources))
         {
             DuplicateProjectResources();
         }
     }
 }
Beispiel #7
0
        private void OnDestroy()
        {
            if (m_instance == this)
            {
                m_instance = null;
                RuntimeEditorApplication.Reset();
                EditorsMap.Reset();
            }

            Unsubscribe();
        }
        private void Update()
        {
            if (!RuntimeEditorApplication.IsActiveWindow(RuntimeWindowType.GameView) && RuntimeEditorApplication.IsOpened)
            {
                return;
            }

            if (InputController.GetKeyDown(KeyCode.Return))
            {
                SwitchPlayer(m_current, 0.0f, true);
            }
            else if (InputController.GetKeyDown(KeyCode.Backspace))
            {
                SwitchPlayer(m_current, 0.0f, false);
            }
        }
Beispiel #9
0
        private void OnPlaymodeStateChanged()
        {
            if (RuntimeEditorApplication.IsPlaying)
            {
                RuntimeEditorApplication.ActivateWindow(RuntimeWindowType.GameView);
            }
            else
            {
                RuntimeEditorApplication.ActivateWindow(RuntimeWindowType.SceneView);
            }

            if (PlayToggle != null)
            {
                PlayToggle.isOn = RuntimeEditorApplication.IsPlaying;
            }

            UpdateLoadSaveButtonsState();
        }
Beispiel #10
0
        protected override void UpdateOverride()
        {
            base.UpdateOverride();
            if (!RuntimeEditorApplication.IsActiveWindow(this) && !RuntimeEditorApplication.IsActiveWindow(RuntimeWindowType.SceneView))
            {
                return;
            }

            if (InputController.GetKeyDown(RemoveKey))
            {
                if (m_listBox.SelectedItem != null)
                {
                    PopupWindow.Show("Remove Selected assets", "You can not undo this action", "Delete", args =>
                    {
                        m_listBox.RemoveSelectedItems();
                    }, "Cancel");
                }
            }
        }
Beispiel #11
0
        private void OnDestroy()
        {
            if (Instance == this)
            {
                Instance = null;
                RuntimeEditorApplication.Reset();
            }

            RuntimeEditorApplication.PlaymodeStateChanged -= OnPlaymodeStateChanged;
            RuntimeEditorApplication.IsOpenedChanged      -= OnIsOpenedChanged;
            RuntimeSelection.SelectionChanged             -= OnRuntimeSelectionChanged;
            RuntimeTools.ToolChanged          -= OnRuntimeToolChanged;
            RuntimeTools.PivotRotationChanged -= OnPivotRotationChanged;
            RuntimeUndo.RedoCompleted         -= OnUndoCompleted;
            RuntimeUndo.RedoCompleted         -= OnRedoCompleted;
            RuntimeUndo.StateChanged          -= OnUndoRedoStateChanged;
            ExposeToEditor.Awaked             -= OnAwaked;
            ExposeToEditor.Destroyed          -= OnDestroyed;
        }
Beispiel #12
0
        protected override void UpdateOverride()
        {
            base.UpdateOverride();

            if (RuntimeTools.ActiveTool != null)
            {
                return;
            }

            HandleInput();

            if (RuntimeEditorApplication.IsPointerOverWindow(this))
            {
                SetCursor();
            }
            else
            {
                CursorHelper.ResetCursor(this);
            }
        }
Beispiel #13
0
        private void CompleteSpawn(object item)
        {
            ItemContainer itemContainer = m_listBox.GetItemContainer(item);

            if (itemContainer != null)
            {
                ResourcePreview resource = itemContainer.GetComponentInChildren <ResourcePreview>();
                resource.CompleteSpawn();
            }

            if (RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.Resources))
            {
                RuntimeTools.SpawnPrefab = null;
            }

            if (Drop != null)
            {
                Drop(this, new ProjectResourcesEventArgs(new [] { (ProjectItemObjectPair)item }));
            }
        }
        public ProjectItem BeginDropProjectItem()
        {
            ProjectItem dropTarget = null;

            if (m_dragProjectItem != null)
            {
                if (m_treeView.DropAction == ItemDropAction.SetLastChild)
                {
                    dropTarget = (ProjectItem)m_treeView.DropTarget;
                }

                if (RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.ProjectTree))
                {
                    RuntimeTools.SpawnPrefab = null;
                }
            }
            m_treeView.ExternalItemDrop();
            m_dragProjectItem = null;

            return(dropTarget);
        }
        private void Start()
        {
            GameObject          go               = RuntimeSelection.activeGameObject;
            ExposeToEditor      exposeToEditor   = go.GetComponent <ExposeToEditor>();
            HierarchyItem       hierarchyItem    = go.GetComponent <HierarchyItem>();
            HashSet <Component> ignoreComponents = new HashSet <Component>();

            if (exposeToEditor != null)
            {
                if (exposeToEditor.Colliders != null)
                {
                    for (int i = 0; i < exposeToEditor.Colliders.Length; ++i)
                    {
                        Collider collider = exposeToEditor.Colliders[i];
                        if (!ignoreComponents.Contains(collider))
                        {
                            ignoreComponents.Add(collider);
                        }
                    }
                }

                ignoreComponents.Add(exposeToEditor);
            }

            if (hierarchyItem != null)
            {
                ignoreComponents.Add(hierarchyItem);
            }

            InputName.text        = go.name;
            TogEnableDisable.isOn = go.activeSelf;

            InputName.onEndEdit.AddListener(OnEndEditName);
            TogEnableDisable.onValueChanged.AddListener(OnEnableDisable);
            Component[] components = go.GetComponents <Component>();
            for (int i = 0; i < components.Length; ++i)
            {
                Component component = components[i];
                if (component == null)
                {
                    continue;
                }

                if (ignoreComponents.Contains(component))
                {
                    continue;
                }

                if ((component.hideFlags & HideFlags.HideInInspector) != 0)
                {
                    continue;
                }

                if (EditorsMap.IsObjectEditorEnabled(component.GetType()))
                {
                    GameObject editorPrefab = EditorsMap.GetObjectEditor(component.GetType());
                    if (editorPrefab != null)
                    {
                        ComponentEditor componentEditorPrefab = editorPrefab.GetComponent <ComponentEditor>();
                        if (componentEditorPrefab != null)
                        {
                            ComponentEditor editor = Instantiate(componentEditorPrefab);
                            editor.EndEditCallback = () =>
                            {
                                RuntimeEditorApplication.SaveSelectedObjects();
                            };
                            editor.transform.SetParent(ComponentsPanel, false);
                            editor.Component = component;
                        }
                        else
                        {
                            Debug.LogErrorFormat("editor prefab {0} does not have ComponentEditor script", editorPrefab.name);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        private void LateUpdate()
        {
            if (RuntimeTools.ActiveTool != null && RuntimeTools.ActiveTool != this)
            {
                return;
            }

            if (RuntimeTools.IsViewing)
            {
                return;
            }

            if (KeyCode == KeyCode.None || InputController.GetKeyDown(KeyCode))
            {
                m_active = true;
            }

            if (m_active)
            {
                if (Input.GetMouseButtonDown(MouseButton))
                {
                    m_startMousePosition = Input.mousePosition;
                    m_isDragging         = GetPoint(out m_startPt) &&
                                           (!RuntimeEditorApplication.IsOpened || RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.SceneView) && !RuntimeTools.IsPointerOverGameObject());
                    if (m_isDragging)
                    {
                        m_rectTransform.anchoredPosition = m_startPt;
                        m_rectTransform.sizeDelta        = new Vector2(0, 0);
                        CursorHelper.SetCursor(this, null, Vector3.zero, CursorMode.Auto);
                    }
                    else
                    {
                        RuntimeTools.ActiveTool = null;
                    }
                }
                else if (Input.GetMouseButtonUp(MouseButton))
                {
                    if (m_isDragging)
                    {
                        m_isDragging = false;

                        HitTest();
                        m_rectTransform.sizeDelta = new Vector2(0, 0);
                        CursorHelper.ResetCursor(this);
                    }

                    RuntimeTools.ActiveTool = null;
                    m_active = false;
                }
                else if (m_isDragging)
                {
                    GetPoint(out m_endPt);

                    Vector2 size = m_endPt - m_startPt;
                    if (size != Vector2.zero)
                    {
                        RuntimeTools.ActiveTool = this;
                    }
                    m_rectTransform.sizeDelta  = new Vector2(Mathf.Abs(size.x), Mathf.Abs(size.y));
                    m_rectTransform.localScale = new Vector3(Mathf.Sign(size.x), Mathf.Sign(size.y), 1);
                }
            }
        }
Beispiel #17
0
        private void LateUpdate()
        {
            if (InputController._GetMouseButtonDown(0))
            {
                if (RuntimeTools.ActiveTool != null && RuntimeTools.ActiveTool != BoxSelection.Current)
                {
                    return;
                }

                if (!IPointerOverEditorArea)
                {
                    return;
                }

                if (RuntimeTools.IsViewing)
                {
                    return;
                }

                if (!RuntimeSelection.Enabled)
                {
                    return;
                }

                bool       rangeSelect = InputController._GetKey(RangeSelectKey);
                bool       multiselect = InputController._GetKey(MultiselectKey) || InputController._GetKey(MultiselectKey2) || rangeSelect;
                Ray        ray         = SceneCamera.ScreenPointToRay(InputController._MousePosition);
                RaycastHit hitInfo;

                //if (Physics.Raycast(ray, out hitInfo, float.MaxValue, LayerMask.value))
                if (Physics.Raycast(ray, out hitInfo, float.MaxValue))
                {
                    GameObject hitGO     = hitInfo.collider.gameObject;
                    bool       canSelect = CanSelect(hitGO);
                    if (canSelect)
                    {
                        hitGO = hitGO.GetComponentInParent <ExposeToEditor>().gameObject;
                        if (multiselect)
                        {
                            List <Object> selection;
                            if (RuntimeSelection.objects != null)
                            {
                                selection = RuntimeSelection.objects.ToList();
                            }
                            else
                            {
                                selection = new List <Object>();
                            }

                            if (selection.Contains(hitGO))
                            {
                                selection.Remove(hitGO);
                                if (rangeSelect)
                                {
                                    selection.Insert(0, hitGO);
                                }
                            }
                            else
                            {
                                selection.Insert(0, hitGO);
                            }
                            RuntimeSelection.Select(hitGO, selection.ToArray());
                        }
                        else
                        {
                            RuntimeSelection.activeObject = hitGO;
                        }
                    }
                    else
                    {
                        if (!multiselect)
                        {
                            RuntimeSelection.activeObject = null;
                        }
                    }
                }
                else
                {
                    if (!multiselect)
                    {
                        RuntimeSelection.activeObject = null;
                    }
                }
            }

            if (RuntimeEditorApplication.IsActiveWindow(this))
            {
                if (InputController._GetKeyDown(SelectAllKey) && InputController._GetKey(ModifierKey))
                {
                    IEnumerable <GameObject> filtered = RuntimeEditorApplication.IsPlaying ?
                                                        ExposeToEditor.FindAll(ExposeToEditorObjectType.PlayMode) :
                                                        ExposeToEditor.FindAll(ExposeToEditorObjectType.EditorMode);
                    RuntimeSelection.objects = filtered.ToArray();
                }
            }
        }
Beispiel #18
0
        private void HandleInput()
        {
            if (RuntimeTools.AutoFocus)
            {
                do
                {
                    if (RuntimeTools.ActiveTool != null)
                    {
                        break;
                    }

                    if (m_autoFocusTransform == null)
                    {
                        break;
                    }

                    if (m_autoFocusTransform.position == SecondaryPivot.position)
                    {
                        break;
                    }

                    if (m_focusAnimation != null && m_focusAnimation.InProgress)
                    {
                        break;
                    }

                    Vector3 offset = (m_autoFocusTransform.position - SecondaryPivot.position);
                    SceneCamera.transform.position    += offset;
                    Pivot.transform.position          += offset;
                    SecondaryPivot.transform.position += offset;
                }while (false);
            }

            if (InputController._GetMouseButtonUp(0) ||
                InputController._GetMouseButtonUp(1) ||
                InputController._GetMouseButtonUp(2))
            {
                m_handleInput        = false;
                m_mouseOrbit.enabled = false;
                m_rotate             = false;
                SetCursor();
                return;
            }

            bool isGameViewActive = RuntimeEditorApplication.IsActiveWindow(RuntimeWindowType.GameView);

            if (!isGameViewActive)
            {
                float mouseWheel = InputController._GetAxis("Mouse ScrollWheel");
                if (mouseWheel != 0)
                {
                    if (!RuntimeTools.IsPointerOverGameObject())
                    {
                        m_mouseOrbit.Zoom();
                    }
                }
            }

            if (m_lockInput)
            {
                return;
            }


            if (!isGameViewActive)
            {
                if (InputController._GetKeyDown(SnapToGridKey) && InputController._GetKey(ModifierKey))
                {
                    SnapToGrid();
                }

                if (InputController._GetKeyDown(FocusKey))
                {
                    Focus();
                }

                bool rotate = InputController._GetKey(RotateKey) || InputController._GetKey(RotateKey2) || InputController._GetKey(RotateKey3);
                bool pan    = InputController._GetMouseButton(2) || InputController._GetMouseButton(1) || InputController._GetMouseButton(0) && RuntimeTools.Current == RuntimeTool.View;
                if (pan != m_pan)
                {
                    m_pan = pan;
                    if (m_pan)
                    {
                        if (RuntimeTools.Current != RuntimeTool.View)
                        {
                            m_rotate = false;
                        }
                        m_dragPlane = new Plane(-SceneCamera.transform.forward, Pivot.position);
                    }
                    SetCursor();
                }
                else
                {
                    if (rotate != m_rotate)
                    {
                        m_rotate = rotate;
                        SetCursor();
                    }
                }
            }

            RuntimeTools.IsViewing = m_rotate || m_pan;
            bool isLocked = RuntimeTools.IsViewing || isGameViewActive;

            if (!IPointerOverEditorArea)
            {
                return;
            }


            bool isMouse0ButtonDown = InputController._GetMouseButtonDown(0);
            bool isMouse1ButtonDown = InputController._GetMouseButtonDown(1);
            bool isMouse2ButtonDown = InputController._GetMouseButtonDown(2);

            if (isMouse0ButtonDown || isMouse1ButtonDown || isMouse2ButtonDown)
            {
                m_handleInput       = !PositionHandle.IsDragging;
                m_lastMousePosition = InputController._MousePosition;
                if (m_rotate)
                {
                    m_mouseOrbit.enabled = true;
                }
            }



            if (m_handleInput)
            {
                if (isLocked)
                {
                    if (m_pan && (!m_rotate || RuntimeTools.Current != RuntimeTool.View))
                    {
                        Pan();
                    }
                }
            }
        }
        public void CompleteSpawn()
        {
            if (RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.SceneView))
            {
                if (m_resource is Material)
                {
                    Material material    = (Material)m_resource;
                    Camera   sceneCamera = RuntimeEditorApplication.ActiveSceneCamera;
                    if (sceneCamera)
                    {
                        Ray        ray = sceneCamera.ScreenPointToRay(Input.mousePosition);
                        RaycastHit hitInfo;
                        if (Physics.Raycast(ray, out hitInfo))
                        {
                            MeshRenderer        renderer  = hitInfo.collider.GetComponentInChildren <MeshRenderer>();
                            SkinnedMeshRenderer sRenderer = hitInfo.collider.GetComponentInChildren <SkinnedMeshRenderer>();
                            if (renderer != null || sRenderer != null)
                            {
                                RuntimeUndo.BeginRecord();
                            }

                            if (renderer != null)
                            {
                                RuntimeUndo.RecordValue(renderer, Strong.PropertyInfo((MeshRenderer x) => x.sharedMaterials));
                                Material[] materials = renderer.sharedMaterials;
                                for (int i = 0; i < materials.Length; ++i)
                                {
                                    materials[i] = material;
                                }
                                renderer.sharedMaterials = materials;
                            }

                            if (sRenderer != null)
                            {
                                RuntimeUndo.RecordValue(sRenderer, Strong.PropertyInfo((SkinnedMeshRenderer x) => x.sharedMaterials));
                                Material[] materials = sRenderer.sharedMaterials;
                                for (int i = 0; i < materials.Length; ++i)
                                {
                                    materials[i] = material;
                                }
                                sRenderer.sharedMaterials = materials;
                            }

                            if (renderer != null || sRenderer != null)
                            {
                                RuntimeUndo.EndRecord();
                            }

                            if (renderer != null || sRenderer != null)
                            {
                                RuntimeUndo.BeginRecord();
                            }

                            if (renderer != null)
                            {
                                RuntimeUndo.RecordValue(renderer, Strong.PropertyInfo((MeshRenderer x) => x.sharedMaterials));
                            }

                            if (sRenderer != null)
                            {
                                RuntimeUndo.RecordValue(sRenderer, Strong.PropertyInfo((SkinnedMeshRenderer x) => x.sharedMaterials));
                            }

                            if (renderer != null || sRenderer != null)
                            {
                                RuntimeUndo.EndRecord();
                            }
                        }
                    }
                }
                else
                {
                    if (m_state == State.AfterSpawn)
                    {
                        bool isEnabled = RuntimeUndo.Enabled;
                        RuntimeUndo.Enabled      = false;
                        RuntimeSelection.objects = m_selection;
                        RuntimeUndo.Enabled      = isEnabled;

                        RuntimeUndo.BeginRecord();
                        RuntimeUndo.RecordSelection();
                        RuntimeUndo.BeginRegisterCreateObject(m_instance);
                        RuntimeUndo.EndRecord();

                        RuntimeUndo.Enabled = false;
                        RuntimeSelection.activeGameObject = m_instance;
                        RuntimeUndo.Enabled = isEnabled;

                        RuntimeUndo.BeginRecord();
                        RuntimeUndo.RegisterCreatedObject(m_instance);
                        RuntimeUndo.RecordSelection();
                        RuntimeUndo.EndRecord();
                    }
                }
                EndSpawn();
                RuntimeEditorApplication.ActivateWindow(RuntimeWindowType.SceneView);
            }
            else
            {
                if (!RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.Hierarchy))
                {
                    EndSpawn();
                }
            }
        }
        private void Update()
        {
            if (InputController._GetMouseButtonDown(0))
            {
                if (RuntimeTools.Current != Tool && RuntimeTools.Current != RuntimeTool.None || RuntimeTools.IsViewing)
                {
                    return;
                }

                if (RuntimeTools.IsPointerOverGameObject())
                {
                    return;
                }

                if (SceneCamera == null)
                {
                    Debug.LogError("Camera is null");
                    return;
                }

                if (RuntimeTools.ActiveTool != null)
                {
                    return;
                }

                if (RuntimeEditorApplication.ActiveSceneCamera != null && !RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.SceneView))
                {
                    return;
                }

                m_isDragging = OnBeginDrag();
                if (m_isDragging)
                {
                    RuntimeTools.ActiveTool = this;
                    RecordTransform();
                }
                else
                {
                    RuntimeTools.ActiveTool = null;
                }
            }
            else if (InputController._GetMouseButtonUp(0))
            {
                TryCancelDrag();
            }
            else
            {
                if (m_isDragging)
                {
                    if (InputController._GetKey(UnitSnapKey) || RuntimeTools.UnitSnapping)
                    {
                        EffectiveGridUnitSize = CurrentGridUnitSize;
                    }
                    else
                    {
                        EffectiveGridUnitSize = 0;
                    }

                    OnDrag();
                }
            }


            UpdateOverride();

            if (Model != null)
            {
                SyncModelTransform();
            }

            if (m_isDragging)
            {
                if (RuntimeTools.PivotMode == RuntimePivotMode.Center && m_commonCenterTarget != null && m_realTargets != null && m_realTargets.Length > 1)
                {
                    for (int i = 0; i < m_commonCenterTarget.Length; ++i)
                    {
                        Transform commonCenterTarget = m_commonCenterTarget[i];
                        Transform target             = m_realTargets[i];

                        target.transform.position   = commonCenterTarget.position;
                        target.transform.rotation   = commonCenterTarget.rotation;
                        target.transform.localScale = commonCenterTarget.localScale;
                    }
                }
            }
        }
        public void BuildEditor()
        {
            foreach (Transform t in EditorsPanel)
            {
                Destroy(t.gameObject);
            }

            IMaterialDescriptor selector;

            if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector))
            {
                selector = new MaterialDescriptor();
            }


            object converter = selector.CreateConverter(this);

            MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter);
            if (descriptors == null)
            {
                Destroy(gameObject);
                return;
            }

            for (int i = 0; i < descriptors.Length; ++i)
            {
                MaterialPropertyDescriptor descriptor = descriptors[i];
                PropertyEditor             editor     = null;
                object       target       = descriptor.Target;
                PropertyInfo propertyInfo = descriptor.PropertyInfo;
#if !UNITY_WEBGL && PROC_MATERIAL
                if (descriptor.ProceduralDescription == null)
#endif
                {
                    RTShaderPropertyType propertyType = descriptor.Type;

                    switch (propertyType)
                    {
                    case RTShaderPropertyType.Range:
                        if (RangeEditor != null)
                        {
                            RangeEditor range = Instantiate(RangeEditor);
                            range.transform.SetParent(EditorsPanel, false);

                            var rangeLimits = descriptor.Limits;
                            range.Min = rangeLimits.Min;
                            range.Max = rangeLimits.Max;
                            editor    = range;
                        }
                        break;

                    default:
                        if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                        {
                            GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                            GameObject instance     = Instantiate(editorPrefab);
                            instance.transform.SetParent(EditorsPanel, false);

                            if (instance != null)
                            {
                                editor = instance.GetComponent <PropertyEditor>();
                            }
                        }
                        break;
                    }
                }
#if !UNITY_WEBGL && PROC_MATERIAL
                else
                {
                    ProcPropertyDescription input = descriptor.ProceduralDescription;
                    if (input.hasRange)
                    {
                        if (input.type == ProcPropertyType.Float)
                        {
                            if (RangeEditor != null)
                            {
                                RangeEditor range = Instantiate(RangeEditor);
                                range.transform.SetParent(EditorsPanel, false);
                                range.Min = input.minimum;
                                range.Max = input.maximum;
                                //TODO implement step on range editor // = input.step
                                editor = range;
                            }
                        }
                        else
                        {
                            //TODO: Implement range on vector editors

                            if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                            {
                                GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                                GameObject instance     = Instantiate(editorPrefab);
                                instance.transform.SetParent(EditorsPanel, false);

                                if (instance != null)
                                {
                                    editor = instance.GetComponent <PropertyEditor>();
                                }
                            }
                        }
                    }
                    else
                    {
                        //if(input.type == ProceduralPropertyType.Enum)
                        //TODO: Implement enum from string array editor. //input.enumOptions

                        if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                        {
                            GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                            GameObject instance     = Instantiate(editorPrefab);
                            instance.transform.SetParent(EditorsPanel, false);

                            if (instance != null)
                            {
                                editor = instance.GetComponent <PropertyEditor>();
                            }
                        }
                    }
                }
#endif

                if (editor == null)
                {
                    continue;
                }

                editor.Init(target, propertyInfo, descriptor.Label, null, descriptor.ValueChangedCallback, () =>
                {
                    RuntimeEditorApplication.SaveSelectedObjects();
                });
            }
        }
        private void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (RuntimeTools.IsPointerOverGameObject())
                {
                    return;
                }

                if (SceneCamera == null)
                {
                    Debug.LogError("Camera is null");
                    return;
                }

                if (RuntimeTools.IsViewing)
                {
                    return;
                }

                if (RuntimeTools.ActiveTool != null)
                {
                    return;
                }

                if (RuntimeEditorApplication.ActiveSceneCamera != null && !RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.SceneView))
                {
                    return;
                }

                Vector2 pointer = Input.mousePosition;
                m_dragIndex = Hit(pointer, HandlesPositions, HandlesNormals);
                if (m_dragIndex >= 0 && OnBeginDrag(m_dragIndex))
                {
                    m_handlesTransform        = HandlesTransform;
                    m_handlesInverseTransform = Matrix4x4.TRS(Target.position, Target.rotation, Target.localScale).inverse;  // m_handlesTransform.inverse;
                    m_dragPlane  = GetDragPlane();
                    m_isDragging = GetPointOnDragPlane(Input.mousePosition, out m_prevPoint);
                    m_normal     = HandlesNormals[m_dragIndex].normalized;
                    if (m_isDragging)
                    {
                        RuntimeTools.ActiveTool = this;
                    }
                    if (EnableUndo)
                    {
                        bool isRecording = RuntimeUndo.IsRecording;
                        if (!isRecording)
                        {
                            RuntimeUndo.BeginRecord();
                        }
                        RecordOverride();
                        if (!isRecording)
                        {
                            RuntimeUndo.EndRecord();
                        }
                    }
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                if (m_isDragging)
                {
                    OnDrop();
                    bool isRecording = RuntimeUndo.IsRecording;
                    if (!isRecording)
                    {
                        RuntimeUndo.BeginRecord();
                    }
                    RecordOverride();
                    if (!isRecording)
                    {
                        RuntimeUndo.EndRecord();
                    }
                    m_isDragging            = false;
                    RuntimeTools.ActiveTool = null;
                }
            }
            else
            {
                if (m_isDragging)
                {
                    Vector3 point;
                    if (GetPointOnDragPlane(Input.mousePosition, out point))
                    {
                        Vector3 offset = m_handlesInverseTransform.MultiplyVector(point - m_prevPoint);
                        offset = Vector3.Project(offset, m_normal);
                        if (InputController.GetKey(UnitSnapKey) || RuntimeTools.UnitSnapping)
                        {
                            Vector3 gridOffset = Vector3.zero;
                            if (Mathf.Abs(offset.x * 1.5f) >= GridSize)
                            {
                                gridOffset.x = GridSize * Mathf.Sign(offset.x);
                            }

                            if (Mathf.Abs(offset.y * 1.5f) >= GridSize)
                            {
                                gridOffset.y = GridSize * Mathf.Sign(offset.y);
                            }

                            if (Mathf.Abs(offset.z * 1.5f) >= GridSize)
                            {
                                gridOffset.z = GridSize * Mathf.Sign(offset.z);
                            }

                            if (gridOffset != Vector3.zero)
                            {
                                if (OnDrag(m_dragIndex, gridOffset))
                                {
                                    m_prevPoint = point;
                                }
                            }
                        }
                        else
                        {
                            if (OnDrag(m_dragIndex, offset))
                            {
                                m_prevPoint = point;
                            }
                        }
                    }
                }
            }

            UpdateOverride();
        }