Exemplo n.º 1
0
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject gameObject = base.target as GameObject;
            PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);

            if (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab)
            {
                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));
                        GameObjectInspector.dragObject.hideFlags = HideFlags.HideInHierarchy;
                        GameObjectInspector.dragObject.name      = gameObject.name;
                    }
                    if (HandleUtility.ignoreRaySnapObjects == null)
                    {
                        HandleUtility.ignoreRaySnapObjects = GameObjectInspector.dragObject.GetComponentsInChildren <Transform>();
                    }
                    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();
                }
            }
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject go = target as GameObject;

            if (!PrefabUtility.IsPartOfPrefabAsset(go))
            {
                return;
            }

            var prefabAssetRoot = go.transform.root.gameObject;

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.DragUpdated:

                Scene destinationScene = sceneView.customScene.IsValid() ? sceneView.customScene : SceneManager.GetActiveScene();
                if (dragObject == null)
                {
                    dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                    dragObject.name      = go.name;
                }

                if (HandleUtility.ignoreRaySnapObjects == null)
                {
                    HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object hit = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(evt.mousePosition));

                if (hit != null)
                {
                    RaycastHit rh     = (RaycastHit)hit;
                    float      offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, rh.normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, rh.normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(rh.point + (rh.normal * offset));
                }
                else
                {
                    dragObject.transform.position = HandleUtility.GUIPointToWorldRay(evt.mousePosition).GetPoint(10);
                }

                // Use prefabs original z position when in 2D mode
                if (sceneView.in2DMode)
                {
                    Vector3 dragPosition = dragObject.transform.position;
                    dragPosition.z = prefabAssetRoot.transform.position.z;
                    dragObject.transform.position = dragPosition;
                }

                evt.Use();
                break;

            case EventType.DragPerform:

                var stage = StageNavigationManager.instance.currentItem;
                if (stage.isPrefabStage)
                {
                    var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.prefabAssetPath);
                    if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefabAssetThatIsAddedTo, go))
                    {
                        PrefabUtility.ShowCyclicNestingWarningDialog();
                        return;
                    }
                }

                Transform parent = sceneView.customParentForDraggedObjects;

                string uniqueName = GameObjectUtility.GetUniqueNameForSibling(parent, dragObject.name);
                if (parent != null)
                {
                    dragObject.transform.parent = parent;
                }
                dragObject.hideFlags = 0;
                Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                EditorUtility.SetDirty(dragObject);
                DragAndDrop.AcceptDrag();
                Selection.activeObject             = dragObject;
                HandleUtility.ignoreRaySnapObjects = null;
                if (SceneView.mouseOverWindow != null)
                {
                    SceneView.mouseOverWindow.Focus();
                }
                dragObject.name = uniqueName;
                dragObject      = null;
                evt.Use();
                break;

            case EventType.DragExited:
                if (dragObject)
                {
                    UnityObject.DestroyImmediate(dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    dragObject = null;
                    evt.Use();
                }
                break;
            }
        }
Exemplo n.º 3
0
 private void DoPrefabButtons(PrefabType prefabType, GameObject go)
 {
     if (this.m_HasInstance)
     {
         using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode))
         {
             EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
             GUIContent gUIContent = (base.targets.Length <= 1) ? GameObjectInspector.s_Styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_Styles.goTypeLabelMultiple;
             if (gUIContent != null)
             {
                 EditorGUILayout.BeginHorizontal(new GUILayoutOption[]
                 {
                     GUILayout.Width(24f + GameObjectInspector.s_Styles.tagFieldWidth)
                 });
                 GUILayout.FlexibleSpace();
                 if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                 {
                     GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                     GUILayout.Label(gUIContent, EditorStyles.whiteLabel, new GUILayoutOption[]
                     {
                         GUILayout.ExpandWidth(false)
                     });
                     GUI.contentColor = Color.white;
                 }
                 else
                 {
                     GUILayout.Label(gUIContent, new GUILayoutOption[]
                     {
                         GUILayout.ExpandWidth(false)
                     });
                 }
                 EditorGUILayout.EndHorizontal();
             }
             if (base.targets.Length > 1)
             {
                 GUILayout.Label("Instance Management Disabled", GameObjectInspector.s_Styles.instanceManagementInfo, new GUILayoutOption[0]);
             }
             else
             {
                 if (prefabType != PrefabType.MissingPrefabInstance)
                 {
                     if (GUILayout.Button("Select", "MiniButtonLeft", new GUILayoutOption[0]))
                     {
                         Selection.activeObject = PrefabUtility.GetPrefabParent(base.target);
                         EditorGUIUtility.PingObject(Selection.activeObject);
                     }
                 }
                 if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                 {
                     if (GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0]))
                     {
                         List <UnityEngine.Object> hierarchy = new List <UnityEngine.Object>();
                         this.GetObjectListFromHierarchy(hierarchy, go);
                         Undo.RegisterFullObjectHierarchyUndo(go, "Revert to prefab");
                         PrefabUtility.ReconnectToLastPrefab(go);
                         Undo.RegisterCreatedObjectUndo(PrefabUtility.GetPrefabObject(go), "Revert to prefab");
                         PrefabUtility.RevertPrefabInstance(go);
                         this.CalculatePrefabStatus();
                         List <UnityEngine.Object> list = new List <UnityEngine.Object>();
                         this.GetObjectListFromHierarchy(list, go);
                         this.RegisterNewComponents(list, hierarchy);
                     }
                 }
                 using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode()))
                 {
                     if (prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance)
                     {
                         if (GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0]))
                         {
                             this.RevertAndCheckForNewComponents(go);
                         }
                     }
                     if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                     {
                         GameObject gameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go);
                         GUI.enabled = (gameObject != null && !AnimationMode.InAnimationMode());
                         if (GUILayout.Button("Apply", "MiniButtonRight", new GUILayoutOption[0]))
                         {
                             UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(gameObject);
                             string             assetPath    = AssetDatabase.GetAssetPath(prefabParent);
                             bool flag = Provider.PromptAndCheckoutIfNeeded(new string[]
                             {
                                 assetPath
                             }, "The version control requires you to check out the prefab before applying changes.");
                             if (flag)
                             {
                                 PrefabUtility.ReplacePrefab(gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                                 this.CalculatePrefabStatus();
                                 EditorSceneManager.MarkSceneDirty(gameObject.scene);
                                 GUIUtility.ExitGUI();
                             }
                         }
                     }
                 }
                 if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance)
                 {
                     if (GUILayout.Button("Open", "MiniButtonRight", new GUILayoutOption[0]))
                     {
                         AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(base.target));
                         GUIUtility.ExitGUI();
                     }
                 }
             }
             EditorGUILayout.EndHorizontal();
         }
     }
 }
