Exemplo n.º 1
0
        ///<summary>
        ///</summary>
        ///<param name="component"></param>
        ///<param name="attribute"></param>
        ///<returns></returns>
        ///<exception cref="Exception"></exception>
        public static StyleableProxy CreateProxy(object component, StyleableAttribute attribute)
        {
            StyleableProxy proxy = new StyleableProxy
            {
                _mode = attribute.Mode,
                _classnameProperty = attribute.ClassnameProperty,
                _idProperty        = attribute.IdProperty
            };

            Type readerType = attribute.Reader;

            if (null == readerType)
            {
                // default reader (for MonoBehavour)
                readerType = typeof(HierarchyReader);
                //throw new Exception("No reader found");
            }

            Debug.Log("readerType: " + readerType);
            IStyleReader reader = (IStyleReader)Activator.CreateInstance(readerType);

            proxy._readIdMethod        = reader.GetId;
            proxy._readClassnameMethod = reader.GetClassname;

            Type type = component.GetType();

            //Debug.Log("type: " + type);

            //try
            //{
            //    //if (!string.IsNullOrEmpty(attribute.ReadIdMethod))
            //    //var reader = Activator.CreateInstance(readerType);
            //    //Debug.Log("attribute.ReadIdMethod: " + attribute.ReadIdMethod);

            //    proxy._getIdMethod = readerType.GetMethod(attribute.ReadIdMethod); // GetMethodInfo(component, attribute.ReadIdMethod);

            //    //Debug.Log("!!!");
            //}
            //catch (Exception ex)
            //{
            //    throw new Exception(string.Format("Couldn't get the method specified with ID [{0}]: ", attribute.ReadIdMethod), ex);
            //}


            //if (!string.IsNullOrEmpty(attribute.ReadClassnameMethod))
            //{
            //    try
            //    {
            //        //Debug.Log("attribute.ReadClassnameMethod: " + attribute.ReadClassnameMethod);
            //        //Debug.Log("type: " + type);

            //        proxy._getClassnameMethod = readerType.GetMethod(attribute.ReadClassnameMethod); // GetMethodInfo(component, attribute.ReadClassnameMethod);

            //        //Debug.Log("!!!");
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(string.Format("Couldn't get the method specified with ReadClassnameMethod [{0}]: ", attribute.ReadClassnameMethod), ex);
            //    }
            //}

            if (proxy._mode == StyleableProxyMode.SendMessage)
            {
                if (!(component is MonoBehaviour))
                {
                    throw new Exception("SendMessage mode could only be used with MonoBehaviour subclasses");
                }
                proxy._monoBehaviour = (MonoBehaviour)component;
                return(proxy); // do not process anything via reflection; return
            }

            if (!string.IsNullOrEmpty(attribute.LoadMethod))
            {
                try
                {
                    proxy._loadStylesMethod = type.GetMethod(attribute.LoadMethod, new Type[] {}); //GetMethodInfo(component, attribute.LoadMethod);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Couldn't get the method specified with LoadMethod: [{0}]: ", attribute.LoadMethod), ex);
                }
            }

            //Debug.Log(3);
            //if (!string.IsNullOrEmpty(attribute.GetMethod))
            //{
            //    try
            //    {

            //        proxy._getStyleMethod = type.GetMethod(attribute.GetMethod, new[]{typeof(string)});
            //        //proxy._getStyleMethod = GetMethodInfo(component, attribute.GetMethod);
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(string.Format("Couldn't get the method specified with GetMethod: [{0}]: ", attribute.ReadClassnameMethod), ex);
            //    }
            //}

            //Debug.Log(4);
            //if (!string.IsNullOrEmpty(attribute.SetMethod))
            //{
            //    try
            //    {
            //        proxy._setStyleMethod = type.GetMethod(attribute.SetMethod, new[] { typeof(string), typeof(object) }); //GetMethodInfo(component, attribute.SetMethod);
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(string.Format("Couldn't get the method specified with SetMethod:  [{0}]: ", attribute.ReadClassnameMethod), ex);
            //    }
            //}
            //Debug.Log(5);
            if (!string.IsNullOrEmpty(attribute.ChangedMethod))
            {
                try
                {
                    proxy._styleChangedMethod = type.GetMethod(attribute.ChangedMethod, new[] { typeof(string), typeof(object) }); // GetMethodInfo(component, attribute.ChangedMethod);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Couldn't get the method specified with ChangedMethod:  [{0}]: ", attribute.ChangedMethod), ex);
                }
            }
            //Debug.Log(6);

            return(proxy);
        }
