Example #1
0
        private static AttributeMethod[] GetAttributeMethods()
        {
            List <AttributeMethod> response = new List <AttributeMethod>();

            MonoBehaviour[] sceneActive = GameObject.FindObjectsOfType <MonoBehaviour>();

            foreach (MonoBehaviour mono in sceneActive)
            {
                Type monoType = mono.GetType();

                // Retreive the fields from the mono instance
                MethodInfo[] methodFields = monoType.GetMethods(BindingFlags.Instance | BindingFlags.Public);

                // search all fields and find the attribute [Position]
                for (int i = 0; i < methodFields.Length; i++)
                {
                    Networked attribute = Attribute.GetCustomAttribute(methodFields[i], typeof(Networked)) as Networked;

                    // if we detect any attribute
                    if (attribute != null)
                    {
                        AttributeMethod newAttributeMethod = new AttributeMethod(methodFields[i], attribute, mono);
                        response.Add(newAttributeMethod);
                        attribute.SetAttributeMethod(newAttributeMethod);
                    }
                }
            }

            return(response.ToArray());
        }
Example #2
0
 public AttributeMethod(MethodInfo method, Networked attribute, object classInstance)
 {
     this.method        = method;
     this.attribute     = attribute;
     this.classInstance = classInstance;
 }