Exemplo n.º 4
0
 public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, UnityEngine.Object[] objectReferences, string[] paths, SpriteUtility.ShowFileDialogDelegate saveFileDialog)
 {
     if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform || evt.type == EventType.DragExited)
     {
         if (objectReferences.Length == 1 && objectReferences[0] as UnityEngine.Texture2D != null)
         {
             GameObject gameObject = HandleUtility.PickGameObject(evt.mousePosition, true);
             if (gameObject != null)
             {
                 Renderer component = gameObject.GetComponent <Renderer>();
                 if (component != null && !(component is SpriteRenderer))
                 {
                     SpriteUtility.CleanUp(true);
                     return;
                 }
             }
         }
         EventType type = evt.type;
         if (type != EventType.DragUpdated)
         {
             if (type != EventType.DragPerform)
             {
                 if (type == EventType.DragExited)
                 {
                     if (SpriteUtility.s_SceneDragObjects != null)
                     {
                         SpriteUtility.CleanUp(true);
                         evt.Use();
                     }
                 }
             }
             else
             {
                 List <Sprite> spriteFromPathsOrObjects = SpriteUtility.GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);
                 if (spriteFromPathsOrObjects.Count > 0 && SpriteUtility.s_SceneDragObjects != null)
                 {
                     if (SpriteUtility.s_SceneDragObjects.Count == 0)
                     {
                         SpriteUtility.CreateSceneDragObjects(spriteFromPathsOrObjects);
                         SpriteUtility.PositionSceneDragObjects(SpriteUtility.s_SceneDragObjects, sceneView, evt.mousePosition);
                     }
                     bool flag = true;
                     if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation && spriteFromPathsOrObjects.Count > 1)
                     {
                         UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
                         flag = SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], spriteFromPathsOrObjects.ToArray(), saveFileDialog);
                     }
                     else
                     {
                         UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
                     }
                     if (flag)
                     {
                         using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                         {
                             while (enumerator.MoveNext())
                             {
                                 GameObject gameObject2 = (GameObject)enumerator.Current;
                                 Undo.RegisterCreatedObjectUndo(gameObject2, "Create Sprite");
                                 gameObject2.hideFlags = HideFlags.None;
                             }
                         }
                         Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                     }
                     SpriteUtility.CleanUp(!flag);
                     evt.Use();
                 }
             }
         }
         else
         {
             SpriteUtility.DragType dragType = (!evt.alt) ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
             if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
             {
                 if (!SpriteUtility.ExistingAssets(objectReferences) && SpriteUtility.PathsAreValidTextures(paths))
                 {
                     DragAndDrop.visualMode           = DragAndDropVisualMode.Copy;
                     SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                     SpriteUtility.s_DragType         = dragType;
                 }
                 else
                 {
                     List <Sprite> spriteFromPathsOrObjects2 = SpriteUtility.GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);
                     if (spriteFromPathsOrObjects2.Count == 0)
                     {
                         return;
                     }
                     if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                     {
                         SpriteUtility.CleanUp(true);
                     }
                     SpriteUtility.s_DragType = dragType;
                     SpriteUtility.CreateSceneDragObjects(spriteFromPathsOrObjects2);
                     SpriteUtility.IgnoreForRaycasts(SpriteUtility.s_SceneDragObjects);
                 }
             }
             SpriteUtility.PositionSceneDragObjects(SpriteUtility.s_SceneDragObjects, sceneView, evt.mousePosition);
             DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
             evt.Use();
         }
     }
 }
Exemplo n.º 5
0
        public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, Object[] objectReferences, string[] paths, ShowFileDialogDelegate saveFileDialog)
        {
            if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited)
            {
                return;
            }

            // Return if any of the dragged objects are null, e.g. a MonoBehaviour without a managed instance
            if (objectReferences.Any(obj => obj == null))
            {
                return;
            }

            // Regardless of EditorBehaviorMode or SceneView mode we don't handle if texture is dragged over a GO with renderer
            if (objectReferences.Length == 1 && objectReferences[0] as UnityTexture2D != null)
            {
                GameObject go = HandleUtility.PickGameObject(evt.mousePosition, true);
                if (go != null)
                {
                    var renderer = go.GetComponent <Renderer>();
                    if (renderer != null && !(renderer is SpriteRenderer))
                    {
                        // There is an object where the cursor is
                        // and we are dragging a texture. Most likely user wants to
                        // assign texture to the GO
                        // Case 730444: Proceed only if the go has a renderer
                        CleanUp(true);
                        return;
                    }
                }
            }

            switch (evt.type)
            {
            case (EventType.DragUpdated):
                DragType newDragType = evt.alt ? DragType.CreateMultiple : DragType.SpriteAnimation;

                if (s_DragType != newDragType || s_SceneDragObjects == null)               // Either this is first time we are here OR evt.alt changed during drag
                {
                    if (!ExistingAssets(objectReferences) && PathsAreValidTextures(paths)) // External drag with images that are not in the project
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        s_SceneDragObjects     = new List <Object>();
                        s_DragType             = newDragType;
                    }
                    else     // Internal drag with assets from project
                    {
                        List <Sprite> assets = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);

                        if (assets.Count == 0)
                        {
                            return;
                        }

                        if (s_DragType != DragType.NotInitialized)     // evt.alt changed during drag, so we need to cleanup and start over
                        {
                            CleanUp(true);
                        }

                        s_DragType = newDragType;
                        CreateSceneDragObjects(assets, sceneView);
                        IgnoreForRaycasts(s_SceneDragObjects);
                    }
                }

                PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                evt.Use();
                break;

            case (EventType.DragPerform):
                List <Sprite> sprites = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);

                if (sprites.Count > 0 && s_SceneDragObjects != null)
                {
                    // Store current undoIndex to undo all operations done if any part of sprite creation fails
                    int undoIndex = Undo.GetCurrentGroup();

                    // For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets
                    if (s_SceneDragObjects.Count == 0)
                    {
                        CreateSceneDragObjects(sprites, sceneView);
                        PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);
                    }

                    foreach (GameObject dragGO in s_SceneDragObjects)
                    {
                        dragGO.hideFlags = HideFlags.None;

                        // When in e.g Prefab Mode ensure to reparent dragged objects under the prefab root
                        if (sceneView.customParentForDraggedObjects != null)
                        {
                            dragGO.transform.SetParent(sceneView.customParentForDraggedObjects, true);
                        }

                        Undo.RegisterCreatedObjectUndo(dragGO, "Create Sprite");
                        EditorUtility.SetDirty(dragGO);
                    }

                    bool createGameObject = true;
                    if (s_DragType == DragType.SpriteAnimation && sprites.Count > 1)
                    {
                        createGameObject = AddAnimationToGO((GameObject)s_SceneDragObjects[0], sprites.ToArray(), saveFileDialog);
                    }

                    if (createGameObject)
                    {
                        Selection.objects = s_SceneDragObjects.ToArray();
                    }
                    else
                    {
                        // Revert all Create Sprite actions if animation failed to be created or was cancelled
                        Undo.RevertAllDownToGroup(undoIndex);
                    }
                    CleanUp(!createGameObject);
                    evt.Use();
                }
                break;

            case EventType.DragExited:
                if (s_SceneDragObjects != null)
                {
                    CleanUp(true);
                    evt.Use();
                }
                break;
            }
        }
