private VisualizerBase FindVisualizor(Type type) { if (type.IsPrimitive) { return(primitiveAndNullVisualizer); } if (type.IsEnum) { return(enumVisualizer); } if (rules.ContainsKey(type)) { return(rules[type]); } VisualizerBase visualizor = FindBaseTypeVisualizer(type); if (visualizor != null) { return(visualizor); } visualizor = FindInterfaceVisualizer(type); if (visualizor != null) { return(visualizor); } return(compositeVisualizer); }
private bool InspectRoot(string name, Type type, ref object data, VisualizerBase visualizer, IMark mark) { using (GUITools.HorizontalScope()) { bool changed = visualizer.InspectSelf(this, name, ref data, type); if (type != null && type.IsClass) { if (data != null) { if (GUILayout.Button("-", GUILayout.Width(20))) { data = null; changed = true; } } else { if (GUILayout.Button("+", GUILayout.Width(20))) { data = CreateClassInstance(type, visualizer, mark); changed = true; } } } return(changed); } }
public void SetSpecialVisualizer(SpecialVisualizer type, VisualizerBase income) { if (income == null) { throw new ArgumentNullException("income"); } AssertValidSetupState(); switch (type) { case SpecialVisualizer.Composite: compositeVisualizer = income; break; case SpecialVisualizer.Enum: enumVisualizer = income; break; case SpecialVisualizer.PrimitiveAndNull: primitiveAndNullVisualizer = income; break; default: throw new NotImplementedException(type.ToString()); } }
private void RegisterDefaultVisualizers() { ///////////////////////////////////////////////////////////////////////// // Register three special visualizer primitiveAndNullVisualizer = new PrimitiveVisualizer(); compositeVisualizer = new CompositeVisualizer(); enumVisualizer = new EnumVisualizer(); // static visualizers // If input is a type, then show static members of that type // // The draw back is, you cannot inpect the real content of Type type anymore. rules.Add(typeof(Type), new StaticVisualizer()); ///////////////////////////////////////////////////////////////////////// // type --> visualize // C# basic types rules.Add(typeof(string), new StringVisualizer()); rules.Add(typeof(MulticastDelegate), new MulticastDelegateVisualizer()); rules.Add(typeof(DateTime), new DateTimeVisualizer()); rules.Add(typeof(TimeSpan), new TimeSpanVisualizer()); // C# containers rules.Add(typeof(Array), new ArrayVisualizer()); rules.Add(typeof(List <>), new ListVisualizer()); rules.Add(typeof(IDictionary), new DictionaryVisualizer()); rules.Add(typeof(HashSet <>), new HashSetVisualizer()); // UnityEngine types rules.Add(typeof(UnityEngine.Object), new UnityObjectVisualizer()); var unityTypeVisualizer = new UnityTypeVisualizer(); rules.Add(typeof(Color), unityTypeVisualizer); rules.Add(typeof(Vector2), unityTypeVisualizer); rules.Add(typeof(Vector3), unityTypeVisualizer); rules.Add(typeof(Vector4), unityTypeVisualizer); rules.Add(typeof(Bounds), unityTypeVisualizer); rules.Add(typeof(Rect), unityTypeVisualizer); rules.Add(typeof(AnimationCurve), unityTypeVisualizer); // Markers markRules.Add(typeof(UnixTimestampAttribute), new UnixTimeStampVisualizer()); // Extension foreach (var extension in OnRegisterDefaultVisualizers) { extension.Value(this); } }
private static object CreateClassInstance(Type type, VisualizerBase visualizer, IMark mark) { if (visualizer.HasCustomCreator(type, mark)) { return(visualizer.CustomCreateInstance(type, mark)); } try { return(Activator.CreateInstance(type)); } catch (Exception e) { Debug.Log(e); return(null); } }
public void SetVisualizer(Type type, VisualizerBase income) { if (type == null) { throw new ArgumentNullException("type"); } if (income == null) { throw new ArgumentNullException("income"); } AssertValidSetupState(); if (type.GetInterface(typeof(IMark).Name) != null) { markRules[type] = income; } else { rules[type] = income; } }
public bool InspectInternal(string name, string path, object data, Type type = null, IMark mark = null, Action <object> OnValueChanged = null) { if (data != null) { type = data.GetType(); } GUITools.SetLabelWidth(options.labelWidth); VisualizerBase visualizer = GetVisualizer(type, mark); bool changed = false; object changedData = data; if (visualizer != null) { string fieldinfo = name; var postfix = visualizer.GetLabelPostfix(this, data, type); if (postfix != null) { fieldinfo += postfix; } if (visualizer.HasChildren()) { // Note: to avoid infinite expand that may cause by alwaysShowChildren, // If parentAlwaysShowChild, then current node ignores alwaysShowChildren. var parentAlwaysShowChild = parentIsAlwaysShow.Count > 0 && parentIsAlwaysShow.Peek(); bool alwaysShowChildren = !parentAlwaysShowChild && visualizer.AlwaysShowChildren(); if (!alwaysShowChildren) { using (GUITools.HorizontalScope()) { var width = options.labelWidth - options.indentOffset * GUITools.GetIndentLevel(); using (GUITools.HorizontalScope(width)) { isFoldout[path] = GUITools.Foldout(isFoldout.ContainsKey(path) && isFoldout[path], fieldinfo); } changed |= InspectRoot(name, type, ref changedData, visualizer, mark); } } else { changed |= InspectRoot(name, type, ref changedData, visualizer, mark); } if (changedData != null && (alwaysShowChildren || isFoldout[path])) { try { parentIsAlwaysShow.Push(alwaysShowChildren); using (GUITools.Indent()) changed |= visualizer.InspectChildren(this, path, ref changedData, type); } finally { parentIsAlwaysShow.Pop(); } } } else { changed |= InspectRoot(fieldinfo, type, ref changedData, visualizer, mark); } } if (changed && OnValueChanged != null) { OnValueChanged(changedData); } return(changed); }