Example #1
0
        private object OnNewShape(object arg)
        {
            GameObject     go;
            ExposeToEditor exposeToEditor;

            CreateNewShape((PBShapeType)arg, out go, out exposeToEditor);

            IRuntimeEditor             rte   = IOC.Resolve <IRuntimeEditor>();
            RuntimeWindow              scene = rte.GetWindow(RuntimeWindowType.Scene);
            IRuntimeSelectionComponent selectionComponent = null;

            if (scene != null)
            {
                selectionComponent = scene.IOCContainer.Resolve <IRuntimeSelectionComponent>();
            }

            Editor.Undo.BeginRecord();
            if (selectionComponent == null || selectionComponent.CanSelect)
            {
                Editor.Selection.activeGameObject = go;
            }

            Editor.Undo.RegisterCreatedObjects(new[] { exposeToEditor });
            Editor.Undo.EndRecord();

            return(go);
        }
Example #2
0
        protected override void Start()
        {
            base.Start();

            m_plane = new Plane(Vector3.forward, 0);

            m_graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>();
            CreateUVRenderers();
            m_graphicsLayer.Camera.RenderersCache.Refresh();
            m_uvEditor.RefreshPivotPoint();

            m_selectionComponent = Window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
            m_selectionComponent.BoxSelection.Selection += OnBoxSelection;

            m_selectionComponent.PositionHandle.BeforeDrag.AddListener(OnBeginMove);
            m_selectionComponent.PositionHandle.Drag.AddListener(OnMove);
            m_selectionComponent.PositionHandle.Drop.AddListener(OnEndMove);

            m_selectionComponent.RotationHandle.BeforeDrag.AddListener(OnBeginRotate);
            m_selectionComponent.RotationHandle.Drag.AddListener(OnRotate);
            m_selectionComponent.RotationHandle.Drop.AddListener(OnEndRotate);

            m_selectionComponent.ScaleHandle.BeforeDrag.AddListener(OnBeginScale);
            m_selectionComponent.ScaleHandle.Drag.AddListener(OnScale);
            m_selectionComponent.ScaleHandle.Drop.AddListener(OnEndScale);
        }
Example #3
0
        public void ResetPosition()
        {
            if (m_selectedHandles != null)
            {
                foreach (int hid in m_selectedHandles)
                {
                    GameObject handle;
                    if (!m_keyToHandle.TryGetValue(hid, out handle))
                    {
                        Debug.LogWarningFormat("Handle {0} was not found", hid);
                        continue;
                    }

                    Vector3 pos = handle.transform.localPosition;
                    pos.y = 0;
                    handle.transform.localPosition = pos;
                    UpdateTerrain(hid, pos, GetInterpolatedHeights, SetTerrainHeights);
                }

                IWindowManager wm = IOC.Resolve <IWindowManager>();
                foreach (Transform windowTransform in wm.GetWindows(RuntimeWindowType.Scene.ToString()))
                {
                    RuntimeWindow window = windowTransform.GetComponent <RuntimeWindow>();
                    if (window == null)
                    {
                        continue;
                    }
                    IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                    if (selectionComponent != null && selectionComponent.CustomHandle != null)
                    {
                        selectionComponent.CustomHandle.Refresh();
                    }
                }
            }
        }
        protected override void AwakeOverride()
        {
            base.AwakeOverride();

            m_component = m_window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
            Window.IOCContainer.RegisterFallback <ISelectionComponentState>(this);
        }
        protected virtual void Activate()
        {
            foreach (Transform windowTranform in m_windowToHandle.Keys)
            {
                RuntimeWindow window = windowTranform.GetComponentInChildren <RuntimeWindow>();
                IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                selectionComponent.CustomHandle = m_windowToHandle[windowTranform];
            }

            SetCurrentTool(RuntimeTool.Custom);
        }
