Ejemplo n.º 1
0
        /// <summary>
        /// Ends drawing a property tree, and handles management of undo, as well as marking scenes and drawn assets dirty.
        /// </summary>
        /// <param name="tree">The tree.</param>
        public static void EndDrawPropertyTree(PropertyTree tree)
        {
            try
            {
                tree.InvokeDelayedActions();

                var so = tree.GetUnitySerializedObjectNoUpdate();

                if (so != null)
                {
                    if (SerializedObject_nativeObjectPtrGetter != null)
                    {
                        IntPtr ptr = SerializedObject_nativeObjectPtrGetter(ref so);

                        if (ptr == IntPtr.Zero)
                        {
                            // SerializedObject has been disposed, likely due to a scene change invoked from GUI code.
                            // BAIL THE F**K OUT! :D Crashes will happen.
                            return;
                        }
                    }

                    if (tree.WillUndo)
                    {
                        so.ApplyModifiedProperties();
                    }
                    else
                    {
                        so.ApplyModifiedPropertiesWithoutUndo();
                    }
                }

                bool appliedOdinChanges = false;

                if (tree.ApplyChanges())
                {
                    appliedOdinChanges = true;
                    GUIHelper.RequestRepaint();
                }

                // This is very important, as applying changes may cause more actions to be delayed
                tree.InvokeDelayedActions();

                if (appliedOdinChanges)
                {
                    tree.InvokeOnValidate();

                    if (tree.PrefabModificationHandler.HasPrefabs)
                    {
                        var targets = tree.WeakTargets;

                        for (int i = 0; i < targets.Count; i++)
                        {
                            if (tree.PrefabModificationHandler.TargetPrefabs[i] == null)
                            {
                                continue;
                            }

                            var target = (UnityEngine.Object)targets[i];
                            PrefabUtility.RecordPrefabInstancePropertyModifications(target);
                        }
                    }
                }

                if (tree.WillUndo)
                {
                    Undo.FlushUndoRecordObjects();
                }

                drawnInspectorDepthCount--;

#if ODIN_LIMITED_VERSION
                if (drawnInspectorDepthCount == 0)
                {
                    float height = 17;
                    Rect  rect   = GUILayoutUtility.GetRect(20, height, GUILayoutOptions.ExpandWidth().Height(height));
                    rect.y += 2;

                    GUI.Label(rect, "Odin Inspector Non-Commercial Version", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                }
#endif

#if ODIN_TRIAL_VERSION
                if (drawnInspectorDepthCount == 0)
                {
                    float height = OdinTrialVersionInfo.IsExpired ? 22 : 17;
                    var   rect   = GUILayoutUtility.GetRect(16, height, GUILayoutOptions.ExpandWidth().Height(height));

                    var bgRect = rect;
                    bgRect.xMin -= 20;
                    bgRect.xMax += 20;
                    bgRect.y    += 2;
                    SirenixEditorGUI.DrawBorders(bgRect, 0, 0, 1, 0, SirenixGUIStyles.LightBorderColor);

                    rect.y += 2;
                    if (OdinTrialVersionInfo.IsExpired)
                    {
                        EditorGUI.DrawRect(bgRect, Color.black);
                        GUIHelper.PushContentColor(Color.red);

                        GUI.Label(rect.AddY(3), "Odin Inspector Trial expired!", SirenixGUIStyles.Label);
                        GUIHelper.PopContentColor();
                        var btnRect = rect.AlignRight(EditorStyles.miniButton.CalcSize(new GUIContent("Purchase Odin Inspector")).x);
                        btnRect.yMin += 2;
                        btnRect.yMax -= 2;
                        GUIHelper.PushColor(Color.green);
                        if (GUI.Button(btnRect, "Purchase Odin Inspector", EditorStyles.miniButton))
                        {
                            UnityEditorInternal.AssetStore.Open("content/89041");
                        }
                        GUIHelper.PopColor();
                    }
                    else
                    {
                        GUI.Label(rect, "Odin Inspector Trial Version", SirenixGUIStyles.LeftAlignedGreyMiniLabel);
                        GUI.Label(rect, "Expires " + OdinTrialVersionInfo.ExpirationDate.ToShortDateString(), EditorStyles.centeredGreyMiniLabel);
                        GUI.Label(rect, OdinTrialVersionInfo.ExpirationDate.Subtract(System.DateTime.Now).TotalHours.ToString("F2") + " hours remaining.", SirenixGUIStyles.RightAlignedGreyMiniLabel);
                    }
                }
#endif
            }
            finally
            {
                EditorTimeHelper.Time = tree.prevTimeHelper;
            }
        }