protected virtual void OnObjectDestroyed(ExposeToEditor o)
 {
 }
 protected bool Filter(ExposeToEditor go)
 {
     return(go.name.ToLower().Contains(m_filter.ToLower()));
 }
 protected virtual void OnObjectStarted(ExposeToEditor obj)
 {
 }
        protected virtual void OnItemDoubleClicked(object sender, ItemArgs e)
        {
            ExposeToEditor exposeToEditor = (ExposeToEditor)e.Items[0];

            Editor.Selection.activeObject = exposeToEditor.gameObject;
        }
        protected virtual void OnItemDrop(object sender, ItemDropArgs e)
        {
            if (e.IsExternal)
            {
                return;
            }
            Transform dropT = ((ExposeToEditor)e.DropTarget).transform;

            if (e.Action == ItemDropAction.SetLastChild)
            {
                Editor.Undo.BeginRecord();
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    ExposeToEditor exposed = (ExposeToEditor)e.DragItems[i];
                    Transform      dragT   = exposed.transform;
                    dragT.SetParent(dropT, true);
                    dragT.SetAsLastSibling();

                    Editor.Undo.EndRecordTransform(dragT, dropT, dragT.GetSiblingIndex());
                }
                Editor.Undo.CreateRecord(null, null, true,
                                         record => RefreshTree(record, true),
                                         record => RefreshTree(record, false));
                Editor.Undo.EndRecord();
            }
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                Editor.Undo.BeginRecord();

                for (int i = e.DragItems.Length - 1; i >= 0; --i)
                {
                    ExposeToEditor exposed = (ExposeToEditor)e.DragItems[i];
                    Transform      dragT   = exposed.transform;

                    int dropTIndex = dropT.GetSiblingIndex();
                    if (dragT.parent != dropT.parent)
                    {
                        dragT.SetParent(dropT.parent, true);
                        dragT.SetSiblingIndex(dropTIndex + 1);
                    }
                    else
                    {
                        int dragTIndex = dragT.GetSiblingIndex();
                        if (dropTIndex < dragTIndex)
                        {
                            dragT.SetSiblingIndex(dropTIndex + 1);
                        }
                        else
                        {
                            dragT.SetSiblingIndex(dropTIndex);
                        }
                    }
                    Editor.Undo.EndRecordTransform(dragT, dragT.parent, dragT.GetSiblingIndex());
                }
                Editor.Undo.CreateRecord(null, null, true,
                                         record => RefreshTree(record, true),
                                         record => RefreshTree(record, false));
                Editor.Undo.EndRecord();
            }
            else if (e.Action == ItemDropAction.SetPrevSibling)
            {
                Editor.Undo.BeginRecord();
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    ExposeToEditor exposed = (ExposeToEditor)e.DragItems[i];
                    Transform      dragT   = exposed.transform;
                    if (dragT.parent != dropT.parent)
                    {
                        dragT.SetParent(dropT.parent, true);
                    }

                    int dropTIndex = dropT.GetSiblingIndex();
                    int dragTIndex = dragT.GetSiblingIndex();
                    if (dropTIndex > dragTIndex)
                    {
                        dragT.SetSiblingIndex(dropTIndex - 1);
                    }
                    else
                    {
                        dragT.SetSiblingIndex(dropTIndex);
                    }

                    Editor.Undo.EndRecordTransform(dragT, dragT.parent, dragT.GetSiblingIndex());
                }
                Editor.Undo.CreateRecord(null, null, true,
                                         record => RefreshTree(record, true),
                                         record => RefreshTree(record, false));
                Editor.Undo.EndRecord();
            }

            Editor.DragDrop.RaiseDrop(e.PointerEventData);
        }