Example #6
0
        private void OnCreateCustomHandle(IRuntimeSelectionComponent selectionComponent)
        {
            if (selectionComponent != null && selectionComponent.CustomHandle == null)
            {
                m_positionHandlePrefab.gameObject.SetActive(false);

                selectionComponent.CustomHandle       = Instantiate(m_positionHandlePrefab, transform);
                selectionComponent.Filtering         += OnSelectionFiltering;
                selectionComponent.SelectionChanging += OnSelectionChanging;
                selectionComponent.CustomHandle.BeforeDrag.AddListener(OnBeforeDrag);
                selectionComponent.CustomHandle.Drop.AddListener(OnDrop);
            }
        }
        private void OnActiveWindowChanged(RuntimeWindow deactivatedWindow)
        {
            if (m_selectionComponent != null)
            {
                m_selectionComponent.SelectionChanging -= OnSelectionChanging;
            }

            if (m_editor.ActiveWindow != null && m_editor.ActiveWindow.WindowType == RuntimeWindowType.Scene)
            {
                m_selectionComponent = m_editor.ActiveWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                m_selectionComponent.SelectionChanging += OnSelectionChanging;
            }
        }
Example #8
0
 private void OnDestroyCustomHandle(IRuntimeSelectionComponent selectionComponent)
 {
     if (selectionComponent != null && selectionComponent.CustomHandle != null)
     {
         selectionComponent.Filtering         -= OnSelectionFiltering;
         selectionComponent.SelectionChanging -= OnSelectionChanging;
         selectionComponent.CustomHandle.BeforeDrag.RemoveListener(OnBeforeDrag);
         selectionComponent.CustomHandle.Drop.RemoveListener(OnDrop);
         selectionComponent.Selection = null;
         Destroy(selectionComponent.CustomHandle.gameObject);
         selectionComponent.CustomHandle = null;
     }
 }
Example #9
0
 private void SetCanSelect(bool value)
 {
     Transform[] windows = m_wm.GetWindows(RuntimeWindowType.Scene.ToString());
     for (int i = 0; i < windows.Length; ++i)
     {
         RuntimeWindow window = windows[i].GetComponent <RuntimeWindow>();
         IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
         if (selectionComponent != null)
         {
             selectionComponent.CanSelect    = value;
             selectionComponent.CanSelectAll = value;
         }
     }
 }
Example #10
0
        private void OnActiveWindowChanged(RuntimeWindow window)
        {
            UnsubscribeFromEvents();

            if (m_rte.ActiveWindow != null && m_rte.ActiveWindow.WindowType == RuntimeWindowType.Scene)
            {
                m_selectionComponent = m_rte.ActiveWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
            }
            else
            {
                m_selectionComponent = null;
            }

            SubscribeToEvents();
        }
Example #11
0
 private void OnActiveWindowChanged(RuntimeWindow window)
 {
     if (m_editor.ActiveWindow != null && m_editor.ActiveWindow.WindowType == RuntimeWindowType.Scene)
     {
         m_updateRenderers    = true;
         m_activeWindow       = m_editor.ActiveWindow;
         m_selectionComponent = m_activeWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
     }
     else
     {
         m_activeWindow       = null;
         m_selectionComponent = null;
         m_renderers          = null;
     }
 }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.U))
            {
                foreach (Transform windowTranform in m_windowToHandle.Keys)
                {
                    RuntimeWindow window = windowTranform.GetComponentInChildren <RuntimeWindow>();
                    IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                    selectionComponent.CustomHandle = m_windowToHandle[windowTranform];
                }

                IRTE rte = IOC.Resolve <IRTE>();
                rte.Tools.Current = RuntimeTool.Custom;
            }
        }
Example #13
0
        protected virtual void RecordUndo()
        {
            ExposeToEditor exposeToEditor = m_prefabInstance.GetComponent <ExposeToEditor>();

            Editor.Undo.BeginRecord();
            Editor.Undo.RegisterCreatedObjects(new[] { exposeToEditor });

            IRuntimeSelectionComponent selectionComponent = IOCContainer.Resolve <IRuntimeSelectionComponent>();

            if (selectionComponent.CanSelect)
            {
                Editor.Selection.activeGameObject = m_prefabInstance;
            }
            Editor.Undo.EndRecord();
        }
