Пример #1
0
        void IDropHandler.OnDrop(PointerEventData eventData)
        {
            GameObject go = eventData.pointerDrag;

            if (go != null)
            {
                ItemContainer itemContainer = go.GetComponent <ItemContainer>();
                if (itemContainer != null && itemContainer.Item != null)
                {
                    object item = itemContainer.Item;
                    if (item != null && item is GameObject)
                    {
                        GameObject prefab = item as GameObject;
                        if (RuntimePrefabs.IsPrefab(prefab.transform))
                        {
                            Ray ray = Camera.ScreenPointToRay(Input.mousePosition);
                            //Plane p = new Plane(Vector3.up, Vector3.zero);
                            float distance;
                            //if(!p.Raycast(ray, out distance))
                            {
                                distance = 15;
                            }
                            Vector3        worldPoint     = ray.GetPoint(distance);
                            GameObject     prefabInstance = Instantiate(prefab);
                            ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>();
                            if (exposeToEditor != null)
                            {
                                exposeToEditor.SetName(prefab.name);
                            }
                            prefabInstance.transform.position   = worldPoint;
                            prefabInstance.transform.rotation   = prefab.transform.rotation;
                            prefabInstance.transform.localScale = prefab.transform.localScale;
                            RuntimeSelection.activeGameObject   = prefabInstance;
                        }
                    }
                }
            }
        }
Пример #2
0
        private static void HideFromEditor()
        {
            RuntimeEditor     editor = Object.FindObjectOfType <RuntimeEditor>();
            List <GameObject> prefabs;

            if (editor != null)
            {
                Undo.RecordObject(editor, "Battlehub.RTEditor.ExposeToEditor");
                prefabs = new List <GameObject>(editor.Prefabs);
            }
            else
            {
                prefabs = new List <GameObject>();
            }

            foreach (GameObject go in Selection.gameObjects)
            {
                if (RuntimePrefabs.IsPrefab(go.transform))
                {
                    prefabs.Remove(go);
                }
                else
                {
                    ExposeToEditor exposeToEditor = go.GetComponent <ExposeToEditor>();
                    if (exposeToEditor != null)
                    {
                        Undo.DestroyObjectImmediate(exposeToEditor);
                    }
                }
            }

            if (editor != null)
            {
                editor.Prefabs = prefabs.ToArray();
            }

            EditorUtility.SetDirty(editor);
        }
Пример #3
0
 private void OnRuntimeSelectionChanged(Object[] unselected)
 {
     if (RuntimeSelection.activeGameObject == null ||
         RuntimePrefabs.IsPrefab(RuntimeSelection.activeGameObject.transform))
     {
         if (m_positionHandle != null)
         {
             m_positionHandle.gameObject.SetActive(false);
         }
         if (m_rotationHandle != null)
         {
             m_rotationHandle.gameObject.SetActive(false);
         }
         if (m_scaleHandle != null)
         {
             m_scaleHandle.gameObject.SetActive(false);
         }
     }
     else
     {
         OnRuntimeToolChanged();
     }
 }
Пример #4
0
        private static void ExposeToEditor()
        {
            RuntimeEditor editor = Object.FindObjectOfType <RuntimeEditor>();

            Undo.RecordObject(editor, "Battlehub.RTEditor.ExposeToEditor");
            List <GameObject> prefabs = new List <GameObject>(editor.Prefabs);

            foreach (GameObject go in Selection.gameObjects)
            {
                if (RuntimePrefabs.IsPrefab(go.transform))
                {
                    prefabs.Add(go);
                }
                else
                {
                    Undo.RegisterCreatedObjectUndo(go.AddComponent <ExposeToEditor>(), "Battlehub.RTEditor.ExposeToEditor");
                }
            }

            editor.Prefabs = prefabs.ToArray();

            EditorUtility.SetDirty(editor);
        }
Пример #5
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 = 0; i < e.DragItems.Length; ++i)
                    {
                        Transform dragT = ((GameObject)e.DragItems[i]).transform;
                        if (dragT.parent != dropT.parent)
                        {
                            dragT.SetParent(dropT.parent, true);
                        }

                        int siblingIndex = dropT.GetSiblingIndex();
                        dragT.SetSiblingIndex(siblingIndex + 1);
                    }
                }
                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 siblingIndex = dropT.GetSiblingIndex();
                        dragT.SetSiblingIndex(siblingIndex);
                    }
                }
            }
        }
Пример #6
0
        private void Start()
        {
            if (!TreeViewPrefab)
            {
                Debug.LogError("Set TreeViewPrefab field");
                return;
            }

            m_treeView = Instantiate(TreeViewPrefab).GetComponent <TreeView>();
            m_treeView.transform.SetParent(transform, false);

            m_treeView.ItemDataBinding  += OnItemDataBinding;
            m_treeView.SelectionChanged += OnSelectionChanged;
            m_treeView.ItemsRemoved     += OnItemsRemoved;
            m_treeView.ItemExpanding    += OnItemExpanding;
            m_treeView.ItemBeginDrag    += OnItemBeginDrag;
            m_treeView.ItemDrop         += OnItemDrop;
            m_treeView.ItemEndDrag      += OnItemEndDrag;

            RuntimeSelection.SelectionChanged += OnRuntimeSelectionChanged;
#if UNITY_EDITOR
            UnityEditor.Selection.selectionChanged += OnEditorSelectionChanged;
#endif

            HashSet <GameObject> filtered = new HashSet <GameObject>();
            GameObject[]         objects  = Resources.FindObjectsOfTypeAll <GameObject>();
            for (int i = 0; i < objects.Length; ++i)
            {
                GameObject obj = objects[i] as GameObject;
                if (obj == null)
                {
                    continue;
                }

                if (!RuntimePrefabs.IsPrefab(obj.transform))
                {
                    if (TypeCriteria == typeof(GameObject))
                    {
                        filtered.Add(obj);
                    }
                    else
                    {
                        Component component = obj.GetComponent(TypeCriteria);
                        if (component)
                        {
                            if (!filtered.Contains(component.gameObject))
                            {
                                filtered.Add(component.gameObject);
                            }
                        }
                    }
                }
            }

            m_treeView.Items = filtered.Where(f => f.transform.parent == null && CanExposeToEditor(f)).OrderBy(t => t.transform.GetSiblingIndex());

            ExposeToEditor.Awaked        += OnObjectAwaked;
            ExposeToEditor.Started       += OnObjectStarted;
            ExposeToEditor.Enabled       += OnObjectEnabled;
            ExposeToEditor.Disabled      += OnObjectDisabled;
            ExposeToEditor.Destroyed     += OnObjectDestroyed;
            ExposeToEditor.ParentChanged += OnParentChanged;
            ExposeToEditor.NameChanged   += OnNameChanged;
        }