Beispiel #6
0
        public override void Drop(object[] dragObjects, PointerEventData pointerEventData)
        {
            base.Drop(dragObjects, pointerEventData);

            if (CanDrop(dragObjects))
            {
                ExposeToEditor           dropTarget   = (ExposeToEditor)m_treeView.DropTarget;
                VirtualizingTreeViewItem treeViewItem = null;
                if (dropTarget != null)
                {
                    treeViewItem = m_treeView.GetTreeViewItem(m_treeView.DropTarget);
                }

                AssetItem[] loadAssetItems = dragObjects.Where(o => o is AssetItem && m_project.ToType((AssetItem)o) == typeof(GameObject)).Select(o => (AssetItem)o).ToArray();
                if (loadAssetItems.Length > 0)
                {
                    m_isSpawningPrefab = true;
                    Editor.IsBusy      = true;
                    m_project.Load(loadAssetItems, (error, objects) =>
                    {
                        Editor.IsBusy = false;
                        if (error.HasError)
                        {
                            IWindowManager wm = IOC.Resolve <IWindowManager>();
                            wm.MessageBox("Unable to load asset items.", error.ErrorText);
                            return;
                        }

                        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 = Instantiate(prefab, Vector3.zero, Quaternion.identity);
                            prefab.SetActive(wasPrefabEnabled);

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

                            exposeToEditor.SetName(prefab.name);

                            if (dropTarget == null)
                            {
                                exposeToEditor.transform.SetParent(null);
                                m_treeView.Add(exposeToEditor);
                            }
                            else
                            {
                                if (m_treeView.DropAction == ItemDropAction.SetLastChild)
                                {
                                    exposeToEditor.transform.SetParent(dropTarget.transform);
                                    m_treeView.AddChild(dropTarget, exposeToEditor);
                                    treeViewItem.CanExpand  = true;
                                    treeViewItem.IsExpanded = true;
                                }
                                else if (m_treeView.DropAction != ItemDropAction.None)
                                {
                                    int index;
                                    int siblingIndex;
                                    if (m_treeView.DropAction == 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;
                                    }
                                }
                            }

                            prefabInstance.SetActive(true);
                            createdObjects[i] = prefabInstance;
                        }

                        if (createdObjects.Length > 0)
                        {
                            IRuntimeEditor editor = IOC.Resolve <IRuntimeEditor>();
                            editor.RegisterCreatedObjects(createdObjects);
                        }

                        m_treeView.ExternalItemDrop();
                        m_isSpawningPrefab = false;
                    });
                }
                else
                {
                    m_treeView.ExternalItemDrop();
                }
            }
            else
            {
                m_treeView.ExternalItemDrop();
            }
        }
        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;
        }
Beispiel #8
0
 private void OnObjectDestroyed(ExposeToEditor obj)
 {
     m_listBox.Remove(obj.gameObject);
 }
Beispiel #9
0
        private void CreateEditor()
        {
            DestroyEditor();

            if (Editor.Selection.activeObject == null)
            {
                return;
            }

            UnityObject[] selectedObjects = Editor.Selection.objects.Where(o => o != null).ToArray();
            if (selectedObjects.Length != 1)
            {
                return;
            }

            Type objType = selectedObjects[0].GetType();

            for (int i = 1; i < selectedObjects.Length; ++i)
            {
                if (objType != selectedObjects[i].GetType())
                {
                    return;
                }
            }

            ExposeToEditor exposeToEditor = Editor.Selection.activeGameObject != null?
                                            Editor.Selection.activeGameObject.GetComponent <ExposeToEditor>() :
                                                null;

            if (exposeToEditor != null && !exposeToEditor.CanInspect)
            {
                return;
            }

            GameObject editorPrefab;

            if (objType == typeof(Material))
            {
                Material mat = selectedObjects[0] as Material;
                if (mat.shader == null)
                {
                    return;
                }

                editorPrefab = m_editorsMap.GetMaterialEditor(mat.shader);
            }
            else
            {
                if (!m_editorsMap.IsObjectEditorEnabled(objType))
                {
                    return;
                }
                editorPrefab = m_editorsMap.GetObjectEditor(objType);
            }

            if (editorPrefab != null)
            {
                m_editor = Instantiate(editorPrefab);
                m_editor.transform.SetParent(m_panel, false);
                m_editor.transform.SetAsFirstSibling();
            }

            if (m_addComponentRoot != null && exposeToEditor)
            {
                IProject project = IOC.Resolve <IProject>();
                if (project == null || project.ToAssetItem(Editor.Selection.activeGameObject) == null)
                {
                    m_addComponentRoot.SetActive(true);
                    if (m_addComponentControl != null)
                    {
                        m_addComponentControl.ComponentSelected += OnAddComponent;
                    }
                }
            }
        }