Example #14
0
        private void Start()
        {
            m_tool              = IOC.Resolve <IProBuilderTool>();
            m_tool.ModeChanged += OnModeChanged;

            if (m_rte != null)
            {
                m_rte.ActiveWindowChanged += OnActiveWindowChanged;

                if (m_rte.ActiveWindow != null && m_rte.ActiveWindow.WindowType == RuntimeWindowType.Scene)
                {
                    m_selectionComponent = m_rte.ActiveWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                    SubscribeToEvents();
                }
            }
        }
        protected virtual void  Deactivate()
        {
            foreach (Transform windowTranform in m_windowToHandle.Keys)
            {
                RuntimeWindow window = windowTranform.GetComponentInChildren <RuntimeWindow>();
                BaseHandle    handle = m_windowToHandle[windowTranform];
                if (handle != null)
                {
                    handle.gameObject.SetActive(false);
                }

                IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                selectionComponent.CustomHandle = null;
            }

            SetCurrentTool(RuntimeTool.None);
        }
Example #16
0
        private void OnSelectionChanging(object sender, RuntimeSelectionChangingArgs e)
        {
            if (m_editor.Tools.Custom is EditorType)
            {
                EditorType editorType = (EditorType)m_editor.Tools.Custom;
                if (editorType != EditorType.Empty)
                {
                    IRuntimeSelectionComponent component = (IRuntimeSelectionComponent)sender;
                    RaycastHit[] hits = Physics.RaycastAll(component.Window.Pointer);

                    if (Terrain != null && hits.Any(hit => hit.collider.gameObject == Terrain.gameObject))
                    {
                        e.Cancel = true;
                    }
                }
            }
        }
        public static void AddGameObjectToScene(this IRTE editor, GameObject go)
        {
            Vector3 pivot = Vector3.zero;
            IRuntimeSelectionComponent selectionComponent = editor.GetScenePivot();

            if (selectionComponent != null)
            {
                pivot = selectionComponent.SecondaryPivot;
            }

            editor.AddGameObjectToHierarchy(go);

            go.transform.position = pivot;
            go.AddComponent <ExposeToEditor>();
            go.SetActive(true);
            editor.RegisterCreatedObjects(new[] { go }, selectionComponent != null ? selectionComponent.CanSelect : true);
        }
        private void TryToDisableCustomSelection(Transform windowTransform)
        {
            RuntimeWindow window = windowTransform.GetComponent <RuntimeWindow>();

            if (window != null && window.WindowType == RuntimeWindowType.Scene)
            {
                IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                if (selectionComponent != null)
                {
                    selectionComponent.Selection = null;
                    if (DestroyCustomHandle != null)
                    {
                        DestroyCustomHandle(selectionComponent);
                    }
                }
            }
        }
Example #19
0
        private void Start()
        {
            IOC.Register("HighlightRenderers", m_cache = gameObject.AddComponent <RenderersCache>());

            m_editor = IOC.Resolve <IRTE>();

            m_activeWindow = m_editor.ActiveWindow;
            if (m_activeWindow != null && m_editor.ActiveWindow.WindowType == RuntimeWindowType.Scene)
            {
                m_selectionComponent = m_activeWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
            }

            m_editor.Object.Enabled        += OnObjectEnabled;
            m_editor.Object.Disabled       += OnObjectDisabled;
            m_editor.Object.ComponentAdded += OnComponentAdded;

            m_editor.Selection.SelectionChanged += OnSelectionChanged;
            m_editor.ActiveWindowChanged        += OnActiveWindowChanged;
        }
Example #20
0
        private void SubscribeSelectionChangingEvent(bool subscribe, RuntimeWindow window)
        {
            if (window != null && window.WindowType == RuntimeWindowType.Scene)
            {
                IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();

                if (selectionComponent != null)
                {
                    if (subscribe)
                    {
                        selectionComponent.SelectionChanging += OnSelectionChanging;
                    }
                    else
                    {
                        selectionComponent.SelectionChanging -= OnSelectionChanging;
                    }
                }
            }
        }
Example #21
0
        private void Start()
        {
            SetCanSelect(Mode == ProBuilderToolMode.Object);
            if (m_rte.ActiveWindow != null && m_rte.ActiveWindow.WindowType == RuntimeWindowType.Scene)
            {
                m_selectionComponent = m_rte.ActiveWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                m_boxSelection       = m_rte.ActiveWindow.IOCContainer.Resolve <IBoxSelection>();

                SubscribeToEvents();
            }

            if (m_rte != null)
            {
                m_rte.ActiveWindowChanged         += OnActiveWindowChanged;
                m_rte.Tools.PivotModeChanging     += OnPivotModeChanging;
                m_rte.Tools.PivotModeChanged      += OnPivotModeChanged;
                m_rte.Tools.PivotRotationChanging += OnPivotRotationChanging;
                m_rte.Tools.PivotRotationChanged  += OnPivotRotationChanged;
                m_rte.SceneLoading += OnSceneLoading;
            }
        }
