Exemple #1
0
        private void SetGenericRows()
        {
            for (int i = 0; i < genericArguments.Length || i < genericArgRows.Count; i++)
            {
                if (i >= genericArguments.Length)
                {
                    if (i >= genericArgRows.Count)
                    {
                        break;
                    }
                    else
                    {
                        // exceeded actual args, but still iterating so there must be views left, disable them
                        genericArgRows[i].SetActive(false);
                    }
                    continue;
                }

                var arg = genericArguments[i];

                if (i >= genericArgRows.Count)
                {
                    AddArgRow(i, true);
                }

                genericArgRows[i].SetActive(true);

                var autoCompleter = genericAutocompleters[i];
                autoCompleter.BaseType = arg;
                autoCompleter.CacheTypes();

                var constraints = arg.GetGenericParameterConstraints();
                autoCompleter.GenericConstraints = constraints;

                var sb = new StringBuilder($"<color={SignatureHighlighter.CONST}>{arg.Name}</color>");

                for (int j = 0; j < constraints.Length; j++)
                {
                    if (j == 0)
                    {
                        sb.Append(' ').Append('(');
                    }
                    else
                    {
                        sb.Append(',').Append(' ');
                    }

                    sb.Append(SignatureHighlighter.Parse(constraints[j], false));

                    if (j + 1 == constraints.Length)
                    {
                        sb.Append(')');
                    }
                }

                genericArgLabels[i].text = sb.ToString();
            }
        }
        // Setting target

        private void SetTarget(object target)
        {
            string prefix;

            if (StaticOnly)
            {
                Target     = null;
                TargetType = target as Type;
                prefix     = "[S]";
            }
            else
            {
                TargetType = target.GetActualType();
                prefix     = "[R]";
            }

            // Setup main labels and tab text
            currentBaseTabText = $"{prefix} {SignatureHighlighter.Parse(TargetType, false)}";
            Tab.TabText.text   = currentBaseTabText;
            NameText.text      = SignatureHighlighter.Parse(TargetType, true);

            string asmText;

            if (TargetType.Assembly is AssemblyBuilder || string.IsNullOrEmpty(TargetType.Assembly.Location))
            {
                asmText = $"{TargetType.Assembly.GetName().Name} <color=grey><i>(in memory)</i></color>";
            }
            else
            {
                asmText = Path.GetFileName(TargetType.Assembly.Location);
            }
            AssemblyText.text = $"<color=grey>Assembly:</color> {asmText}";

            // unity helpers
            SetUnityTargets();

            // Get cache members

            this.members = CacheMember.GetCacheMembers(Target, TargetType, this);

            // reset filters

            this.filterInputField.Text = "";

            SetFilter("", StaticOnly ? BindingFlags.Static : BindingFlags.Instance);
            scopeFilterButtons[BindingFlags.Default].Component.gameObject.SetActive(!StaticOnly);
            scopeFilterButtons[BindingFlags.Instance].Component.gameObject.SetActive(!StaticOnly);

            foreach (var toggle in memberTypeToggles)
            {
                toggle.isOn = true;
            }

            refreshWanted = true;
        }
Exemple #3
0
        protected virtual void SetValueState(CacheObjectCell cell, ValueStateArgs args)
        {
            // main value label
            if (args.valueActive)
            {
                cell.ValueLabel.text            = ValueLabelText;
                cell.ValueLabel.supportRichText = args.valueRichText;
                cell.ValueLabel.color           = args.valueColor;
            }
            else
            {
                cell.ValueLabel.text = "";
            }

            // Type label (for primitives)
            cell.TypeLabel.gameObject.SetActive(args.typeLabelActive);
            if (args.typeLabelActive)
            {
                cell.TypeLabel.text = SignatureHighlighter.Parse(LastValueType, false);
            }

            // toggle for bools
            cell.Toggle.gameObject.SetActive(args.toggleActive);
            if (args.toggleActive)
            {
                cell.Toggle.interactable = CanWrite;
                cell.Toggle.isOn         = (bool)Value;
                cell.ToggleText.text     = Value.ToString();
            }

            // inputfield for numbers
            cell.InputField.UIRoot.SetActive(args.inputActive);
            if (args.inputActive)
            {
                cell.InputField.Text = ParseUtility.ToStringForInput(Value, LastValueType);
                cell.InputField.Component.readOnly = !CanWrite;
            }

            // apply for bool and numbers
            cell.ApplyButton.Component.gameObject.SetActive(args.applyActive);

            // Inspect button only if last value not null.
            if (cell.InspectButton != null)
            {
                cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull);
            }

            // allow IValue for null strings though
            cell.SubContentButton.Component.gameObject.SetActive(args.subContentButtonActive && (!LastValueWasNull || State == ValueState.String));
        }
        void AddSuggestion(Type type)
        {
            if (suggestedNames.Contains(type.FullName))
            {
                return;
            }
            suggestedNames.Add(type.FullName);

            if (!sharedTypeToLabel.ContainsKey(type.FullName))
            {
                sharedTypeToLabel.Add(type.FullName, SignatureHighlighter.Parse(type, true));
            }

            suggestions.Add(new Suggestion(sharedTypeToLabel[type.FullName], type.FullName));
        }
        public void SetCell(HookCell cell, int index)
        {
            if (index >= this.currentHooks.Count)
            {
                cell.Disable();
                return;
            }

            cell.CurrentDisplayedIndex = index;
            var hook = (HookInstance)this.currentHooks[index];

            cell.MethodNameLabel.text = SignatureHighlighter.HighlightMethod(hook.TargetMethod);

            cell.ToggleActiveButton.ButtonText.text = hook.Enabled ? "Enabled" : "Disabled";
            RuntimeHelper.SetColorBlockAuto(cell.ToggleActiveButton.Component,
                                            hook.Enabled ? new Color(0.15f, 0.2f, 0.15f) : new Color(0.2f, 0.2f, 0.15f));
        }