Exemplo n.º 6
0
        internal bool DrawInspector(Rect contentRect)
        {
            int  num6;
            bool flag4;

            if (s_styles == null)
            {
                s_styles = new Styles();
            }
            base.serializedObject.Update();
            GameObject target = this.target as GameObject;

            EditorGUIUtility.labelWidth = 52f;
            bool enabled = GUI.enabled;

            GUI.enabled = true;
            GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig);
            GUI.enabled = enabled;
            float      width  = contentRect.width;
            float      y      = contentRect.y;
            GUIContent goIcon = null;
            PrefabType none   = PrefabType.None;

            if (this.m_AllOfSamePrefabType)
            {
                none = PrefabUtility.GetPrefabType(target);
                switch (none)
                {
                case PrefabType.None:
                    goIcon = s_styles.goIcon;
                    break;

                case PrefabType.Prefab:
                case PrefabType.PrefabInstance:
                case PrefabType.DisconnectedPrefabInstance:
                    goIcon = s_styles.prefabIcon;
                    break;

                case PrefabType.ModelPrefab:
                case PrefabType.ModelPrefabInstance:
                case PrefabType.DisconnectedModelPrefabInstance:
                    goIcon = s_styles.modelIcon;
                    break;

                case PrefabType.MissingPrefabInstance:
                    goIcon = s_styles.prefabIcon;
                    break;
                }
            }
            else
            {
                goIcon = s_styles.typelessIcon;
            }
            EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, goIcon.image as Texture2D, this.m_Icon);
            EditorGUI.BeginDisabledGroup(none == PrefabType.ModelPrefab);
            EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none);
            float num3 = s_styles.staticFieldToggleWidth + 15f;
            float num4 = ((width - 52f) - num3) - 5f;

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_Name.hasMultipleDifferentValues;
            string name = EditorGUI.DelayedTextField(new Rect(52f, (4f + y) + 1f, num4, 16f), target.name, null, EditorStyles.textField);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                foreach (UnityEngine.Object obj3 in base.targets)
                {
                    ObjectNames.SetNameSmart(obj3 as GameObject, name);
                }
            }
            Rect totalPosition = new Rect(width - num3, 4f + y, s_styles.staticFieldToggleWidth, 16f);

            EditorGUI.BeginProperty(totalPosition, GUIContent.none, this.m_StaticEditorFlags);
            EditorGUI.BeginChangeCheck();
            Rect position = totalPosition;

            EditorGUI.showMixedValue |= ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue);
            Event     current = Event.current;
            EventType type    = current.type;
            bool      flag2   = (current.type == EventType.MouseDown) && (current.button != 0);

            if (flag2)
            {
                current.type = EventType.Ignore;
            }
            bool flagValue = EditorGUI.ToggleLeft(position, "Static", target.isStatic);

            if (flag2)
            {
                current.type = type;
            }
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(base.targets, -1, flagValue);
                base.serializedObject.SetIsDifferentCacheDirty();
            }
            EditorGUI.EndProperty();
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues;
            EditorGUI.EnumMaskField(new Rect(totalPosition.x + s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(target), s_styles.staticDropdown, out num6, out flag4);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(base.targets, num6, flag4);
                base.serializedObject.SetIsDifferentCacheDirty();
            }
            float num7 = 4f;
            float num8 = 4f;

            EditorGUIUtility.fieldWidth = ((((width - num7) - 52f) - s_styles.layerFieldWidth) - num8) / 2f;
            string tag = null;

            try
            {
                tag = target.tag;
            }
            catch (Exception)
            {
                tag = "Undefined";
            }
            EditorGUIUtility.labelWidth = s_styles.tagFieldWidth;
            Rect rect3 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);

            EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Tag);
            EditorGUI.BeginChangeCheck();
            string str3 = EditorGUI.TagField(rect3, EditorGUIUtility.TempContent("Tag"), tag);

            if (EditorGUI.EndChangeCheck())
            {
                this.m_Tag.stringValue = str3;
                Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle);
                foreach (UnityEngine.Object obj4 in base.targets)
                {
                    (obj4 as GameObject).tag = str3;
                }
            }
            EditorGUI.EndProperty();
            EditorGUIUtility.labelWidth = s_styles.layerFieldWidth;
            rect3 = new Rect((52f + EditorGUIUtility.fieldWidth) + num7, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);
            EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Layer);
            EditorGUI.BeginChangeCheck();
            int layer = EditorGUI.LayerField(rect3, EditorGUIUtility.TempContent("Layer"), target.layer);

            if (EditorGUI.EndChangeCheck())
            {
                GameObjectUtility.ShouldIncludeChildren children = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?");
                if (children != GameObjectUtility.ShouldIncludeChildren.Cancel)
                {
                    this.m_Layer.intValue = layer;
                    this.SetLayer(layer, children == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
                }
            }
            EditorGUI.EndProperty();
            if (!this.m_HasInstance || EditorApplication.isPlayingOrWillChangePlaymode)
            {
                goto Label_0992;
            }
            float      num11    = ((width - 52f) - 5f) / 3f;
            Rect       rect4    = new Rect(52f + (num11 * 0f), 44f + y, num11, 15f);
            Rect       rect5    = new Rect(52f + (num11 * 1f), 44f + y, num11, 15f);
            Rect       rect6    = new Rect(52f + (num11 * 2f), 44f + y, num11, 15f);
            Rect       rect7    = new Rect(52f, 44f + y, num11 * 3f, 15f);
            GUIContent content2 = (base.targets.Length <= 1) ? s_styles.goTypeLabel[(int)none] : s_styles.goTypeLabelMultiple;

            if (content2 != null)
            {
                float x = GUI.skin.label.CalcSize(content2).x;
                switch (none)
                {
                case PrefabType.DisconnectedModelPrefabInstance:
                case PrefabType.MissingPrefabInstance:
                case PrefabType.DisconnectedPrefabInstance:
                    GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                    if (none == PrefabType.MissingPrefabInstance)
                    {
                        GUI.Label(new Rect(52f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel);
                    }
                    else
                    {
                        GUI.Label(new Rect((52f - x) - 5f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel);
                    }
                    GUI.contentColor = Color.white;
                    goto Label_078B;
                }
                Rect rect8 = new Rect((52f - x) - 5f, 44f + y, x, 18f);
                GUI.Label(rect8, content2);
            }
Label_078B:
            if (base.targets.Length > 1)
            {
                GUI.Label(rect7, "Instance Management Disabled", s_styles.instanceManagementInfo);
            }
            else
            {
                if ((none != PrefabType.MissingPrefabInstance) && GUI.Button(rect4, "Select", "MiniButtonLeft"))
                {
                    Selection.activeObject = PrefabUtility.GetPrefabParent(this.target);
                    EditorGUIUtility.PingObject(Selection.activeObject);
                }
                if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid"))
                {
                    Undo.RegisterFullObjectHierarchyUndo(target, "Revert to prefab");
                    PrefabUtility.ReconnectToLastPrefab(target);
                    PrefabUtility.RevertPrefabInstance(target);
                    this.CalculatePrefabStatus();
                    Undo.RegisterCreatedObjectUndo(target, "Reconnect prefab");
                    GUIUtility.ExitGUI();
                }
                bool flag5 = GUI.enabled;
                GUI.enabled = GUI.enabled && !AnimationMode.InAnimationMode();
                if (((none == PrefabType.ModelPrefabInstance) || (none == PrefabType.PrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid"))
                {
                    Undo.RegisterFullObjectHierarchyUndo(target, "Revert Prefab Instance");
                    PrefabUtility.RevertPrefabInstance(target);
                    this.CalculatePrefabStatus();
                    GUIUtility.ExitGUI();
                }
                if ((none == PrefabType.PrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance))
                {
                    GameObject source = PrefabUtility.FindValidUploadPrefabInstanceRoot(target);
                    GUI.enabled = (source != null) && !AnimationMode.InAnimationMode();
                    if (GUI.Button(rect6, "Apply", "MiniButtonRight"))
                    {
                        UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(source);
                        string             assetPath    = AssetDatabase.GetAssetPath(prefabParent);
                        string[]           assets       = new string[] { assetPath };
                        if (Provider.PromptAndCheckoutIfNeeded(assets, "The version control requires you to check out the prefab before applying changes."))
                        {
                            PrefabUtility.ReplacePrefab(source, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                            this.CalculatePrefabStatus();
                            GUIUtility.ExitGUI();
                        }
                    }
                }
                GUI.enabled = flag5;
                if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.ModelPrefabInstance)) && GUI.Button(rect6, "Open", "MiniButtonRight"))
                {
                    AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target));
                    GUIUtility.ExitGUI();
                }
            }
Label_0992:
            EditorGUI.EndDisabledGroup();
            base.serializedObject.ApplyModifiedProperties();
            return(true);
        }
Exemplo n.º 7
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))
                    {
                        UnityEngine.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;
            }
            }
        }