Example #22
0
        private void OnWindowCreated(Transform windowTransform)
        {
            if (m_mode == ProBuilderToolMode.Object)
            {
                return;
            }

            RuntimeWindow window = windowTransform.GetComponentInChildren <RuntimeWindow>(true);

            if (window.WindowType != RuntimeWindowType.Scene)
            {
                return;
            }

            IRuntimeSelectionComponent selectionComponent = window.IOCContainer.Resolve <IRuntimeSelectionComponent>();

            if (selectionComponent != null)
            {
                selectionComponent.CanSelect    = false;
                selectionComponent.CanSelectAll = false;
            }
        }
        public static IRuntimeSelectionComponent GetScenePivot(this IRTE editor)
        {
            if (editor.ActiveWindow != null)
            {
                IRuntimeSceneComponent scenePivot = editor.ActiveWindow.IOCContainer.Resolve <IRuntimeSceneComponent>();
                if (scenePivot != null)
                {
                    return(scenePivot);
                }
            }

            RuntimeWindow sceneWindow = editor.GetWindow(RuntimeWindowType.Scene);

            if (sceneWindow != null)
            {
                IRuntimeSelectionComponent scenePivot = sceneWindow.IOCContainer.Resolve <IRuntimeSelectionComponent>();
                if (scenePivot != null)
                {
                    return(scenePivot);
                }
            }

            return(null);
        }
