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

            if (!Equals(text, result) || isBeingEdited)
            {
                if (_userHasHitReturn)
                {
                    _currentlyEditingTag = null;
                    _userHasHitReturn    = false;
                    try
                    {
                        var converted = Convert.ChangeType(result, field.Type());
                        if (!Equals(converted, value))
                        {
                            field.SetValue(converted);
                        }
                    }
                    catch (Exception ex)
                    {
                        RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, "[Inspector] Failed to set value - " + ex.Message);
                    }
                }
                else
                {
                    _currentlyEditingText = result;
                    _currentlyEditingTag  = field;
                }
            }
        }
Esempio n. 3
0
        public static string GetEditValue(ICacheEntry field, object value)
        {
            var valueType = field.Type();

            if (valueType == typeof(string))
            {
                return((string)value ?? "");
            }

            var isNull = value.IsNullOrDestroyed();

            if (isNull != null)
            {
                return(isNull);
            }

            var typeConverter = TomlTypeConverter.GetConverter(valueType);

            if (typeConverter != null)
            {
                return(typeConverter.ConvertToString(value, valueType));
            }

            return(ToStringConverter.ObjectToString(value));
        }
Esempio n. 4
0
        public static bool CanEditValue(ICacheEntry field, object value)
        {
            var valueType = field.Type();

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

            if (_canCovertCache.ContainsKey(valueType))
            {
                return(_canCovertCache[valueType]);
            }

            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);
            }
        }
Esempio n. 5
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 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);
 }