public override object ParserFiled(InspectorStyle style, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true) { EditorGUILayout.BeginHorizontal(); string path = value as string; path = EditorGUILayout.TextField(new GUIContent("导出路径"), path); if (GUILayout.Button("选择", GUILayout.Width(40))) { string savePath = null; if (style.ParserAgrs == null || (string)style.ParserAgrs[0] == "Folder") { savePath = EditorUtility.SaveFolderPanel("路径", path, ""); } else { savePath = EditorUtility.SaveFilePanel("路径", path, "", (string)style.ParserAgrs[0]); } if (savePath.IsNOTNullOrEmpty()) { path = savePath; } } fieldInfo.SetValue(instance, path); EditorGUILayout.EndHorizontal(); return(path); }
private string GetFieldName(FieldInfo fieldInfo) { InspectorStyle inspectorStyle = fieldInfo.GetAttribute <InspectorStyle>(); string name = inspectorStyle == null ? fieldInfo.Name : inspectorStyle.Name; return(name); }
/// <summary> /// 解析显示字段 /// </summary> /// <param name="style"> /// The style. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="t"> /// The t. /// </param> /// <param name="fieldInfo"> /// The member. /// </param> /// <param name="instance"> /// The instance. /// </param> /// <param name="withName"></param> /// <returns> /// The <see cref="object"/>. /// </returns> public abstract object ParserFiled( InspectorStyle style, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true);
public override object ParserFiled( InspectorStyle style, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true) { var type = style.ParserAgrs[0] as Type; var fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Static); string currValue = value as string; List <FieldInfo> enums = new List <FieldInfo>(); List <GUIContent> enumNames = new List <GUIContent>(); int currIndex = -1; for (int i = 0; i < fieldInfos.Length; i++) { var info = fieldInfos[i]; enums.Add(info); var inspectorStyle = info.GetAttribute <InspectorStyle>(); enumNames.Add(new GUIContent(inspectorStyle == null?info.Name: inspectorStyle.Name)); var o = info.GetValue(null) as string; if (o == currValue) { currIndex = i; } } if (currIndex < 0) { currIndex = 0; } if (withName) { currIndex = EditorGUILayout.Popup(new GUIContent(style.Name), currIndex, enumNames.ToArray()); } else { currIndex = EditorGUILayout.Popup(currIndex, enumNames.ToArray()); } currValue = enums[currIndex].GetValue(null) as string; return(currValue); }
public override object ParserFiled(InspectorStyle style, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true) { int w = -1; int h = 80; if (style.ParserAgrs != null) { if (style.ParserAgrs.Length >= 1) { if (style.ParserAgrs[0] is int) { w = (int)style.ParserAgrs[0]; } } if (style.ParserAgrs.Length >= 2) { if (style.ParserAgrs[1] is int) { h = (int)style.ParserAgrs[1]; } } } GUILayout.BeginHorizontal(); if (withName) { GUILayout.Label(style.Name, GUILayout.Width(145)); } string textArea = null; if (w < 0) { textArea = EditorGUILayout.TextArea((string)value, GUILayout.Height(h)); } else { textArea = EditorGUILayout.TextArea((string)value, GUILayout.Width(w), GUILayout.Height(h)); } GUILayout.EndHorizontal(); return(textArea); }
private int GetComparerValue(T l, T r, string fieldName) { FieldInfo fieldInfo = typeof(T).GetField(fieldName); if (fieldInfo == null) { FieldInfo[] fieldInfos = typeof(T).GetFields(); foreach (var info in fieldInfos) { InspectorStyle inspectorStyle = info.GetAttribute <InspectorStyle>(); if (inspectorStyle != null && inspectorStyle.Name == fieldName) { fieldInfo = info; break; } } } object valueL = fieldInfo.GetValue(l); object valueR = fieldInfo.GetValue(r); return(Comparer.Default.Compare(valueL, valueR)); }
private static void Preference() { tool = GUILayout.Toolbar(tool, new string[] { "Preferences", "Editors", "About" }); if (tool == 0) { EditorGUI.BeginChangeCheck(); inspectDefaultItems = EditorGUILayout.Toggle(new GUIContent("Inspect Default Items", "Draws all types that do not have a Custom Editor associated. If false, your classes are drawn by Unity unless they have the AdvancedInspector attribute."), inspectDefaultItems); expandableReferences = EditorGUILayout.Toggle(new GUIContent("Expandable References", "All MonoBehaviour/ScriptableObject references are expandable from the displayed field."), expandableReferences); collectionItemNaming = (InspectorCollectionItemNaming)EditorGUILayout.EnumPopup(new GUIContent("Collection Naming", "How items in a collection are named."), collectionItemNaming); valueScroll = (InspectorDragControl)EditorGUILayout.EnumPopup("Number Drag", valueScroll); if (valueScroll == copyPaste) { copyPaste = Next(copyPaste); } copyPaste = (InspectorDragControl)EditorGUILayout.EnumPopup("Copy/Paste Drag", copyPaste); if (valueScroll == copyPaste) { valueScroll = Next(valueScroll); } #if UNITY_2017_1 || UNITY_2017_2 massExpand = (InspectorModifierControl)EditorGUILayout.EnumMaskField("Expand/Collapse Children", massExpand); contextual = (InspectorModifierControl)EditorGUILayout.EnumMaskField("Contextual Menu", contextual); #else massExpand = (InspectorModifierControl)EditorGUILayout.EnumFlagsField("Expand/Collapse Children", massExpand); contextual = (InspectorModifierControl)EditorGUILayout.EnumFlagsField("Contextual Menu", contextual); #endif extraIndentation = Mathf.Clamp(EditorGUILayout.IntField("Indentation", extraIndentation), 0, int.MaxValue); largeCollection = Mathf.Clamp(EditorGUILayout.IntField("Large Collection", largeCollection), 10, 200); separator = (SeparatorStyle)EditorGUILayout.EnumPopup("Separator", separator); separatorDefaultColor = EditorGUILayout.ColorField("Separator Default", separatorDefaultColor); separatorSelectedColor = EditorGUILayout.ColorField("Separator Selected", separatorSelectedColor); boxDefaultColor = EditorGUILayout.ColorField("Box Default", boxDefaultColor); boxPlayColor = EditorGUILayout.ColorField("Box Playmode", boxPlayColor); style = (InspectorStyle)EditorGUILayout.EnumPopup("Style", style); Color previous = GUI.color; GUI.color = EditorApplication.isPlaying ? boxPlayColor : boxDefaultColor; GUILayout.Box("", AdvancedInspectorControl.BoxTitleStyle); GUILayout.Box("", AdvancedInspectorControl.BoxStyle); GUI.color = previous; if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetBool(InspectDefaultItemsKey, inspectDefaultItems); EditorPrefs.SetInt(StyleKey, (int)style); EditorPrefs.SetInt(SeparatorKey, (int)separator); EditorPrefs.SetString(SeparatorDefaultKey, ColorToString(separatorDefaultColor)); EditorPrefs.SetString(SeparatorSelectedKey, ColorToString(separatorSelectedColor)); EditorPrefs.SetString(BoxDefaultKey, ColorToString(boxDefaultColor)); EditorPrefs.SetString(BoxPlayKey, ColorToString(boxPlayColor)); EditorPrefs.SetInt(IndentationKey, extraIndentation); EditorPrefs.SetInt(LargeCollectionKey, largeCollection); EditorPrefs.SetInt(ValueScrollKey, (int)valueScroll); EditorPrefs.SetInt(CopyPasteKey, (int)copyPaste); EditorPrefs.SetInt(MassExpandKey, (int)massExpand); EditorPrefs.SetBool(ExpandableReferencesKey, expandableReferences); EditorPrefs.SetInt(CollectionItemNamingKey, (int)collectionItemNaming); } } else if (tool == 1) { bool offAll = false; bool onAll = false; GUILayout.BeginHorizontal(); if (GUILayout.Button("Turn Off")) { offAll = true; } if (GUILayout.Button("Turn On")) { onAll = true; } GUILayout.EndHorizontal(); bool changed = false; scrollView = GUILayout.BeginScrollView(scrollView); foreach (KeyValuePair <FileInfo, string[]> pair in editors) { bool active = !pair.Value[0].Contains("///"); bool result = EditorGUILayout.ToggleLeft(pair.Key.Name, active); if (offAll) { result = false; } if (onAll) { result = true; } if (result != active) { if (!result) { for (int i = 0; i < pair.Value.Length; i++) { pair.Value[i] = "///" + pair.Value[i]; } } else { for (int i = 0; i < pair.Value.Length; i++) { pair.Value[i] = pair.Value[i].Substring(3); } } string path = "Assets" + pair.Key.FullName.Substring(Application.dataPath.Length); if (!AssetDatabase.IsOpenForEdit(path, StatusQueryOptions.UseCachedIfPossible)) { Provider.Checkout(path, CheckoutMode.Both); } File.WriteAllLines(pair.Key.FullName, pair.Value); UnityEngine.Object[] selection = Selection.objects; Selection.objects = new UnityEngine.Object[0]; Selection.objects = selection; changed = true; } } GUILayout.EndScrollView(); if (changed) { AssetDatabase.Refresh(); } } else if (tool == 2) { GUIStyle style = new GUIStyle(); style.normal.textColor = Color.blue; GUI.DrawTexture(new Rect(-16, 36, 379, 93), Logo, ScaleMode.ScaleToFit); GUILayout.Space(100); EditorGUILayout.LabelField(version); GUILayout.Space(10); if (GUILayout.Button("Manual", style)) { Application.OpenURL("http://lightstrikersoftware.com/docs/AdvancedInspector_Manual.pdf"); } GUILayout.Space(10); if (GUILayout.Button("Tutorials", style)) { Application.OpenURL("http://lightstrikersoftware.com/docs/AdvancedInspector_Tutorials.pdf"); } GUILayout.Space(10); EditorGUILayout.LabelField("Need Help? Found A Bug?"); if (GUILayout.Button("*****@*****.**", style)) { Application.OpenURL("mailto:[email protected]"); } } }
static InspectorPreferences() { if (EditorPrefs.HasKey(InspectDefaultItemsKey)) { inspectDefaultItems = EditorPrefs.GetBool(InspectDefaultItemsKey); } if (EditorPrefs.HasKey(StyleKey)) { style = (InspectorStyle)EditorPrefs.GetInt(StyleKey); } if (EditorPrefs.HasKey(SeparatorKey)) { separator = (SeparatorStyle)EditorPrefs.GetInt(SeparatorKey); } if (EditorPrefs.HasKey(SeparatorDefaultKey)) { separatorDefaultColor = StringToColor(EditorPrefs.GetString(SeparatorDefaultKey)); } if (EditorPrefs.HasKey(SeparatorSelectedKey)) { separatorSelectedColor = StringToColor(EditorPrefs.GetString(SeparatorSelectedKey)); } if (EditorPrefs.HasKey(BoxDefaultKey)) { boxDefaultColor = StringToColor(EditorPrefs.GetString(BoxDefaultKey)); } if (EditorPrefs.HasKey(BoxPlayKey)) { boxPlayColor = StringToColor(EditorPrefs.GetString(BoxPlayKey)); } if (EditorPrefs.HasKey(IndentationKey)) { extraIndentation = EditorPrefs.GetInt(IndentationKey); } if (EditorPrefs.HasKey(LargeCollectionKey)) { largeCollection = EditorPrefs.GetInt(LargeCollectionKey); } if (EditorPrefs.HasKey(ValueScrollKey)) { valueScroll = (InspectorDragControl)EditorPrefs.GetInt(ValueScrollKey); } if (EditorPrefs.HasKey(CopyPasteKey)) { copyPaste = (InspectorDragControl)EditorPrefs.GetInt(CopyPasteKey); } if (EditorPrefs.HasKey(MassExpandKey)) { massExpand = (InspectorModifierControl)EditorPrefs.GetInt(MassExpandKey); } if (EditorPrefs.HasKey(ContextualKey)) { contextual = (InspectorModifierControl)EditorPrefs.GetInt(ContextualKey); } if (EditorPrefs.HasKey(ExpandableReferencesKey)) { expandableReferences = EditorPrefs.GetBool(ExpandableReferencesKey); } if (EditorPrefs.HasKey(CollectionItemNamingKey)) { collectionItemNaming = (InspectorCollectionItemNaming)EditorPrefs.GetInt(CollectionItemNamingKey); } GetAllEditor(); }
public static object GenericField( string name, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true) { if (t == null) { return(value); } Init(); if (fieldInfo != null) { //检查是否有字段解析支持 InspectorStyle inspectorStyle = fieldInfo.GetAttribute <InspectorStyle>(); FieldInspectorParser parser = null; if (inspectorStyle != null) { name = inspectorStyle.Name; if (inspectorStyle.ParserName != null) { inspectorFieldParsers.TryGetValue(inspectorStyle.ParserName, out parser); } } if (parser != null) { return(parser.ParserFiled(inspectorStyle, value, t, fieldInfo, instance, withName)); } } //检查是否有默认类型解析 if (inspectorTypeParsers.ContainsKey(t)) { return(inspectorTypeParsers[t].Show(name, value, t, fieldInfo, instance, withName)); } //默认显示 if (t == typeof(string)) { if (withName) { return(EditorGUILayout.TextField(name, (string)value)); } return(EditorGUILayout.TextField((string)value)); } if (t == typeof(bool)) { if (withName) { return(EditorGUILayout.Toggle(name, (bool)value)); } return(EditorGUILayout.Toggle((bool)value)); } if (t == typeof(int)) { if (withName) { return(EditorGUILayout.IntField(name, (int)value)); } return(EditorGUILayout.IntField((int)value)); } if (t == typeof(uint)) { if (withName) { return((uint)EditorGUILayout.IntField(name, Convert.ToInt32((uint)value))); } return((uint)EditorGUILayout.IntField(Convert.ToInt32((uint)value))); } if (t == typeof(float)) { if (withName) { return(EditorGUILayout.FloatField(name, (float)value)); } return(EditorGUILayout.FloatField((float)value)); } if (t == typeof(Vector2)) { if (withName) { return(EditorGUILayout.Vector2Field(name, (Vector2)value)); } return(EditorGUILayout.Vector2Field("", (Vector2)value)); } if (t == typeof(Vector3)) { if (withName) { return(EditorGUILayout.Vector3Field(name, (Vector3)value)); } return(EditorGUILayout.Vector3Field("", (Vector3)value)); } if (t == typeof(Vector4)) { if (withName) { return(EditorGUILayout.Vector4Field(name, (Vector4)value)); } return(EditorGUILayout.Vector4Field("", (Vector4)value)); } if (t == typeof(Quaternion)) { var quat = (Quaternion)value; var vec4 = new Vector4(quat.x, quat.y, quat.z, quat.w); if (withName) { vec4 = EditorGUILayout.Vector4Field(name, vec4); } else { vec4 = EditorGUILayout.Vector4Field("", vec4); } return(new Quaternion(vec4.x, vec4.y, vec4.z, vec4.w)); } if (t == typeof(Color)) { if (withName) { return(EditorGUILayout.ColorField(name, (Color)value)); } return(EditorGUILayout.ColorField((Color)value)); } if (t == typeof(Rect)) { if (withName) { return(EditorGUILayout.RectField(name, (Rect)value)); } return(EditorGUILayout.RectField((Rect)value)); } if (t == typeof(AnimationCurve)) { if (withName) { return(EditorGUILayout.CurveField(name, (AnimationCurve)value)); } return(EditorGUILayout.CurveField((AnimationCurve)value)); } if (t == typeof(Bounds)) { if (withName) { return(EditorGUILayout.BoundsField(name, (Bounds)value)); } return(EditorGUILayout.BoundsField((Bounds)value)); } if (typeof(IList).IsAssignableFrom(t)) { return(ListEditor(name, (IList)value, t)); } if (t.IsSubclassOf(typeof(System.Enum))) { bool hasAttribute = t.HasAttribute <FlagsAttribute>(); if (hasAttribute) { if (withName) { GUILayout.BeginHorizontal(); GUILayout.Label(name, GUILayout.Width(150)); FlagsEnumEditor(value, fieldInfo, instance); GUILayout.EndHorizontal(); } else { FlagsEnumEditor(value, fieldInfo, instance); } return(fieldInfo.GetValue(instance)); } else { if (withName) { return(EditorGUILayout.EnumPopup(name, (System.Enum)value)); } return(EditorGUILayout.EnumPopup((System.Enum)value)); } } if (typeof(UnityEngine.Object).IsAssignableFrom(t)) { if (withName) { return(EditorGUILayout.ObjectField(name, (UnityEngine.Object)value, t, true)); } return(EditorGUILayout.ObjectField((UnityEngine.Object)value, t, true)); } if (value == null) { try { value = ReflecTool.Instantiate(fieldInfo.FieldType); fieldInfo.SetValue(instance, value); } catch (Exception e) { // ignored } } if (value != null) { GUILayout.BeginVertical(); if (withName) { GUILayout.Label(name); } GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); ShowObject(value); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } return(value); }
public override object ParserFiled( InspectorStyle style, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true) { string[] imgFolderPaths = new string[style.ParserAgrs.Length]; for (int i = 0; i < style.ParserAgrs.Length; i++) { var parserAgr = style.ParserAgrs[i]; imgFolderPaths[i] = parserAgr as string; } string currName = value as string ?? ""; Texture2D currTexture2D = null; try { var databasePath = this.FieldValueToAssetDatabasePath(currName); currTexture2D = AssetDatabase.LoadAssetAtPath <Texture2D>(String.Format("{0}.png", databasePath)); if (currTexture2D == null) { currTexture2D = AssetDatabase.LoadAssetAtPath <Texture2D>(String.Format("{0}.jpg", databasePath)); } } catch (Exception) { } GUILayout.BeginHorizontal(); if (withName) { GUILayout.Label(style.Name, GUILayout.Width(145)); } bool open = false; int width = 25, height = 25; if (currTexture2D == null) { open = GUILayout.Button("选择图片"); } else { if (currTexture2D.width > currTexture2D.height) { width = 100; height = currTexture2D.height / (currTexture2D.width / 100); } else { height = 100; width = currTexture2D.width / (currTexture2D.height / 100); } open = GUILayout.Button(new GUIContent(currTexture2D), GUILayout.Width(width), GUILayout.Height(height)); } if (open) { OpenSelectWindow(fieldInfo, instance, imgFolderPaths); } GUILayout.BeginVertical(); GUILayout.Space(height - 20); currName = EditorGUILayout.TextField(currName); GUILayout.EndVertical(); GUILayout.EndHorizontal(); return(currName); }