Example #24
0
        protected virtual void OnDrop(PointerEventData pointerEventData)
        {
            if (m_prefabInstance != null)
            {
                RecordUndo();
                m_prefabInstance           = null;
                m_prefabInstanceTransforms = null;
            }

            if (m_dropTarget != null)
            {
                MeshRenderer        renderer  = m_dropTarget.GetComponentInChildren <MeshRenderer>();
                SkinnedMeshRenderer sRenderer = m_dropTarget.GetComponentInChildren <SkinnedMeshRenderer>();

                if (renderer != null || sRenderer != null)
                {
                    AssetItem assetItem = (AssetItem)Editor.DragDrop.DragObjects[0];
                    Editor.IsBusy = true;
                    m_project.Load(new[] { assetItem }, (error, obj) =>
                    {
                        Editor.IsBusy = false;

                        if (error.HasError)
                        {
                            IWindowManager wm = IOC.Resolve <IWindowManager>();
                            if (wm != null)
                            {
                                wm.MessageBox("Unable to load asset item ", error.ErrorText);
                            }
                            return;
                        }

                        if (obj[0] is Material)
                        {
                            if (renderer != null)
                            {
                                Editor.Undo.BeginRecordValue(renderer, Strong.PropertyInfo((MeshRenderer x) => x.sharedMaterials, "sharedMaterials"));
                                Material[] materials = renderer.sharedMaterials;
                                for (int i = 0; i < materials.Length; ++i)
                                {
                                    materials[i] = (Material)obj[0];
                                }
                                renderer.sharedMaterials = materials;
                            }

                            if (sRenderer != null)
                            {
                                Editor.Undo.BeginRecordValue(sRenderer, Strong.PropertyInfo((SkinnedMeshRenderer x) => x.sharedMaterials, "sharedMaterials"));
                                Material[] materials = sRenderer.sharedMaterials;
                                for (int i = 0; i < materials.Length; ++i)
                                {
                                    materials[i] = (Material)obj[0];
                                }
                                sRenderer.sharedMaterials = materials;
                            }

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

                            if (renderer != null)
                            {
                                Editor.Undo.EndRecordValue(renderer, Strong.PropertyInfo((MeshRenderer x) => x.sharedMaterials, "sharedMaterials"));
                            }

                            if (sRenderer != null)
                            {
                                Editor.Undo.EndRecordValue(sRenderer, Strong.PropertyInfo((SkinnedMeshRenderer x) => x.sharedMaterials, "sharedMaterials"));
                            }

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

                m_dropTarget = null;
                m_dragItem   = null;
            }


            IToolCmd cmd = Editor.DragDrop.DragObjects.OfType <IToolCmd>().FirstOrDefault();

            if (cmd != null)
            {
                GameObject go = cmd.Run() as GameObject;
                if (go != null)
                {
                    CreateDragPlane();
                    Vector3 point;
                    if (GetPointOnDragPlane(out point))
                    {
                        m_point = point;

                        RaycastHit hit = Physics.RaycastAll(Pointer).FirstOrDefault();
                        if (hit.transform != null)
                        {
                            m_point = hit.point;
                        }

                        ExposeToEditor exposeToEditor = go.GetComponent <ExposeToEditor>();
                        go.transform.position = m_point + Vector3.up * exposeToEditor.Bounds.extents.y;

                        IRuntimeSelectionComponent selectionComponent = IOCContainer.Resolve <IRuntimeSelectionComponent>();
                        if (selectionComponent.CanSelect)
                        {
                            bool wasEnabled = Editor.Undo.Enabled;
                            Editor.Undo.Enabled = false;
                            Editor.Selection.activeGameObject = null;
                            Editor.Selection.activeGameObject = go;
                            Editor.Undo.Enabled = wasEnabled;
                        }
                    }
                }
            }
        }
        protected void OnAssetItemsLoaded(Object[] objects, ExposeToEditor dropTarget, VirtualizingTreeViewItem treeViewItem)
        {
            m_selectionComponent = Editor.GetScenePivot();

            GameObject[] createdObjects = new GameObject[objects.Length];
            for (int i = 0; i < objects.Length; ++i)
            {
                GameObject prefab           = (GameObject)objects[i];
                bool       wasPrefabEnabled = prefab.activeSelf;
                prefab.SetActive(false);
                GameObject prefabInstance = InstantiatePrefab(prefab);
                Editor.AddGameObjectToHierarchy(prefabInstance);
                prefab.SetActive(wasPrefabEnabled);

                ExposeToEditor exposeToEditor = ExposePrefabInstance(prefabInstance);
                exposeToEditor.SetName(prefab.name);

                if (dropTarget == null)
                {
                    exposeToEditor.transform.SetParent(null);
                    m_treeView.Add(exposeToEditor);
                }
                else
                {
                    if (m_lastDropAction == ItemDropAction.SetLastChild)
                    {
                        exposeToEditor.transform.SetParent(dropTarget.transform);
                        m_treeView.AddChild(dropTarget, exposeToEditor);
                        treeViewItem.CanExpand  = true;
                        treeViewItem.IsExpanded = true;
                    }
                    if (m_lastDropAction != ItemDropAction.None && m_lastDropAction != ItemDropAction.SetLastChild)
                    {
                        int index;
                        int siblingIndex;
                        if (m_lastDropAction == ItemDropAction.SetNextSibling)
                        {
                            index        = m_treeView.IndexOf(dropTarget) + 1;
                            siblingIndex = dropTarget.transform.GetSiblingIndex() + 1;
                        }
                        else
                        {
                            index        = m_treeView.IndexOf(dropTarget);
                            siblingIndex = dropTarget.transform.GetSiblingIndex();
                        }

                        exposeToEditor.transform.SetParent(dropTarget.transform.parent != null ? dropTarget.transform.parent : null);
                        exposeToEditor.transform.SetSiblingIndex(siblingIndex);

                        TreeViewItemContainerData newTreeViewItemData = (TreeViewItemContainerData)m_treeView.Insert(index, exposeToEditor);
                        VirtualizingTreeViewItem  newTreeViewItem     = m_treeView.GetTreeViewItem(exposeToEditor);
                        if (newTreeViewItem != null)
                        {
                            newTreeViewItem.Parent = treeViewItem.Parent;
                        }
                        else
                        {
                            newTreeViewItemData.Parent = treeViewItem.Parent;
                        }
                    }
                }

                OnActivatePrefabInstance(prefabInstance);
                createdObjects[i] = prefabInstance;
            }

            if (createdObjects.Length > 0)
            {
                IRuntimeEditor editor = IOC.Resolve <IRuntimeEditor>();
                editor.RegisterCreatedObjects(createdObjects, m_selectionComponent != null ? m_selectionComponent.CanSelect : true);
            }

            m_treeView.ExternalItemDrop();
            m_isSpawningPrefab = false;
        }