protected virtual void OnEnable() { var targetObject = serializedObject.targetObject; var hasAttributeHeader = targetObject.GetType().IsDefined(typeof(ClassHeaderAttribute), true); if (hasAttributeHeader) { var attributes = Attribute.GetCustomAttributes(targetObject.GetType(), typeof(ClassHeaderAttribute), true); if (attributes.Length > 0) { headerAttribute = (ClassHeaderAttribute)attributes[0]; } } // skin = Resources.Load("skin") as GUISkin; // m_Logo = Resources.Load("icon_v2") as Texture2D; if (headerAttribute != null && ((MonoBehaviour)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; } }
protected virtual void OnEnable() { var targetObject = serializedObject.targetObject; var hasAttributeHeader = targetObject.GetType().IsDefined(typeof(ClassHeaderAttribute), true); if (hasAttributeHeader) { var attributes = Attribute.GetCustomAttributes(targetObject.GetType(), typeof(ClassHeaderAttribute), true); if (attributes.Length > 0) { headerAttribute = (ClassHeaderAttribute)attributes[0]; } } skin = Resources.Load("skin") as GUISkin; m_Logo = Resources.Load("icon") as Texture2D; var prop = serializedObject.GetIterator(); if (((mMonoBehaviour)target) != null) { const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; List <string> events = new List <string>(); toolbars = new List <ToolBar>(); var toolbar = new ToolBar(); toolbar.title = "Default"; toolbars.Add(toolbar); var index = 0; bool needReorder = false; int oldOrder = 0; while (prop.NextVisible(true)) { var fieldInfo = targetObject.GetType().GetField(prop.name, flags); if (fieldInfo != null) { var toolBarAttributes = fieldInfo.GetCustomAttributes(typeof(EditorToolbarAttribute), true); if (toolBarAttributes.Length > 0) { var attribute = toolBarAttributes[0] as EditorToolbarAttribute; var _toolbar = toolbars.Find(tool => tool != null && tool.title == attribute.title); if (_toolbar == null) { toolbar = new ToolBar(); toolbar.title = attribute.title; toolbar.useIcon = attribute.useIcon; toolbar.iconName = attribute.icon; toolbars.Add(toolbar); toolbar.order = attribute.order; if (oldOrder < attribute.order) { needReorder = true; } index = toolbars.Count - 1; } else { index = toolbars.IndexOf(_toolbar); if (index < toolbars.Count) { if (attribute.overrideChildOrder) { if (oldOrder < attribute.order) { needReorder = true; } toolbars[index].order = attribute.order; } if (attribute.overrideIcon) { toolbars[index].useIcon = true; toolbars[index].iconName = attribute.icon; } } } } if (index < toolbars.Count) { toolbars[index].variables.Add(prop.name); } if ((EditorHelper.IsUnityEventyType(fieldInfo.FieldType) && !events.Contains(fieldInfo.Name))) { events.Add(fieldInfo.Name); } } } if (needReorder) { toolbars.Sort((a, b) => a.order.CompareTo(b.order)); } 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); } }