Example #1
0
    protected virtual void OnEnable()
    {
        var targetObject       = serializedObject.targetObject;
        var hasAttributeHeader = targetObject.GetType().IsDefined(typeof(vClassHeaderAttribute), true);

        if (hasAttributeHeader)
        {
            var attributes = Attribute.GetCustomAttributes(targetObject.GetType(), typeof(vClassHeaderAttribute), true);
            if (attributes.Length > 0)
            {
                headerAttribute = (vClassHeaderAttribute)attributes[0];
            }
        }

        skin   = Resources.Load("skin") as GUISkin;
        m_Logo = Resources.Load("icon_v2") as Texture2D;
        if (headerAttribute != null && ((vMonoBehaviour)target) != null)
        {
            const BindingFlags flags  = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
            FieldInfo[]        fields = targetObject.GetType().GetFields(flags);
            List <string>      events = new List <string>();
            foreach (FieldInfo fieldInfo in fields)
            {
                if (vEditorHelper.IsUnityEventyType(fieldInfo.FieldType) && !events.Contains(fieldInfo.Name))
                {
                    events.Add(fieldInfo.Name);
                }
            }
            PropertyInfo[] properties = serializedObject.GetType().GetProperties(flags);
            foreach (PropertyInfo propertyInfo in properties)
            {
                if (vEditorHelper.IsUnityEventyType(propertyInfo.PropertyType) && !events.Contains(propertyInfo.Name))
                {
                    events.Add(propertyInfo.Name);
                }
            }
            ignoreEvents = events.vToArray();
            m_Logo       = Resources.Load(headerAttribute.iconName) as Texture2D;
        }
    }
Example #2
0
    protected virtual void OnEnable()
    {
        var targetObject       = serializedObject.targetObject;
        var hasAttributeHeader = targetObject.GetType().IsDefined(typeof(vClassHeaderAttribute), true);

        if (hasAttributeHeader)
        {
            var attributes = Attribute.GetCustomAttributes(targetObject.GetType(), typeof(vClassHeaderAttribute), true);
            if (attributes.Length > 0)
            {
                headerAttribute = (vClassHeaderAttribute)attributes[0];
            }
        }

        skin   = Resources.Load("skin") as GUISkin;
        m_Logo = Resources.Load("icon_v2") as Texture2D;
        var prop = serializedObject.GetIterator();

        if (((vMonoBehaviour)target) != null)
        {
            const BindingFlags flags  = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
            List <string>      events = new List <string>();

            toolbars = new List <vToolBar>();
            var toolbar = new vToolBar();
            toolbar.title = "Default";
            toolbars.Add(toolbar);
            var index = 0;

            while (prop.NextVisible(true))
            {
                var fieldInfo = targetObject.GetType().GetField(prop.name, flags);
                if (fieldInfo != null)
                {
                    var toolBarAttributes = fieldInfo.GetCustomAttributes(typeof(vEditorToolbarAttribute), true);

                    if (toolBarAttributes.Length > 0)
                    {
                        var attribute = toolBarAttributes[0] as vEditorToolbarAttribute;
                        var _toolbar  = toolbars.Find(tool => tool != null && tool.title == attribute.title);

                        if (_toolbar == null)
                        {
                            toolbar       = new vToolBar();
                            toolbar.title = attribute.title;
                            toolbars.Add(toolbar);
                            index = toolbars.Count - 1;
                        }
                        else
                        {
                            index = toolbars.IndexOf(_toolbar);
                        }
                    }
                    if (index < toolbars.Count)
                    {
                        toolbars[index].variables.Add(prop.name);
                    }
                    if ((vEditorHelper.IsUnityEventyType(fieldInfo.FieldType) && !events.Contains(fieldInfo.Name)))
                    {
                        events.Add(fieldInfo.Name);
                    }
                }
            }

            var nullToolBar = toolbars.FindAll(tool => tool != null && (tool.variables == null || tool.variables.Count == 0));
            for (int i = 0; i < nullToolBar.Count; i++)
            {
                if (toolbars.Contains(nullToolBar[i]))
                {
                    toolbars.Remove(nullToolBar[i]);
                }
            }

            ignoreEvents = events.vToArray();
            if (headerAttribute != null)
            {
                m_Logo = Resources.Load(headerAttribute.iconName) as Texture2D;
            }
            //else headerAttribute = new vClassHeaderAttribute(target.GetType().Name);
        }
    }