Beispiel #10
0
        private bool CanExposeToEditor(GameObject go)
        {
            ExposeToEditor exposeToEditor = go.GetComponent <ExposeToEditor>();

            return(exposeToEditor != null);
        }
Beispiel #11
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;
                        }
                    }
                }
            }
        }
Beispiel #12
0
 private void OnObjectDestroyed(ExposeToEditor obj)
 {
     m_treeView.Remove(obj.gameObject);
 }
Beispiel #13
0
 private void OnObjectStarted(ExposeToEditor obj)
 {
 }
Beispiel #14
0
        private void OnItemDrop(object sender, ItemDropArgs e)
        {
            if (e.IsExternal)
            {
                if (e.DragItems != null)
                {
                    for (int i = 0; i < e.DragItems.Length; ++i)
                    {
                        GameObject prefab = e.DragItems[i] as GameObject;
                        if (prefab != null)
                        {
                            if (RuntimePrefabs.IsPrefab(prefab.transform))
                            {
                                GameObject     prefabInstance = Instantiate(prefab);
                                ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>();
                                if (exposeToEditor != null)
                                {
                                    exposeToEditor.SetName(prefab.name);
                                }
                                prefabInstance.transform.position   = prefab.transform.position;
                                prefabInstance.transform.rotation   = prefab.transform.rotation;
                                prefabInstance.transform.localScale = prefab.transform.localScale;
                                RuntimeSelection.activeGameObject   = prefabInstance;
                            }
                        }
                    }
                }
            }
            else
            {
                Transform dropT = ((GameObject)e.DropTarget).transform;
                if (e.Action == ItemDropAction.SetLastChild)
                {
                    for (int i = 0; i < e.DragItems.Length; ++i)
                    {
                        Transform dragT = ((GameObject)e.DragItems[i]).transform;
                        dragT.SetParent(dropT, true);
                        dragT.SetAsLastSibling();
                    }
                }
                else if (e.Action == ItemDropAction.SetNextSibling)
                {
                    for (int i = e.DragItems.Length - 1; i >= 0; --i)
                    {
                        Transform dragT      = ((GameObject)e.DragItems[i]).transform;
                        int       dropTIndex = dropT.GetSiblingIndex();
                        if (dragT.parent != dropT.parent)
                        {
                            dragT.SetParent(dropT.parent, true);
                            dragT.SetSiblingIndex(dropTIndex + 1);
                        }
                        else
                        {
                            int dragTIndex = dragT.GetSiblingIndex();
                            if (dropTIndex < dragTIndex)
                            {
                                dragT.SetSiblingIndex(dropTIndex + 1);
                            }
                            else
                            {
                                dragT.SetSiblingIndex(dropTIndex);
                            }
                        }
                    }
                }
                else if (e.Action == ItemDropAction.SetPrevSibling)
                {
                    for (int i = 0; i < e.DragItems.Length; ++i)
                    {
                        Transform dragT = ((GameObject)e.DragItems[i]).transform;
                        if (dragT.parent != dropT.parent)
                        {
                            dragT.SetParent(dropT.parent, true);
                        }

                        int dropTIndex = dropT.GetSiblingIndex();
                        int dragTIndex = dragT.GetSiblingIndex();
                        if (dropTIndex > dragTIndex)
                        {
                            dragT.SetSiblingIndex(dropTIndex - 1);
                        }
                        else
                        {
                            dragT.SetSiblingIndex(dropTIndex);
                        }
                    }
                }
            }
        }
 protected virtual void OnObjectMarkAsDestoryedChanging(ExposeToEditor o)
 {
 }
        public ProjectAsyncOperation <AssetItem[]> CreatePrefab(ProjectItem dropTarget, ExposeToEditor dragObject, bool?includeDependencies, Action <AssetItem[]> done)
        {
            SelectionGizmoModel gizmo = dragObject.GetComponentInChildren <SelectionGizmoModel>();

            if (gizmo != null)
            {
                gizmo.transform.SetParent(null);
                gizmo.gameObject.SetActive(false);
            }

            Action <AssetItem[]> callback = assetItems =>
            {
                if (gizmo != null)
                {
                    gizmo.transform.SetParent(dragObject.transform);
                    gizmo.gameObject.SetActive(true);
                }

                if (done != null)
                {
                    done(assetItems);
                }
            };

            ProjectAsyncOperation <AssetItem[]> ao = new ProjectAsyncOperation <AssetItem[]>();

            if (!includeDependencies.HasValue)
            {
                m_wm.Confirmation("Create Prefab", "Include dependencies?",
                                  (sender, args) =>
                {
                    CreatePrefabWithDependencies(dropTarget, dragObject, result => OnCreatePrefabWithDepenenciesCompleted(result, ao, callback));
                },
                                  (sender, args) =>
                {
                    CreatePrefabWithoutDependencies(dropTarget, dragObject, result => OnCreatePrefabWithDepenenciesCompleted(result, ao, callback));
                },
                                  "Yes",
                                  "No");
            }
            else
            {
                if (includeDependencies.Value)
                {
                    CreatePrefabWithDependencies(dropTarget, dragObject, result => OnCreatePrefabWithDepenenciesCompleted(result, ao, callback));
                }
                else
                {
                    CreatePrefabWithoutDependencies(dropTarget, dragObject, result => OnCreatePrefabWithDepenenciesCompleted(result, ao, callback));
                }
            }

            return(ao);
        }
        protected virtual void OnParentChanged(ExposeToEditor obj, ExposeToEditor oldParent, ExposeToEditor newParent)
        {
            if (Editor.IsPlaymodeStateChanging)
            {
                return;
            }

            if (!IsFilterEmpty)
            {
                return;
            }

            bool isNewParentExpanded = true;
            bool isOldParentExpanded = true;
            bool isLastChild         = false;

            if (newParent != null)
            {
                isNewParentExpanded = m_treeView.IsExpanded(newParent);
            }

            if (oldParent != null)
            {
                TreeViewItemContainerData itemContainerData = (TreeViewItemContainerData)m_treeView.GetItemContainerData(oldParent);

                isLastChild = !oldParent.HasChildren(); //!itemContainerData.HasChildren(m_treeView);

                isOldParentExpanded = m_treeView.IsExpanded(oldParent);
            }

            if (isNewParentExpanded)
            {
                m_treeView.ChangeParent(newParent, obj);

                if (!isOldParentExpanded)
                {
                    if (isLastChild)
                    {
                        VirtualizingTreeViewItem oldParentContainer = m_treeView.GetTreeViewItem(oldParent);
                        if (oldParentContainer)
                        {
                            oldParentContainer.CanExpand = false;
                        }
                    }
                }
            }
            else
            {
                if (newParent != null)
                {
                    VirtualizingTreeViewItem newParentTreeViewItem = m_treeView.GetTreeViewItem(newParent);
                    if (newParentTreeViewItem != null)
                    {
                        newParentTreeViewItem.CanExpand = true;
                    }
                }

                m_treeView.RemoveChild(oldParent, obj);
            }
        }
Beispiel #18
0
 private void OnObjectDestroyed(ExposeToEditor o)
 {
 }