Exemple #6
0
        public override void ConstructUI(GameObject parent, GameObject subGroup)
        {
            base.ConstructUI(parent, subGroup);

            GetDefaultLabel(false);
            m_richValueType = SignatureHighlighter.ParseFullSyntax(FallbackType, false);

            m_labelLayout = m_baseLabel.gameObject.GetComponent <LayoutElement>();

            m_readonlyInput = UIFactory.CreateLabel(m_mainContent, "ReadonlyLabel", "", TextAnchor.MiddleLeft);
            m_readonlyInput.horizontalOverflow = HorizontalWrapMode.Overflow;

            var testFitter = m_readonlyInput.gameObject.AddComponent <ContentSizeFitter>();

            testFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;

            UIFactory.SetLayoutElement(m_readonlyInput.gameObject, minHeight: 25, preferredHeight: 25, flexibleHeight: 0);
        }
Exemple #7
0
        public ReflectionInspector(object target) : base(target)
        {
            if (this is StaticInspector)
            {
                m_targetType = target as Type;
            }
            else
            {
                m_targetType = ReflectionUtility.GetActualType(target);
            }

            m_targetTypeShortName = SignatureHighlighter.ParseFullSyntax(m_targetType, false);

            ConstructUI();

            CacheMembers(m_targetType);

            FilterMembers();
        }
Exemple #8
0
        public void SetCell(ButtonCell cell, int index)
        {
            if (!cachedCellTexts.ContainsKey(index))
            {
                string text;
                if (m_context == SearchContext.StaticClass)
                {
                    text = SignatureHighlighter.Parse(currentResults[index] as Type, true);
                }
                else
                {
                    text = ToStringUtility.ToStringWithType(currentResults[index], currentResults[index]?.GetActualType());
                }

                cachedCellTexts.Add(index, text);
            }

            cell.Button.ButtonText.text = cachedCellTexts[index];
        }
Exemple #9
0
        private void SetNormalArgRows()
        {
            for (int i = 0; i < arguments.Length || i < argRows.Count; i++)
            {
                if (i >= arguments.Length)
                {
                    if (i >= argRows.Count)
                    {
                        break;
                    }
                    else
                    {
                        // exceeded actual args, but still iterating so there must be views left, disable them
                        argRows[i].SetActive(false);
                    }
                    continue;
                }

                var arg = arguments[i];


                if (i >= argRows.Count)
                {
                    AddArgRow(i, false);
                }

                argRows[i].SetActive(true);
                argLabels[i].text = $"{SignatureHighlighter.Parse(arg.ParameterType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{arg.Name}</color>";
                if (arg.ParameterType == typeof(string))
                {
                    argInputFields[i].PlaceholderText.text = "";
                }
                else
                {
                    var elemType = arg.ParameterType;
                    if (elemType.IsByRef)
                    {
                        elemType = elemType.GetElementType();
                    }
                    argInputFields[i].PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(elemType)}";
                }
            }
        }