Exemplo n.º 8
0
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current = Event.current;

            if (current.type != EventType.DragUpdated && current.type != EventType.DragPerform && current.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if (gameObject != null && DragAndDrop.objectReferences.Length == 1 && DragAndDrop.objectReferences[0] as Texture != null && gameObject.GetComponent <Renderer>() != null)
                {
                    SpriteUtility.CleanUp(true);
                    return;
                }
            }
            EventType type = current.type;

            if (type != EventType.DragUpdated)
            {
                if (type != EventType.DragPerform)
                {
                    if (type == EventType.DragExited)
                    {
                        if (SpriteUtility.s_SceneDragObjects != null && SpriteUtility.s_SceneDragObjects != null)
                        {
                            SpriteUtility.CleanUp(true);
                            current.Use();
                        }
                    }
                }
                else
                {
                    Sprite[] spriteFromDraggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (spriteFromDraggedPathsOrObjects != null && SpriteUtility.s_SceneDragObjects != null)
                    {
                        if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                        {
                            SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], spriteFromDraggedPathsOrObjects);
                        }
                        using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                GameObject gameObject2 = (GameObject)enumerator.Current;
                                Undo.RegisterCreatedObjectUndo(gameObject2, "Create Sprite");
                                gameObject2.hideFlags = HideFlags.None;
                            }
                        }
                        Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                        SpriteUtility.CleanUp(false);
                        current.Use();
                    }
                }
            }
            else
            {
                SpriteUtility.DragType dragType = (!current.alt) ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] spriteFromDraggedPathsOrObjects2 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (spriteFromDraggedPathsOrObjects2 == null || spriteFromDraggedPathsOrObjects2.Length == 0)
                    {
                        return;
                    }
                    Sprite x = spriteFromDraggedPathsOrObjects2[0];
                    if (x == null)
                    {
                        return;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp(true);
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        Sprite[] array = spriteFromDraggedPathsOrObjects2;
                        for (int i = 0; i < array.Length; i++)
                        {
                            Sprite frame = array[i];
                            SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(spriteFromDraggedPathsOrObjects2[0], Vector3.zero));
                    }
                    List <Transform> list = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator2 = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            GameObject gameObject3 = (GameObject)enumerator2.Current;
                            list.AddRange(gameObject3.GetComponentsInChildren <Transform>());
                            gameObject3.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = list.ToArray();
                }
                Vector3 position = Vector3.zero;
                position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    position.z = 0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj != null)
                    {
                        position = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator3 = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        GameObject gameObject4 = (GameObject)enumerator3.Current;
                        gameObject4.transform.position = position;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current.Use();
            }
        }
Exemplo n.º 9
0
 public static void RegisterCreatedObjectUndo(UnityObject target, string name)
 {
     UnityUndo.RegisterCreatedObjectUndo(target, name);
 }
