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;
            }
        }
Beispiel #2
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();
        }