Exemplo n.º 1
0
    private List <ComponentType> LoadFromAssembly(Assembly assembly)
    {
        var         componentTypes = new List <ComponentType>();
        List <Type> types          = new List <Type>(assembly.GetTypes());

        types.Sort((x, y) => x.Name.CompareTo(y.Name));
        foreach (Type type in types)
        {
            if (type.GetCustomAttribute <NetSyncAttribute>() != null)
            {
                componentTypes.Add(type);
                ExtractNetworkMemberInfos(type);
            }
            else
            {
                ProxyNetSyncAttribute proxyNetSyncAttribute = type.GetCustomAttribute <ProxyNetSyncAttribute>();
                if (proxyNetSyncAttribute != null)
                {
                    componentTypes.Add(proxyNetSyncAttribute.Type);
                    ExtractNetworkMemberInfosFromProxy(type, proxyNetSyncAttribute.Type);
                }
            }

            if (type.GetCustomAttribute <NetworkEntityFactoryAttribute>() != null)
            {
                MethodInfo[] methodInfos = type.GetMethods().Where(methodInfo => methodInfo.IsDefined(typeof(NetworkEntityFactoryMethodAttribute), false)).ToArray();
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    NetworkInstantiationHandlerDelegate networkInstantiationHandlerDelegate = null;
                    try {
                        networkInstantiationHandlerDelegate = (NetworkInstantiationHandlerDelegate)Delegate.CreateDelegate(typeof(NetworkInstantiationHandlerDelegate), methodInfo);
                    } catch (Exception ex) {
                        throw new Exception(string.Format("Wrong signature for {0}. Signature requires static Entity {0}(EntityManager)", methodInfo.Name));
                    }
                    RegisterEntityFactoryMethod(methodInfo.GetCustomAttribute <NetworkEntityFactoryMethodAttribute>().InstanceId, networkInstantiationHandlerDelegate);
                }
            }
        }

        return(componentTypes);
        //NetworkFactoryMethods = networkFactoryMethods.ToArray();
    }
Exemplo n.º 2
0
 public void RegisterEntityFactoryMethod(int id, NetworkInstantiationHandlerDelegate networkInstantiationHandler)
 {
     entityFactoryMethodMap.Add(id, networkInstantiationHandler);
 }