Exemplo n.º 10
0
        internal bool DrawInspector(Rect contentRect)
        {
            if (GameObjectInspector.s_styles == null)
            {
                GameObjectInspector.s_styles = new GameObjectInspector.Styles();
            }
            base.serializedObject.Update();
            GameObject gameObject = this.target as GameObject;

            EditorGUIUtility.labelWidth = 52f;
            bool enabled = GUI.enabled;

            GUI.enabled = true;
            GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig);
            GUI.enabled = enabled;
            float      width      = contentRect.width;
            float      y          = contentRect.y;
            GUIContent gUIContent = null;
            PrefabType prefabType = PrefabType.None;

            if (this.m_AllOfSamePrefabType)
            {
                prefabType = PrefabUtility.GetPrefabType(gameObject);
                switch (prefabType)
                {
                case PrefabType.None:
                    gUIContent = GameObjectInspector.s_styles.goIcon;
                    break;

                case PrefabType.Prefab:
                case PrefabType.PrefabInstance:
                case PrefabType.DisconnectedPrefabInstance:
                    gUIContent = GameObjectInspector.s_styles.prefabIcon;
                    break;

                case PrefabType.ModelPrefab:
                case PrefabType.ModelPrefabInstance:
                case PrefabType.DisconnectedModelPrefabInstance:
                    gUIContent = GameObjectInspector.s_styles.modelIcon;
                    break;

                case PrefabType.MissingPrefabInstance:
                    gUIContent = GameObjectInspector.s_styles.prefabIcon;
                    break;
                }
            }
            else
            {
                gUIContent = GameObjectInspector.s_styles.typelessIcon;
            }
            EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, gUIContent.image as Texture2D, this.m_Icon);
            EditorGUI.BeginDisabledGroup(prefabType == PrefabType.ModelPrefab);
            EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none);
            float num    = GameObjectInspector.s_styles.staticFieldToggleWidth + 15f;
            float width2 = width - 52f - num - 5f;

            EditorGUI.DelayedTextField(new Rect(52f, 4f + y + 1f, width2, 16f), this.m_Name, GUIContent.none);
            Rect rect = new Rect(width - num, 4f + y, GameObjectInspector.s_styles.staticFieldToggleWidth, 16f);

            EditorGUI.BeginProperty(rect, GUIContent.none, this.m_StaticEditorFlags);
            EditorGUI.BeginChangeCheck();
            Rect position = rect;

            EditorGUI.showMixedValue |= GameObjectInspector.ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue);
            Event     current = Event.current;
            EventType type    = current.type;
            bool      flag    = current.type == EventType.MouseDown && current.button != 0;

            if (flag)
            {
                current.type = EventType.Ignore;
            }
            bool flagValue = EditorGUI.ToggleLeft(position, "Static", gameObject.isStatic);

            if (flag)
            {
                current.type = type;
            }
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(base.targets, -1, flagValue);
                base.serializedObject.SetIsDifferentCacheDirty();
            }
            EditorGUI.EndProperty();
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues;
            int  changedFlags;
            bool flagValue2;

            EditorGUI.EnumMaskField(new Rect(rect.x + GameObjectInspector.s_styles.staticFieldToggleWidth, rect.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(gameObject), GameObjectInspector.s_styles.staticDropdown, out changedFlags, out flagValue2);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(base.targets, changedFlags, flagValue2);
                base.serializedObject.SetIsDifferentCacheDirty();
            }
            float num2 = 4f;
            float num3 = 4f;

            EditorGUIUtility.fieldWidth = (width - num2 - 52f - GameObjectInspector.s_styles.layerFieldWidth - num3) / 2f;
            string tag = null;

            try
            {
                tag = gameObject.tag;
            }
            catch (Exception)
            {
                tag = "Undefined";
            }
            EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.tagFieldWidth;
            Rect rect2 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);

            EditorGUI.BeginProperty(rect2, GUIContent.none, this.m_Tag);
            EditorGUI.BeginChangeCheck();
            string text = EditorGUI.TagField(rect2, EditorGUIUtility.TempContent("Tag"), tag);

            if (EditorGUI.EndChangeCheck())
            {
                this.m_Tag.stringValue = text;
                Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle);
                UnityEngine.Object[] targets = base.targets;
                for (int i = 0; i < targets.Length; i++)
                {
                    UnityEngine.Object @object = targets[i];
                    (@object as GameObject).tag = text;
                }
            }
            EditorGUI.EndProperty();
            EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.layerFieldWidth;
            rect2 = new Rect(52f + EditorGUIUtility.fieldWidth + num2, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);
            EditorGUI.BeginProperty(rect2, GUIContent.none, this.m_Layer);
            EditorGUI.BeginChangeCheck();
            int num4 = EditorGUI.LayerField(rect2, EditorGUIUtility.TempContent("Layer"), gameObject.layer);

            if (EditorGUI.EndChangeCheck())
            {
                GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(num4) + " for all child objects as well?");
                if (shouldIncludeChildren != GameObjectUtility.ShouldIncludeChildren.Cancel)
                {
                    this.m_Layer.intValue = num4;
                    this.SetLayer(num4, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
                }
            }
            EditorGUI.EndProperty();
            if (this.m_HasInstance && !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                float      num5        = (width - 52f - 5f) / 3f;
                Rect       position2   = new Rect(52f + num5 * 0f, 44f + y, num5, 15f);
                Rect       position3   = new Rect(52f + num5 * 1f, 44f + y, num5, 15f);
                Rect       position4   = new Rect(52f + num5 * 2f, 44f + y, num5, 15f);
                Rect       position5   = new Rect(52f, 44f + y, num5 * 3f, 15f);
                GUIContent gUIContent2 = (base.targets.Length <= 1) ? GameObjectInspector.s_styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_styles.goTypeLabelMultiple;
                if (gUIContent2 != null)
                {
                    float x = GUI.skin.label.CalcSize(gUIContent2).x;
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                        if (prefabType == PrefabType.MissingPrefabInstance)
                        {
                            GUI.Label(new Rect(52f, 44f + y, width - 52f - 5f, 18f), gUIContent2, EditorStyles.whiteLabel);
                        }
                        else
                        {
                            GUI.Label(new Rect(52f - x - 5f, 44f + y, width - 52f - 5f, 18f), gUIContent2, EditorStyles.whiteLabel);
                        }
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        Rect position6 = new Rect(52f - x - 5f, 44f + y, x, 18f);
                        GUI.Label(position6, gUIContent2);
                    }
                }
                if (base.targets.Length > 1)
                {
                    GUI.Label(position5, "Instance Management Disabled", GameObjectInspector.s_styles.instanceManagementInfo);
                }
                else
                {
                    if (prefabType != PrefabType.MissingPrefabInstance && GUI.Button(position2, "Select", "MiniButtonLeft"))
                    {
                        Selection.activeObject = PrefabUtility.GetPrefabParent(this.target);
                        EditorGUIUtility.PingObject(Selection.activeObject);
                    }
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert to prefab");
                        PrefabUtility.ReconnectToLastPrefab(gameObject);
                        PrefabUtility.RevertPrefabInstance(gameObject);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo(gameObject, "Reconnect prefab");
                        GUIUtility.ExitGUI();
                    }
                    bool enabled2 = GUI.enabled;
                    GUI.enabled = (GUI.enabled && !AnimationMode.InAnimationMode());
                    if ((prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) && GUI.Button(position3, "Revert", "MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo(gameObject, "Revert Prefab Instance");
                        PrefabUtility.RevertPrefabInstance(gameObject);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo(gameObject, "Revert prefab");
                        GUIUtility.ExitGUI();
                    }
                    if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GameObject gameObject2 = PrefabUtility.FindValidUploadPrefabInstanceRoot(gameObject);
                        GUI.enabled = (gameObject2 != null && !AnimationMode.InAnimationMode());
                        if (GUI.Button(position4, "Apply", "MiniButtonRight"))
                        {
                            UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(gameObject2);
                            string             assetPath    = AssetDatabase.GetAssetPath(prefabParent);
                            bool flag2 = Provider.PromptAndCheckoutIfNeeded(new string[]
                            {
                                assetPath
                            }, "The version control requires you to check out the prefab before applying changes.");
                            if (flag2)
                            {
                                PrefabUtility.ReplacePrefab(gameObject2, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                                this.CalculatePrefabStatus();
                                GUIUtility.ExitGUI();
                            }
                        }
                    }
                    GUI.enabled = enabled2;
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", "MiniButtonRight"))
                    {
                        AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target));
                        GUIUtility.ExitGUI();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            base.serializedObject.ApplyModifiedProperties();
            return(true);
        }
