public void Uninit() { if (this.sectionName != null) { NGSettingsWindow.RemoveSection(this.sectionName); } }
static NGSettingsWindow() { foreach (Type type in Utility.EachNGTSubClassesOf(typeof(object))) { if (typeof(ScriptableObject).IsAssignableFrom(type) == true) { NGSettingsAttribute[] attributes = type.GetCustomAttributes(typeof(NGSettingsAttribute), false) as NGSettingsAttribute[]; if (attributes.Length > 0) { new SectionDrawer(attributes[0].label, type, attributes[0].priority); } } MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static); for (int i = 0; i < methods.Length; i++) { if (methods[i].IsDefined(typeof(NGSettingsAttribute), false) == true) { NGSettingsAttribute[] attributes = methods[i].GetCustomAttributes(typeof(NGSettingsAttribute), false) as NGSettingsAttribute[]; NGSettingsWindow.AddSection(attributes[0].label, Delegate.CreateDelegate(typeof(Action), methods[i]) as Action, attributes[0].priority); } } } }
/// <summary> /// Initializes a Section and adds it into NGSettings. /// </summary> /// <param name="sectionName">Defines the name of the section.</param> /// <param name="typeSetting">The Type of your class inside NGSettings.</param> /// <param name="priority">The lower the nearest to the top.</param> public SectionDrawer(string sectionName, Type typeSetting, int priority = -1) { this.sectionName = sectionName; this.typeSetting = typeSetting; if (this.typeSetting.IsSubclassOf(typeof(ScriptableObject)) == false) { FieldInfo[] fields = typeof(NGSettings).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < fields.Length; i++) { if (fields[i].FieldType == typeSetting) { this.fieldInfo = fields[i]; break; } } InternalNGDebug.Assert(this.fieldInfo != null, "Field of type \"" + typeSetting + "\" does not exist in class \"" + typeof(NGSettings) + "\"."); } if (this.sectionName != null) { NGSettingsWindow.AddSection(this.sectionName, this.OnGUI, priority); } }
/// <summary> /// Adds a new section in ConsoleSettings with an inspector displaying all public non-static fields from type T. /// </summary> /// <param name="sectionTitle">Title of the section.</param> /// <param name="assetPath">Location in the project to save and load the instance.</param> /// <param name="exposedFields">List of public non-static fields to expose.</param> public AutoExposeSettings(string sectionTitle, string assetPath, string[] exposedFields) { this.sectionTitle = sectionTitle; this.instance = AssetDatabase.LoadAssetAtPath <T>(assetPath); if (this.instance == null) { this.instance = ScriptableObject.CreateInstance <T>(); AssetDatabase.CreateAsset(this.instance, assetPath); AssetDatabase.SaveAssets(); } this.GUIInitializer = this.instance as IGUIInitializer; this.serializedObject = new SerializedObject(this.instance); this.serializedProperties = new SerializedProperty[exposedFields.Length]; for (int i = 0; i < exposedFields.Length; i++) { this.serializedProperties[i] = this.serializedObject.FindProperty(exposedFields[i]); InternalNGDebug.Assert(this.serializedProperties[i] != null, "Field \"" + exposedFields[i] + "\" was not found in type " + typeof(T).FullName + ".", this.instance); } NGSettingsWindow.AddSection(sectionTitle, this.OnGUI); }
public void Uninit() { NGSettingsWindow.RemoveSection(this.sectionTitle); }