/// <summary>
        /// Initializes the Singleton instance
        /// </summary>
        private void Initialize()
        {
            _adapters = new Dictionary <Type, StyleClientAdapterBase>();

            var adapters = GuiReflector.GetAllLoadedTypesDecoratedWith(typeof(StyleClientAdapterAttribute));

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format(@"Found {0} adapters", adapters.Count));
            }
#endif
            foreach (var adapter in adapters)
            {
                if (!(typeof(StyleClientAdapterBase).IsAssignableFrom(adapter)))
                {
                    throw new Exception(string.Format("{0} is not StyleClientAdapterBase", adapter));
                }

                var attributes = CoreReflector.GetClassAttributes <StyleClientAdapterAttribute>(adapter);
                var client     = (StyleClientAdapterBase)Activator.CreateInstance(adapter);
                _adapters[attributes[0].Type] = client;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format(@"Retrieved {0} style client adapters:
{1}", _adapters.Count, DictionaryUtil <Type, StyleClientAdapterBase> .Format(_adapters)));
            }
#endif
        }
Beispiel #2
0
        /*public static List<EventAttribute> GetEvents(Type componentType)
         * {
         *  object[] list = componentType.GetCustomAttributes(typeof(EventAttribute), true);
         *  var events = new List<EventAttribute>();
         *  foreach (var e in list)
         *  {
         *      events.Add((EventAttribute) e);
         *  }
         *  return events;
         * }*/

        private static void GetEventsRecursive(ComponentAdapter clickedAdapter, ComponentAdapter currentAdapter, ref Dictionary <string, EventAttribute> dict, bool bubbling, ICollection <ComponentAdapter> adaptersToExclude)
        {
            Type componentType = currentAdapter.ComponentType;

            if (null == adaptersToExclude || !adaptersToExclude.Contains(currentAdapter))
            {
                //object[] list = componentType.GetCustomAttributes(typeof (EventAttribute), true);
                var eventAttributes = CoreReflector.GetClassAttributes <EventAttribute>(componentType);

                foreach (EventAttribute attribute in eventAttributes)
                {
                    if (clickedAdapter == currentAdapter)
                    {
                        /**
                         * 1. If this is a clicked adapter, get all events
                         * */
                        dict[attribute.Name] = attribute;
                    }
                    else if (bubbling && attribute.Bubbles) // if (bubbling)
                    {
                        /**
                         * 2. Else get only events that may bubble from children
                         * */
                        dict[attribute.Name] = attribute;
                    }

                    /*if (!bubbling || attribute.Bubbles) // if (bubbling)
                     * {
                     *  // bubbling events only
                     *  if (attribute.Bubbles)
                     *      dict[attribute.Name] = attribute;
                     * }
                     * else
                     * {
                     *  // target events only
                     *  dict[attribute.Name] = attribute;
                     * }*/
                    //Debug.Log(" --> " + attribute.Name);
                }
            }

            if (bubbling)
            {
                Transform transform  = currentAdapter.transform;
                var       childCount = transform.childCount;
                for (int i = 0; i < childCount; i++)
                {
                    var childTransform            = transform.GetChild(i);
                    ComponentAdapter childAdapter = GuiLookup.GetAdapter(childTransform);
                    GetEventsRecursive(clickedAdapter, childAdapter, ref dict, true, adaptersToExclude);
                }
            }
        }
Beispiel #3
0
        public static Type GetHostComponent(Type skinType)
        {
            var hostComponentAttributes = CoreReflector.GetClassAttributes <HostComponentAttribute>(skinType);

            //Debug.Log("hostComponentAttributes.Length: " + hostComponentAttributes.Length);

            if (hostComponentAttributes.Count > 0)
            {
                var attr = hostComponentAttributes[0];
                return(attr.Type);
            }
            return(null);
        }
        /// <summary>
        /// Describes component events
        /// </summary>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public static string GetEvents(Type componentType)
        {
            //var events = ReflectionUtil.GetEvents(componentType);
            var events = CoreReflector.GetClassAttributes <EventAttribute>(componentType);

            events.Sort(EventSort);

            StringBuilder sb = new StringBuilder();

            foreach (var eventAttribute in events)
            {
                sb.AppendLine(eventAttribute.ToString());
            }

            return(string.Format(@"Events ({0}):
{1}
{2}", events.Count, Line, sb) + NewLine /* + NewLine*/);
        }
Beispiel #5
0
        /// <summary>
        /// Gets all style properties
        /// </summary>
        /// <param name="type"></param>
        /// <param name="restrictToInspectableTypes"></param>
        public static List <StyleAttribute> GetStyleAttributes(Type type)
        {
            if (StyleAttributeCache.ContainsKey(type))
            {
                return(StyleAttributeCache[type]);
            }

            var styleAttributes = CoreReflector.GetClassAttributes <StyleAttribute>(type);

            List <StyleAttribute> attributes = new List <StyleAttribute>();

            foreach (StyleAttribute attribute in styleAttributes)
            {
                /* with "skinClass" style, the Type isn't required. Set it here */

                /*if (attribute.Name == "skinClass" && null == attribute.Type)
                 *  attribute.Type = typeof(object);*/

                if (/*!restrictToInspectableTypes || */ (attribute.Name == "skinClass" || null != attribute.Type /* && StyleProperty.AlowedTypes.ContainsKey(attribute.Type)*/))
                {
                    /**
                     * Important: Avoid duplication
                     * Subclass attributes are being added before the superclass attributes, so we're fine
                     * */
                    var name = attribute.Name;

                    if (!attributes.Exists(delegate(StyleAttribute a)
                    {
                        return(a.Name == name);
                    }))
                    {
                        attributes.Add(attribute);
                    }
                    else
                    {
                        //Debug.Log(type + " has duplicated attribute: " + name + ": " + attribute.GetDefault());
                    }
                }
            }

            StyleAttributeCache[type] = attributes;

            return(attributes);
        }
Beispiel #6
0
        public void ReflectAttribute()
        {
            var attributes = CoreReflector.GetClassAttributes <StyleModuleAttribute>(GetType());

            if (attributes.Count == 0)
            {
                throw new Exception("Style module must be decorated with StyleModuleAttribute");
            }

            StyleModuleAttribute attribute = attributes[0];

            Id                     = attribute.Id;
            Description            = attribute.Description;
            Icon                   = attribute.Icon;
            AllowMultipleClients   = attribute.AllowMultipleClients;
            AllowSubjectOmmision   = attribute.AllowSubjectOmmision;
            ProcessEditModeChanges = attribute.ProcessEditModeChanges;
            ProcessPlayModeChanges = attribute.ProcessPlayModeChanges;
        }