Exemplo n.º 11
0
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject target = this.target as GameObject;

            switch (PrefabUtility.GetPrefabType((UnityEngine.Object)target))
            {
            case PrefabType.Prefab:
            case PrefabType.ModelPrefab:
                Event current = Event.current;
                switch (current.type)
                {
                case EventType.DragUpdated:
                    if ((UnityEngine.Object)GameObjectInspector.dragObject == (UnityEngine.Object)null)
                    {
                        GameObjectInspector.dragObject           = (GameObject)PrefabUtility.InstantiatePrefab((UnityEngine.Object)PrefabUtility.FindPrefabRoot(target));
                        HandleUtility.ignoreRaySnapObjects       = GameObjectInspector.dragObject.GetComponentsInChildren <Transform>();
                        GameObjectInspector.dragObject.hideFlags = HideFlags.HideInHierarchy;
                        GameObjectInspector.dragObject.name      = target.name;
                    }
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj != null)
                    {
                        RaycastHit raycastHit = (RaycastHit)obj;
                        float      num1       = 0.0f;
                        if (Tools.pivotMode == PivotMode.Center)
                        {
                            float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, raycastHit.normal);
                            if ((double)num2 != double.PositiveInfinity)
                            {
                                num1 = Vector3.Dot(GameObjectInspector.dragObject.transform.position, raycastHit.normal) - num2;
                            }
                        }
                        GameObjectInspector.dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(raycastHit.point + raycastHit.normal * num1);
                    }
                    else
                    {
                        GameObjectInspector.dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                    }
                    if (sceneView.in2DMode)
                    {
                        Vector3 position = GameObjectInspector.dragObject.transform.position;
                        position.z = PrefabUtility.FindPrefabRoot(target).transform.position.z;
                        GameObjectInspector.dragObject.transform.position = position;
                    }
                    current.Use();
                    return;

                case EventType.DragPerform:
                    string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling((Transform)null, GameObjectInspector.dragObject.name);
                    GameObjectInspector.dragObject.hideFlags = HideFlags.None;
                    Undo.RegisterCreatedObjectUndo((UnityEngine.Object)GameObjectInspector.dragObject, "Place " + GameObjectInspector.dragObject.name);
                    EditorUtility.SetDirty((UnityEngine.Object)GameObjectInspector.dragObject);
                    DragAndDrop.AcceptDrag();
                    Selection.activeObject             = (UnityEngine.Object)GameObjectInspector.dragObject;
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    EditorWindow.mouseOverWindow.Focus();
                    GameObjectInspector.dragObject.name = uniqueNameForSibling;
                    GameObjectInspector.dragObject      = (GameObject)null;
                    current.Use();
                    return;

                case EventType.DragExited:
                    if (!(bool)((UnityEngine.Object)GameObjectInspector.dragObject))
                    {
                        return;
                    }
                    UnityEngine.Object.DestroyImmediate((UnityEngine.Object)GameObjectInspector.dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    GameObjectInspector.dragObject     = (GameObject)null;
                    current.Use();
                    return;

                default:
                    return;
                }
            }
        }
