FindPrefabRoot() приватный Метод

private FindPrefabRoot ( GameObject source ) : GameObject
source UnityEngine.GameObject
Результат UnityEngine.GameObject
Пример #1
0
 public static GameObject FindPrefabRoot(GameObject source)
 {
     return(PrefabUtility.FindPrefabRoot(source));
 }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject gameObject = this.target as GameObject;
            PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);

            if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab)
            {
                return;
            }
            Event     current = Event.current;
            EventType type    = current.type;

            if (type != EventType.DragUpdated)
            {
                if (type != EventType.DragPerform)
                {
                    if (type == EventType.DragExited)
                    {
                        if (GameObjectInspector.dragObject)
                        {
                            UnityEngine.Object.DestroyImmediate(GameObjectInspector.dragObject, false);
                            HandleUtility.ignoreRaySnapObjects = null;
                            GameObjectInspector.dragObject     = null;
                            current.Use();
                        }
                    }
                }
                else
                {
                    string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, GameObjectInspector.dragObject.name);
                    GameObjectInspector.dragObject.hideFlags = HideFlags.None;
                    Undo.RegisterCreatedObjectUndo(GameObjectInspector.dragObject, "Place " + GameObjectInspector.dragObject.name);
                    EditorUtility.SetDirty(GameObjectInspector.dragObject);
                    DragAndDrop.AcceptDrag();
                    Selection.activeObject             = GameObjectInspector.dragObject;
                    HandleUtility.ignoreRaySnapObjects = null;
                    EditorWindow.mouseOverWindow.Focus();
                    GameObjectInspector.dragObject.name = uniqueNameForSibling;
                    GameObjectInspector.dragObject      = null;
                    current.Use();
                }
            }
            else
            {
                if (GameObjectInspector.dragObject == null)
                {
                    GameObjectInspector.dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(gameObject));
                    HandleUtility.ignoreRaySnapObjects       = GameObjectInspector.dragObject.GetComponentsInChildren <Transform>();
                    GameObjectInspector.dragObject.hideFlags = HideFlags.HideInHierarchy;
                    GameObjectInspector.dragObject.name      = gameObject.name;
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                if (obj != null)
                {
                    RaycastHit raycastHit = (RaycastHit)obj;
                    float      d          = 0f;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float num = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, raycastHit.normal);
                        if (num != float.PositiveInfinity)
                        {
                            d = Vector3.Dot(GameObjectInspector.dragObject.transform.position, raycastHit.normal) - num;
                        }
                    }
                    GameObjectInspector.dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(raycastHit.point + raycastHit.normal * d);
                }
                else
                {
                    GameObjectInspector.dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                }
                if (sceneView.in2DMode)
                {
                    Vector3 position = GameObjectInspector.dragObject.transform.position;
                    position.z = PrefabUtility.FindPrefabRoot(gameObject).transform.position.z;
                    GameObjectInspector.dragObject.transform.position = position;
                }
                current.Use();
            }
        }
Пример #3
0
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject target = this.target as GameObject;

            switch (PrefabUtility.GetPrefabType(target))
            {
            case PrefabType.Prefab:
            case PrefabType.ModelPrefab:
            {
                Event     current = Event.current;
                EventType type    = current.type;
                if (type != EventType.DragUpdated)
                {
                    if (type == EventType.DragPerform)
                    {
                        string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, dragObject.name);
                        dragObject.hideFlags = HideFlags.None;
                        Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                        EditorUtility.SetDirty(dragObject);
                        DragAndDrop.AcceptDrag();
                        Selection.activeObject             = dragObject;
                        HandleUtility.ignoreRaySnapObjects = null;
                        EditorWindow.mouseOverWindow.Focus();
                        dragObject.name = uniqueNameForSibling;
                        dragObject      = null;
                        current.Use();
                        return;
                    }
                    if ((type == EventType.DragExited) && (dragObject != null))
                    {
                        Object.DestroyImmediate(dragObject, false);
                        HandleUtility.ignoreRaySnapObjects = null;
                        dragObject = null;
                        current.Use();
                    }
                }
                else
                {
                    if (dragObject == null)
                    {
                        dragObject = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(target));
                        HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                        dragObject.hideFlags = HideFlags.HideInHierarchy;
                        dragObject.name      = target.name;
                    }
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj3 = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj3 != null)
                    {
                        RaycastHit hit = (RaycastHit)obj3;
                        float      num = 0f;
                        if (Tools.pivotMode == PivotMode.Center)
                        {
                            float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, hit.normal);
                            if (num2 != float.PositiveInfinity)
                            {
                                num = Vector3.Dot(dragObject.transform.position, hit.normal) - num2;
                            }
                        }
                        dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(hit.point + ((Vector3)(hit.normal * num)));
                    }
                    else
                    {
                        dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                    }
                    if (sceneView.in2DMode)
                    {
                        Vector3 position = dragObject.transform.position;
                        position.z = PrefabUtility.FindPrefabRoot(target).transform.position.z;
                        dragObject.transform.position = position;
                    }
                    current.Use();
                }
                break;
            }
            }
        }