Exemple #10
0
        public void SetKey(object key)
        {
            this.DictKey      = key;
            this.DisplayedKey = key.TryCast();

            var type = DisplayedKey.GetType();

            if (ParseUtility.CanParse(type))
            {
                KeyInputWanted   = true;
                KeyInputText     = ParseUtility.ToStringForInput(DisplayedKey, type);
                KeyInputTypeText = SignatureHighlighter.Parse(type, false);
            }
            else
            {
                KeyInputWanted = false;
                InspectWanted  = type != typeof(bool) && !type.IsEnum;
                KeyLabelText   = ToStringUtility.ToStringWithType(DisplayedKey, type, true);
            }
        }
        public override void SetValue(object value)
        {
            if (value == null)
            {
                // should never be null
                ClearAndRelease();
                return;
            }
            else
            {
                var type = value.GetActualType();
                ReflectionUtility.TryGetEntryTypes(type, out KeysType, out ValuesType);

                CacheEntries(value);

                TopLabel.text = $"[{cachedEntries.Count}] {SignatureHighlighter.Parse(type, false)}";
            }

            this.DictScrollPool.Refresh(true, false);
        }
        // Called from ButtonListHandler.SetCell, will be valid
        private void SetComponentCell(ComponentCell cell, int index)
        {
            var entries = GetEntries();

            cell.Enable();

            var comp = entries[index];
            var type = comp.GetActualType();

            if (!compToStringCache.ContainsKey(type.AssemblyQualifiedName))
            {
                compToStringCache.Add(type.AssemblyQualifiedName, SignatureHighlighter.Parse(type, true));
            }

            cell.Button.ButtonText.text = compToStringCache[type.AssemblyQualifiedName];

            if (typeof(Behaviour).IsAssignableFrom(type))
            {
                cell.BehaviourToggle.interactable = true;
                cell.BehaviourToggle.Set(comp.TryCast <Behaviour>().enabled, false);
                cell.BehaviourToggle.graphic.color = new Color(0.8f, 1, 0.8f, 0.3f);
            }
            else
            {
                cell.BehaviourToggle.interactable = false;
                cell.BehaviourToggle.Set(true, false);
                //RuntimeProvider.Instance.SetColorBlock(cell.BehaviourToggle,)
                cell.BehaviourToggle.graphic.color = new Color(0.2f, 0.2f, 0.2f);
            }

            // if component is the first index it must be the transform, dont show Destroy button for it.
            if (index == 0 && cell.DestroyButton.Component.gameObject.activeSelf)
            {
                cell.DestroyButton.Component.gameObject.SetActive(false);
            }
            else if (index > 0 && !cell.DestroyButton.Component.gameObject.activeSelf)
            {
                cell.DestroyButton.Component.gameObject.SetActive(true);
            }
        }
        public override void RefreshUIForValue()
        {
            if (!Owner.HasEvaluated)
            {
                GetDefaultLabel();
                m_baseLabel.text = DefaultLabel;
                return;
            }

            m_baseLabel.text  = SignatureHighlighter.ParseFullSyntax(FallbackType, false);
            m_valueInput.text = Value.ToString();

            var type = Value.GetType();

            if (type == typeof(float) ||
                type == typeof(double) ||
                type == typeof(decimal))
            {
                m_valueInput.characterValidation = InputField.CharacterValidation.Decimal;
            }
            else
            {
                m_valueInput.characterValidation = InputField.CharacterValidation.Integer;
            }

            if (Owner.CanWrite)
            {
                if (!m_applyBtn.gameObject.activeSelf)
                {
                    m_applyBtn.gameObject.SetActive(true);
                }
            }

            if (!m_valueInput.gameObject.activeSelf)
            {
                m_valueInput.gameObject.SetActive(true);
            }
        }