Exemplo n.º 12
0
        internal bool DrawInspector(Rect contentRect)
        {
            if (GameObjectInspector.s_styles == null)
            {
                GameObjectInspector.s_styles = new GameObjectInspector.Styles();
            }
            this.serializedObject.Update();
            GameObject target1 = this.target as GameObject;

            EditorGUIUtility.labelWidth = 52f;
            bool enabled1 = GUI.enabled;

            GUI.enabled = true;
            GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig);
            GUI.enabled = enabled1;
            float      width1     = contentRect.width;
            float      y          = contentRect.y;
            GUIContent guiContent = (GUIContent)null;
            PrefabType prefabType = PrefabType.None;

            if (this.m_AllOfSamePrefabType)
            {
                prefabType = PrefabUtility.GetPrefabType((UnityEngine.Object)target1);
                switch (prefabType)
                {
                case PrefabType.None:
                    guiContent = GameObjectInspector.s_styles.goIcon;
                    break;

                case PrefabType.Prefab:
                case PrefabType.PrefabInstance:
                case PrefabType.DisconnectedPrefabInstance:
                    guiContent = GameObjectInspector.s_styles.prefabIcon;
                    break;

                case PrefabType.ModelPrefab:
                case PrefabType.ModelPrefabInstance:
                case PrefabType.DisconnectedModelPrefabInstance:
                    guiContent = GameObjectInspector.s_styles.modelIcon;
                    break;

                case PrefabType.MissingPrefabInstance:
                    guiContent = GameObjectInspector.s_styles.prefabIcon;
                    break;
                }
            }
            else
            {
                guiContent = GameObjectInspector.s_styles.typelessIcon;
            }
            EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), this.targets, true, guiContent.image as Texture2D, this.m_Icon);
            EditorGUI.BeginDisabledGroup(prefabType == PrefabType.ModelPrefab);
            EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none);
            float num1   = GameObjectInspector.s_styles.staticFieldToggleWidth + 15f;
            float width2 = (float)((double)width1 - 52.0 - (double)num1 - 5.0);

            EditorGUI.DelayedTextField(new Rect(52f, (float)(4.0 + (double)y + 1.0), width2, 16f), this.m_Name, GUIContent.none);
            Rect totalPosition = new Rect(width1 - num1, 4f + y, GameObjectInspector.s_styles.staticFieldToggleWidth, 16f);

            EditorGUI.BeginProperty(totalPosition, GUIContent.none, this.m_StaticEditorFlags);
            EditorGUI.BeginChangeCheck();
            Rect position1 = totalPosition;

            EditorGUI.showMixedValue |= GameObjectInspector.ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue);
            Event     current = Event.current;
            EventType type    = current.type;
            bool      flag    = current.type == EventType.MouseDown && current.button != 0;

            if (flag)
            {
                current.type = EventType.Ignore;
            }
            bool flagValue = EditorGUI.ToggleLeft(position1, "Static", target1.isStatic);

            if (flag)
            {
                current.type = type;
            }
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(this.targets, -1, flagValue);
                this.serializedObject.SetIsDifferentCacheDirty();
            }
            EditorGUI.EndProperty();
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues;
            int  changedFlags;
            bool changedToValue;

            EditorGUI.EnumMaskField(new Rect(totalPosition.x + GameObjectInspector.s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), (Enum)GameObjectUtility.GetStaticEditorFlags(target1), GameObjectInspector.s_styles.staticDropdown, out changedFlags, out changedToValue);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(this.targets, changedFlags, changedToValue);
                this.serializedObject.SetIsDifferentCacheDirty();
            }
            float num2 = 4f;
            float num3 = 4f;

            EditorGUIUtility.fieldWidth = (float)(((double)width1 - (double)num2 - 52.0 - (double)GameObjectInspector.s_styles.layerFieldWidth - (double)num3) / 2.0);
            string tag;

            try
            {
                tag = target1.tag;
            }
            catch (Exception ex)
            {
                tag = "Undefined";
            }
            EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.tagFieldWidth;
            Rect rect = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);

            EditorGUI.BeginProperty(rect, GUIContent.none, this.m_Tag);
            EditorGUI.BeginChangeCheck();
            string str = EditorGUI.TagField(rect, EditorGUIUtility.TempContent("Tag"), tag);

            if (EditorGUI.EndChangeCheck())
            {
                this.m_Tag.stringValue = str;
                Undo.RecordObjects(this.targets, "Change Tag of " + this.targetTitle);
                foreach (UnityEngine.Object target2 in this.targets)
                {
                    (target2 as GameObject).tag = str;
                }
            }
            EditorGUI.EndProperty();
            EditorGUIUtility.labelWidth = GameObjectInspector.s_styles.layerFieldWidth;
            rect = new Rect(52f + EditorGUIUtility.fieldWidth + num2, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f);
            EditorGUI.BeginProperty(rect, GUIContent.none, this.m_Layer);
            EditorGUI.BeginChangeCheck();
            int layer = EditorGUI.LayerField(rect, EditorGUIUtility.TempContent("Layer"), target1.layer);

            if (EditorGUI.EndChangeCheck())
            {
                GameObjectUtility.ShouldIncludeChildren shouldIncludeChildren = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(this.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?");
                if (shouldIncludeChildren != GameObjectUtility.ShouldIncludeChildren.Cancel)
                {
                    this.m_Layer.intValue = layer;
                    this.SetLayer(layer, shouldIncludeChildren == GameObjectUtility.ShouldIncludeChildren.IncludeChildren);
                }
            }
            EditorGUI.EndProperty();
            if (this.m_HasInstance && !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                float      width3    = (float)(((double)width1 - 52.0 - 5.0) / 3.0);
                Rect       position2 = new Rect((float)(52.0 + (double)width3 * 0.0), 44f + y, width3, 15f);
                Rect       position3 = new Rect((float)(52.0 + (double)width3 * 1.0), 44f + y, width3, 15f);
                Rect       position4 = new Rect((float)(52.0 + (double)width3 * 2.0), 44f + y, width3, 15f);
                Rect       position5 = new Rect(52f, 44f + y, width3 * 3f, 15f);
                GUIContent content   = this.targets.Length <= 1 ? GameObjectInspector.s_styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_styles.goTypeLabelMultiple;
                if (content != null)
                {
                    float x = GUI.skin.label.CalcSize(content).x;
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                        if (prefabType == PrefabType.MissingPrefabInstance)
                        {
                            GUI.Label(new Rect(52f, 44f + y, (float)((double)width1 - 52.0 - 5.0), 18f), content, EditorStyles.whiteLabel);
                        }
                        else
                        {
                            GUI.Label(new Rect((float)(52.0 - (double)x - 5.0), 44f + y, (float)((double)width1 - 52.0 - 5.0), 18f), content, EditorStyles.whiteLabel);
                        }
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUI.Label(new Rect((float)(52.0 - (double)x - 5.0), 44f + y, x, 18f), content);
                    }
                }
                if (this.targets.Length > 1)
                {
                    GUI.Label(position5, "Instance Management Disabled", GameObjectInspector.s_styles.instanceManagementInfo);
                }
                else
                {
                    if (prefabType != PrefabType.MissingPrefabInstance && GUI.Button(position2, "Select", (GUIStyle)"MiniButtonLeft"))
                    {
                        Selection.activeObject = PrefabUtility.GetPrefabParent(this.target);
                        EditorGUIUtility.PingObject(Selection.activeObject);
                    }
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) && GUI.Button(position3, "Revert", (GUIStyle)"MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo((UnityEngine.Object)target1, "Revert to prefab");
                        PrefabUtility.ReconnectToLastPrefab(target1);
                        PrefabUtility.RevertPrefabInstance(target1);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)target1, "Reconnect prefab");
                        GUIUtility.ExitGUI();
                    }
                    bool enabled2 = GUI.enabled;
                    GUI.enabled = GUI.enabled && !AnimationMode.InAnimationMode();
                    if ((prefabType == PrefabType.ModelPrefabInstance || prefabType == PrefabType.PrefabInstance) && GUI.Button(position3, "Revert", (GUIStyle)"MiniButtonMid"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo((UnityEngine.Object)target1, "Revert Prefab Instance");
                        PrefabUtility.RevertPrefabInstance(target1);
                        this.CalculatePrefabStatus();
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)target1, "Revert prefab");
                        GUIUtility.ExitGUI();
                    }
                    if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GameObject prefabInstanceRoot = PrefabUtility.FindValidUploadPrefabInstanceRoot(target1);
                        GUI.enabled = (UnityEngine.Object)prefabInstanceRoot != (UnityEngine.Object)null && !AnimationMode.InAnimationMode();
                        if (GUI.Button(position4, "Apply", (GUIStyle)"MiniButtonRight"))
                        {
                            UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent((UnityEngine.Object)prefabInstanceRoot);
                            if (Provider.PromptAndCheckoutIfNeeded(new string[1] {
                                AssetDatabase.GetAssetPath(prefabParent)
                            }, "The version control requires you to check out the prefab before applying changes."))
                            {
                                PrefabUtility.ReplacePrefab(prefabInstanceRoot, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
                                this.CalculatePrefabStatus();
                                EditorSceneManager.MarkSceneDirty(prefabInstanceRoot.scene);
                                GUIUtility.ExitGUI();
                            }
                        }
                    }
                    GUI.enabled = enabled2;
                    if ((prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) && GUI.Button(position4, "Open", (GUIStyle)"MiniButtonRight"))
                    {
                        AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target));
                        GUIUtility.ExitGUI();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            this.serializedObject.ApplyModifiedProperties();
            return(true);
        }
