Ejemplo n.º 1
0
 protected override bool OnSetValue(object newValue)
 {
     if (PropertyInfo.CanWrite)
     {
         PropertyInfo.SetValue(_instance, newValue, null);
         // Needed for structs to propagate changes back to the original field/prop
         if (_parent != null && _parent.CanSetValue())
         {
             _parent.SetValue(_instance);
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
        private void DrawSingleContentEntry(ICacheEntry entry)
        {
            GUILayout.BeginHorizontal((_inspectorRecordHeight));
            {
                GUILayout.Label(entry.TypeName(), (_inspectorTypeWidth));

                var value = entry.GetValue();

                if (entry.CanEnterValue() || value is Exception)
                {
                    DrawVariableNameEnterButton(entry);
                }
                else
                {
                    DrawVariableName(entry);
                }

                if (entry.CanSetValue() &&
                    CanCovert(EditorUtilities.ExtractText(value), entry.Type()))
                {
                    DrawEditableValue(entry, value, GUILayout.ExpandWidth(true));
                }
                else
                {
                    DrawValue(value, GUILayout.ExpandWidth(true));
                }

                if (DnSpyHelper.IsAvailable && GUILayout.Button("^", _dnSpyButtonOptions))
                {
                    DnSpyHelper.OpenInDnSpy(entry);
                }
            }
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 3
0
        public static void DrawSettingValue(ICacheEntry setting, object value)
        {
            if (Event.current.isKey && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter))
            {
                _userHasHitReturn = true;
            }

            if (setting is MethodCacheEntry)
            {
                DrawUnknownField(value);
            }
            else
            {
                var canSetValue = setting.CanSetValue();
                if (!canSetValue)
                {
                    GUI.color = Color.gray;
                }

                var t = setting.Type();
                if (t.IsEnum)
                {
                    if (t.GetCustomAttributes(typeof(FlagsAttribute), false).Any())
                    {
                        DrawFlagsField(setting, Enum.GetValues(t), value);
                    }
                    else
                    {
                        DrawComboboxField(setting, Enum.GetValues(t), value);
                    }
                }
                else if (setting.CanEnterValue() && SettingDrawHandlers.TryGetValue(setting.Type(), out var drawMethod))
                {
                    drawMethod(setting, value);
                }
                else
                {
                    if (canSetValue && ToStringConverter.CanEditValue(setting, value))
                    {
                        DrawGenericEditableValue(setting, value, GUILayout.ExpandWidth(true));
                    }
                    else
                    {
                        DrawUnknownField(value);
                    }
                }

                GUI.color = Color.white;
            }
        }
Ejemplo n.º 4
0
        private void DrawSingleContentEntry(ICacheEntry entry)
        {
            GUILayout.BeginHorizontal(_inspectorRecordHeight);
            {
                try
                {
                    GUILayout.Label(entry.TypeName(), _inspectorTypeWidth);

                    var value = entry.GetValue();

                    if (entry.CanEnterValue() || value is Exception)
                    {
                        DrawVariableNameEnterButton(entry);
                    }
                    else
                    {
                        GUILayout.TextArea(entry.Name(), GUI.skin.label, _inspectorNameWidth);
                    }

                    if (entry.CanSetValue() && ToStringConverter.CanEditValue(entry, value))
                    {
                        DrawEditableValue(entry, value, GUILayout.ExpandWidth(true));
                    }
                    else
                    {
                        GUILayout.TextArea(ToStringConverter.ObjectToString(value), GUI.skin.label, GUILayout.ExpandWidth(true));
                    }

                    if (DnSpyHelper.IsAvailable && GUILayout.Button("^", _dnSpyButtonOptions))
                    {
                        DnSpyHelper.OpenInDnSpy(entry);
                    }
                }
                catch (Exception ex)
                {
                    RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, $"Failed to draw setting {entry?.Name()} - {ex.Message}");
                    GUILayout.TextArea(ex.Message, GUI.skin.label, GUILayout.ExpandWidth(true));
                }
            }
            GUILayout.EndHorizontal();
        }