Exemple #14
0
        // Setting the List value itself to this model
        public override void SetValue(object value)
        {
            if (value == null)
            {
                // should never be null
                if (cachedEntries.Any())
                {
                    ClearAndRelease();
                }
            }
            else
            {
                var type = value.GetActualType();
                ReflectionUtility.TryGetEntryType(type, out EntryType);

                CacheEntries(value);

                TopLabel.text = $"[{cachedEntries.Count}] {SignatureHighlighter.Parse(type, false)}";
            }

            //this.ScrollPoolLayout.minHeight = Math.Min(400f, 35f * values.Count);
            this.ListScrollPool.Refresh(true, false);
        }
        internal void AddGenericArgRow(int i, GameObject parent)
        {
            var arg = GenericArgs[i];

            string constrainTxt = "";

            if (this.GenericConstraints[i].Length > 0)
            {
                foreach (var constraint in this.GenericConstraints[i])
                {
                    if (constrainTxt != "")
                    {
                        constrainTxt += ", ";
                    }

                    constrainTxt += $"{SignatureHighlighter.ParseFullSyntax(constraint, false)}";
                }
            }
            else
            {
                constrainTxt = $"Any";
            }

            var rowObj = UIFactory.CreateHorizontalGroup(parent, "ArgRowObj", false, true, true, true, 4, default, new Color(1, 1, 1, 0));
Exemple #16
0
        public void OnBorrowed(EvaluateWidget evaluator, Type genericConstraint)
        {
            this.evaluator   = evaluator;
            this.genericType = genericConstraint;

            typeCompleter.Enabled  = true;
            typeCompleter.BaseType = genericType;
            typeCompleter.CacheTypes();

            var constraints = genericType.GetGenericParameterConstraints();

            typeCompleter.GenericConstraints = constraints;

            var sb = new StringBuilder($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");

            for (int j = 0; j < constraints.Length; j++)
            {
                if (j == 0)
                {
                    sb.Append(' ').Append('(');
                }
                else
                {
                    sb.Append(',').Append(' ');
                }

                sb.Append(SignatureHighlighter.Parse(constraints[j], false));

                if (j + 1 == constraints.Length)
                {
                    sb.Append(')');
                }
            }

            argNameLabel.text = sb.ToString();
        }
Exemple #17
0
        internal void RefreshComponentList()
        {
            var go = GameObjectInspector.ActiveInstance.TargetGO;

            s_allComps = go.GetComponents <Component>().ToArray();

            var components = s_allComps;

            s_compListPageHandler.ListCount = components.Length;

            //int startIndex = m_sceneListPageHandler.StartIndex;

            int newCount = 0;

            foreach (var itemIndex in s_compListPageHandler)
            {
                newCount++;

                // normalized index starting from 0
                var i = itemIndex - s_compListPageHandler.StartIndex;

                if (itemIndex >= components.Length)
                {
                    if (i > s_lastCompCount || i >= s_compListTexts.Count)
                    {
                        break;
                    }

                    GameObject label = s_compListTexts[i].transform.parent.parent.gameObject;
                    if (label.activeSelf)
                    {
                        label.SetActive(false);
                    }
                }
                else
                {
                    Component comp = components[itemIndex];

                    if (!comp)
                    {
                        continue;
                    }

                    if (i >= s_compShortlist.Count)
                    {
                        s_compShortlist.Add(comp);
                        AddCompListButton();
                    }
                    else
                    {
                        s_compShortlist[i] = comp;
                    }

                    var text = s_compListTexts[i];

                    text.text = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetActualType(comp), true);

                    var toggle = s_compToggles[i];
                    if (comp.TryCast <Behaviour>() is Behaviour behaviour)
                    {
                        if (!toggle.gameObject.activeSelf)
                        {
                            toggle.gameObject.SetActive(true);
                        }

                        toggle.isOn = behaviour.enabled;
                    }
                    else
                    {
                        if (toggle.gameObject.activeSelf)
                        {
                            toggle.gameObject.SetActive(false);
                        }
                    }

                    var label = text.transform.parent.parent.gameObject;
                    if (!label.activeSelf)
                    {
                        label.SetActive(true);
                    }
                }
            }

            s_lastCompCount = newCount;
        }
Exemple #18
0
 public virtual void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
 {
     this.Owner            = inspector;
     this.NameLabelText    = SignatureHighlighter.Parse(member.DeclaringType, false, member);
     this.NameForFiltering = $"{member.DeclaringType.Name}.{member.Name}";
 }
 private string GetRichTextName()
 {
     return(m_richTextName = SignatureHighlighter.ParseFullSyntax(MemInfo.DeclaringType, false, MemInfo));
 }
Exemple #20
0
        public void OnBorrowed(EvaluateWidget evaluator, ParameterInfo paramInfo)
        {
            this.evaluator = evaluator;
            this.paramInfo = paramInfo;

            this.paramType = paramInfo.ParameterType;
            if (paramType.IsByRef)
            {
                paramType = paramType.GetElementType();
            }

            this.argNameLabel.text =
                $"{SignatureHighlighter.Parse(paramType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{paramInfo.Name}</color>";

            if (ParseUtility.CanParse(paramType) || typeof(Type).IsAssignableFrom(paramType))
            {
                usingBasicLabel = false;

                this.inputField.Component.gameObject.SetActive(true);
                this.basicLabelHolder.SetActive(false);
                this.typeCompleter.Enabled = typeof(Type).IsAssignableFrom(paramType);
                this.enumCompleter.Enabled = paramType.IsEnum;
                this.enumHelperButton.Component.gameObject.SetActive(paramType.IsEnum);

                if (!typeCompleter.Enabled)
                {
                    if (paramType == typeof(string))
                    {
                        inputField.PlaceholderText.text = "...";
                    }
                    else
                    {
                        inputField.PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(paramType)}";
                    }
                }
                else
                {
                    inputField.PlaceholderText.text = "Enter a Type name...";
                    this.typeCompleter.BaseType     = typeof(object);
                    this.typeCompleter.CacheTypes();
                }

                if (enumCompleter.Enabled)
                {
                    enumCompleter.EnumType = paramType;
                    enumCompleter.CacheEnumValues();
                }
            }
            else
            {
                // non-parsable, and not a Type
                usingBasicLabel = true;

                this.inputField.Component.gameObject.SetActive(false);
                this.basicLabelHolder.SetActive(true);
                this.typeCompleter.Enabled = false;
                this.enumCompleter.Enabled = false;
                this.enumHelperButton.Component.gameObject.SetActive(false);

                SetDisplayedValueFromPaste();
            }
        }