Exemplo n.º 13
0
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current1 = Event.current;

            if (current1.type != EventType.DragUpdated && current1.type != EventType.DragPerform && current1.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null && DragAndDrop.objectReferences.Length == 1 && ((UnityEngine.Object)(DragAndDrop.objectReferences[0] as Texture) != (UnityEngine.Object)null && (UnityEngine.Object)gameObject.GetComponent <Renderer>() != (UnityEngine.Object)null))
                {
                    return;
                }
            }
            switch (current1.type)
            {
            case EventType.DragUpdated:
                SpriteUtility.DragType dragType = !current1.alt ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] draggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (draggedPathsOrObjects == null || draggedPathsOrObjects.Length == 0 || (UnityEngine.Object)draggedPathsOrObjects[0] == (UnityEngine.Object)null)
                    {
                        break;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp();
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        foreach (Sprite frame in draggedPathsOrObjects)
                        {
                            SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(draggedPathsOrObjects[0], Vector3.zero));
                    }
                    List <Transform> transformList = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            GameObject current2 = (GameObject)enumerator.Current;
                            transformList.AddRange((IEnumerable <Transform>)current2.GetComponentsInChildren <Transform>());
                            current2.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = transformList.ToArray();
                }
                Vector3 zero  = Vector3.zero;
                Vector3 point = HandleUtility.GUIPointToWorldRay(current1.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    point.z = 0.0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current1.mousePosition));
                    if (obj != null)
                    {
                        point = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ((GameObject)enumerator.Current).transform.position = point;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current1.Use();
                break;

            case EventType.DragPerform:
                Sprite[] draggedPathsOrObjects1 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                if (draggedPathsOrObjects1 == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                {
                    SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], draggedPathsOrObjects1);
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GameObject current2 = (GameObject)enumerator.Current;
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)current2, "Create Sprite");
                        current2.hideFlags = HideFlags.None;
                    }
                }
                Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                SpriteUtility.CleanUp();
                current1.Use();
                break;

            case EventType.DragExited:
                if (SpriteUtility.s_SceneDragObjects == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        UnityEngine.Object.DestroyImmediate(enumerator.Current, false);
                    }
                }
                SpriteUtility.CleanUp();
                current1.Use();
                break;
            }
        }
Exemplo n.º 14
0
        private static void RegisterNewObjects(List <Object> newHierarchy, List <Object> hierarchy, string actionName)
        {
            var danglingObjects = new List <Object>();

            foreach (var i in newHierarchy)
            {
                var found = false;
                foreach (var j in hierarchy)
                {
                    if (j.GetInstanceID() == i.GetInstanceID())
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    danglingObjects.Add(i);
                }
            }

            // We need to ensure that dangling components are registered in an acceptable order regarding dependencies. For example, if we're adding RigidBody and ConfigurableJoint, the RigidBody will need to be added first (as the ConfigurableJoint depends upon it existing)
            var addedTypes = new HashSet <Type>()
            {
                typeof(Transform)
            };
            var emptyPass = false;

            while (danglingObjects.Count > 0 && !emptyPass)
            {
                emptyPass = true;
                for (var i = 0; i < danglingObjects.Count; i++)
                {
                    var danglingObject          = danglingObjects[i];
                    var reqs                    = danglingObject.GetType().GetCustomAttributes(typeof(RequireComponent), inherit: true);
                    var requiredComponentsExist = true;
                    foreach (RequireComponent req in reqs)
                    {
                        if ((req.m_Type0 != null && !addedTypes.Contains(req.m_Type0)) || (req.m_Type1 != null && !addedTypes.Contains(req.m_Type1)) || (req.m_Type2 != null && !addedTypes.Contains(req.m_Type2)))
                        {
                            requiredComponentsExist = false;
                            break;
                        }
                    }
                    if (requiredComponentsExist)
                    {
                        if (danglingObject is Transform)
                        {
                            danglingObject = ((Transform)danglingObject).gameObject;
                        }

                        Undo.RegisterCreatedObjectUndo(danglingObject, actionName);
                        addedTypes.Add(danglingObject.GetType());
                        danglingObjects.RemoveAt(i);
                        i--;
                        emptyPass = false;
                    }
                }
            }

            Debug.Assert(danglingObjects.Count == 0, "Dangling components have unfulfilled dependencies");
            foreach (var component in danglingObjects)
            {
                Undo.RegisterCreatedObjectUndo(component, actionName);
            }
        }