Exemple #1
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();
        }
        private static void DrawGenericEditableValue(ICacheEntry field, object value, params GUILayoutOption[] layoutParams)
        {
            var isBeingEdited = _currentlyEditingTag == field;
            var text          = isBeingEdited ? _currentlyEditingText : ToStringConverter.GetEditValue(field, value);
            var result        = GUILayout.TextField(text, layoutParams);

            if (!Equals(text, result) || isBeingEdited)
            {
                if (_userHasHitReturn)
                {
                    _currentlyEditingTag = null;
                    _userHasHitReturn    = false;

                    ToStringConverter.SetEditValue(field, value, result);
                }
                else
                {
                    _currentlyEditingText = result;
                    _currentlyEditingTag  = field;
                }
            }
        }
Exemple #3
0
        public static bool CanEditValue(ICacheEntry field, object value)
        {
            var valueType = field.Type();

            if (valueType == null)
            {
                return(false);
            }

            if (valueType == typeof(string))
            {
                return(true);
            }

            if (_canCovertCache.TryGetValue(valueType, out var stored))
            {
                return(stored);
            }

            if (TomlTypeConverter.GetConverter(valueType) != null)
            {
                _canCovertCache[valueType] = true;
                return(true);
            }

            try
            {
                var converted = ToStringConverter.ObjectToString(value);
                var _         = Convert.ChangeType(converted, valueType);
                _canCovertCache[valueType] = true;
                return(true);
            }
            catch
            {
                _canCovertCache[valueType] = false;
                return(false);
            }
        }
 private static void DrawUnknownField(object value)
 {
     GUILayout.TextArea(ToStringConverter.ObjectToString(value), GUI.skin.label, GUILayout.ExpandWidth(true));
 }
 private void DrawValue(object value, params GUILayoutOption[] layoutParams)
 {
     GUILayout.TextArea(ToStringConverter.ObjectToString(value), GUI.skin.label, layoutParams);
 }