Exemple #21
0
        protected string GetValueLabel()
        {
            string label = "";

            switch (State)
            {
            case ValueState.NotEvaluated:
                return($"<i>{NOT_YET_EVAL} ({SignatureHighlighter.Parse(FallbackType, true)})</i>");

            case ValueState.Exception:
                return($"<i><color=red>{LastException.ReflectionExToString()}</color></i>");

            // bool and number dont want the label for the value at all
            case ValueState.Boolean:
            case ValueState.Number:
                return(null);

            // and valuestruct also doesnt want it if we can parse it
            case ValueState.ValueStruct:
                if (ParseUtility.CanParse(LastValueType))
                {
                    return(null);
                }
                break;

            // string wants it trimmed to max 200 chars
            case ValueState.String:
                if (!LastValueWasNull)
                {
                    return($"\"{ToStringUtility.PruneString(Value as string, 200, 5)}\"");
                }
                break;

            // try to prefix the count of the collection for lists and dicts
            case ValueState.Collection:
                if (!LastValueWasNull)
                {
                    if (Value is IList iList)
                    {
                        label = $"[{iList.Count}] ";
                    }
                    else if (Value is ICollection iCol)
                    {
                        label = $"[{iCol.Count}] ";
                    }
                    else
                    {
                        label = "[?] ";
                    }
                }
                break;

            case ValueState.Dictionary:
                if (!LastValueWasNull)
                {
                    if (Value is IDictionary iDict)
                    {
                        label = $"[{iDict.Count}] ";
                    }
                    else
                    {
                        label = "[?] ";
                    }
                }
                break;
            }

            // Cases which dont return will append to ToStringWithType

            return(label += ToStringUtility.ToStringWithType(Value, FallbackType, true));
        }
        // Updating result list content

        private void RefreshResultList()
        {
            if (m_resultListPageHandler == null || m_results == null)
            {
                return;
            }

            m_resultListPageHandler.ListCount = m_results.Length;

            int newCount = 0;

            foreach (var itemIndex in m_resultListPageHandler)
            {
                newCount++;

                // normalized index starting from 0
                var i = itemIndex - m_resultListPageHandler.StartIndex;

                if (itemIndex >= m_results.Length)
                {
                    if (i > m_lastCount || i >= m_resultListTexts.Count)
                    {
                        break;
                    }

                    GameObject label = m_resultListTexts[i].transform.parent.parent.gameObject;
                    if (label.activeSelf)
                    {
                        label.SetActive(false);
                    }
                }
                else
                {
                    var obj      = m_results[itemIndex];
                    var unityObj = obj as UnityEngine.Object;

                    if (obj == null || (unityObj != null && !unityObj))
                    {
                        continue;
                    }

                    if (i >= m_resultShortList.Count)
                    {
                        m_resultShortList.Add(obj);
                        AddResultButton();
                    }
                    else
                    {
                        m_resultShortList[i] = obj;
                    }

                    var text = m_resultListTexts[i];

                    if (m_context != SearchContext.StaticClass)
                    {
                        var name = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetType(obj), true);

                        if (unityObj && m_context != SearchContext.Singleton)
                        {
                            if (unityObj && !string.IsNullOrEmpty(unityObj.name))
                            {
                                name += $": {unityObj.name}";
                            }
                            else
                            {
                                name += ": <i><color=grey>untitled</color></i>";
                            }
                        }

                        text.text = name;
                    }
                    else
                    {
                        var type = obj as Type;
                        text.text = SignatureHighlighter.ParseFullSyntax(type, true);
                    }

                    var label = text.transform.parent.parent.gameObject;
                    if (!label.activeSelf)
                    {
                        label.SetActive(true);
                    }
                }
            }

            m_lastCount = newCount;
        }