Exemplo n.º 1
0
 public void     Uninit()
 {
     if (this.sectionName != null)
     {
         NGSettingsWindow.RemoveSection(this.sectionName);
     }
 }
Exemplo n.º 2
0
        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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 public void     Uninit()
 {
     NGSettingsWindow.RemoveSection(this.sectionTitle);
 }