Exemplo n.º 2
0
        ///<summary>
        ///</summary>
        ///<param name="component"></param>
        ///<param name="attribute"></param>
        ///<returns></returns>
        ///<exception cref="Exception"></exception>
        public static StyleableProxy CreateProxy(object component, StyleableAttribute attribute)
        {
            StyleableProxy proxy = new StyleableProxy
                                       {
                                           _mode = attribute.Mode,
                                           _classnameProperty = attribute.ClassnameProperty,
                                           _idProperty = attribute.IdProperty
                                       };

            Type readerType = attribute.Reader;
            if (null == readerType)
            {
                // default reader (for MonoBehavour)
                readerType = typeof(HierarchyReader);
                //throw new Exception("No reader found");
            }

            Debug.Log("readerType: " + readerType);
            IStyleReader reader = (IStyleReader) Activator.CreateInstance(readerType);

            proxy._readIdMethod = reader.GetId;
            proxy._readClassnameMethod = reader.GetClassname;

            Type type = component.GetType();
            //Debug.Log("type: " + type);

            //try
            //{
            //    //if (!string.IsNullOrEmpty(attribute.ReadIdMethod))
            //    //var reader = Activator.CreateInstance(readerType);
            //    //Debug.Log("attribute.ReadIdMethod: " + attribute.ReadIdMethod);
                
            //    proxy._getIdMethod = readerType.GetMethod(attribute.ReadIdMethod); // GetMethodInfo(component, attribute.ReadIdMethod);

            //    //Debug.Log("!!!");
            //}
            //catch (Exception ex)
            //{
            //    throw new Exception(string.Format("Couldn't get the method specified with ID [{0}]: ", attribute.ReadIdMethod), ex);
            //}

            
            //if (!string.IsNullOrEmpty(attribute.ReadClassnameMethod))
            //{
            //    try
            //    {
            //        //Debug.Log("attribute.ReadClassnameMethod: " + attribute.ReadClassnameMethod);
            //        //Debug.Log("type: " + type);

            //        proxy._getClassnameMethod = readerType.GetMethod(attribute.ReadClassnameMethod); // GetMethodInfo(component, attribute.ReadClassnameMethod);

            //        //Debug.Log("!!!");
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(string.Format("Couldn't get the method specified with ReadClassnameMethod [{0}]: ", attribute.ReadClassnameMethod), ex);
            //    }
            //}

            if (proxy._mode == StyleableProxyMode.SendMessage)
            {
                if (!(component is MonoBehaviour))
                {
                    throw new Exception("SendMessage mode could only be used with MonoBehaviour subclasses");
                }
                proxy._monoBehaviour = (MonoBehaviour) component;
                return proxy; // do not process anything via reflection; return
            }

            if (!string.IsNullOrEmpty(attribute.LoadMethod))
            {
                try
                {
                    proxy._loadStylesMethod = type.GetMethod(attribute.LoadMethod, new Type[]{}); //GetMethodInfo(component, attribute.LoadMethod);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Couldn't get the method specified with LoadMethod: [{0}]: ", attribute.LoadMethod), ex);
                }
            }

            //Debug.Log(3);
            //if (!string.IsNullOrEmpty(attribute.GetMethod))
            //{
            //    try
            //    {
                    
            //        proxy._getStyleMethod = type.GetMethod(attribute.GetMethod, new[]{typeof(string)});
            //        //proxy._getStyleMethod = GetMethodInfo(component, attribute.GetMethod);
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(string.Format("Couldn't get the method specified with GetMethod: [{0}]: ", attribute.ReadClassnameMethod), ex);
            //    }
            //}

            //Debug.Log(4);
            //if (!string.IsNullOrEmpty(attribute.SetMethod))
            //{
            //    try
            //    {
            //        proxy._setStyleMethod = type.GetMethod(attribute.SetMethod, new[] { typeof(string), typeof(object) }); //GetMethodInfo(component, attribute.SetMethod);
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(string.Format("Couldn't get the method specified with SetMethod:  [{0}]: ", attribute.ReadClassnameMethod), ex);
            //    }
            //}
            //Debug.Log(5);
            if (!string.IsNullOrEmpty(attribute.ChangedMethod))
            {
                try
                {
                    proxy._styleChangedMethod = type.GetMethod(attribute.ChangedMethod, new[] { typeof(string), typeof(object) }); // GetMethodInfo(component, attribute.ChangedMethod);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Couldn't get the method specified with ChangedMethod:  [{0}]: ", attribute.ChangedMethod), ex);
                }
            }
            //Debug.Log(6);

            return proxy;
        }