コード例 #1
0
        /// <summary>
        /// This should be called from OnGUI before other properties are accessed
        /// because some of Unity's IMGUI methods can't be called outside of OnGUI.
        /// </summary>
        public void Setup()
        {
            if (setupDone)
            {
                return;
            }

            if (Event.current == null)
            {
                                #if DEV_MODE
                Debug.LogWarning("InspectorPreferences.Setup called with Event.current null");
                                #endif

                Styles = new InspectorStyles(null);
            }
            else
            {
                themes.Setup(DrawGUI.IsProSkin, GUI.skin);
                Styles    = new InspectorStyles(theme.guiSkin);
                setupDone = true;
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(theme != null, "InspectorPreferences.Setup - themes.Active was null. Event.current=" + StringUtils.ToString(Event.current) + ".");
                        #endif

            theme.SyntaxHighlight.OnValidate();

            jsonSerializerSettings = new JsonSerializerSettings
            {
                DefaultValueHandling  = DefaultValueHandling.Include,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                NullValueHandling     = NullValueHandling.Include,
                ContractResolver      = new Newtonsoft.Json.Serialization.JsonFullSerializationContractResolver()
            };
            var converters = jsonSerializerSettings.Converters;
            converters.Clear();             //remove any existing converters
            converters.Add(new BinaryConverter());
            converters.Add(new BsonObjectIdConverter());
            converters.Add(new ColorConverter());
            converters.Add(new CharJsonConverter());
            converters.Add(new DoubleJsonConverter());            //gets rid of the trailing ".0"
            converters.Add(new FloatJsonConverter());             //gets rid of the trailing ".0"
            converters.Add(new IsoDateTimeConverter());
            converters.Add(new KeyValuePairConverter());
            converters.Add(new Matrix4x4Converter());
            converters.Add(new QuaternionJsonConverter());
            converters.Add(new RectJsonConverter());
            converters.Add(new RectOffsetJsonConverter());
            converters.Add(new RegexConverter());
            converters.Add(new ResolutionConverter());
            converters.Add(new StringJsonConverter());
            converters.Add(new StringEnumConverter());
            converters.Add(new TypeJsonConverter());             //supports deserializing types from just short name
            converters.Add(new UnityObjectReferenceConverter());
            converters.Add(new VectorsJsonConverter());          //supports copy-pasting between Vector2, Vector3 and Vector4 and even pasting values of things like Rect
            converters.Add(new VersionConverter());
            converters.Add(new GUIStyleConverter());
            converters.Add(new DelegateJsonConverter());
        }
コード例 #2
0
        private void OnValidate()
        {
            if (onValidateInProgress)
            {
                return;
            }
            onValidateInProgress = true;

            var isBeingEdited = Platform.EditorMode && InspectorUtility.ActiveManager != null && InspectorUtility.ActiveManager.ActiveInspector != null && InspectorUtility.ActiveManager.ActiveInspector.State.drawers.First() != null && Array.IndexOf(InspectorUtility.ActiveManager.ActiveInspector.State.drawers.First().GetValues(), this) != -1;

                        #if DEV_MODE && DEBUG_ON_VALIDATE
            Debug.Log("InspectorPreferences.OnValidate called with isBeingEdited=" + StringUtils.ToColorizedString(isBeingEdited));
                        #endif

            if (isBeingEdited)
            {
                isFirstOnValidate = false;

                //If Setup hasn't been called yet this can be null
                if (theme != null && DrawGUI.prefixLabelMouseovered != null)
                {
                    var mouseoverColor = mouseoverEffects.prefixLabelTint ? theme.PrefixMouseoveredText : theme.PrefixIdleText;
                    DrawGUI.prefixLabelMouseovered.SetAllTextColors(mouseoverColor);
                    DrawGUI.prefixLabelMouseoveredModified.SetAllTextColors(mouseoverColor);
                    DrawGUI.foldoutStyleMouseovered.SetAllTextColors(mouseoverColor);
                    DrawGUI.foldoutStyleSelectedMouseovered.SetAllTextColors(mouseoverColor);
                    PrefixDrawer.ClearCache();

                    // This was happening when the themes field was edited
                    if (theme.guiSkin == null)
                    {
                                                #if DEV_MODE
                        Debug.LogError("InspectorPreferences.OnValidate - guiSkin of theme \"" + theme.Name + "\" was null!");
                                                #endif
                        return;
                    }

                    Styles = new InspectorStyles(theme.guiSkin);
                }

                themes.OnValidate();

                if (onSettingsChanged != null)
                {
                    onSettingsChanged(this);
                }
            }
            else
            {
                if (isFirstOnValidate)
                {
                    isFirstOnValidate = false;

                                        #if !DISABLE_UPDATES && UNITY_EDITOR
                    EditorApplication.delayCall += ApplyRelevantUpdates;
                                        #endif
                }
            }

            onValidateInProgress = false;
        }