Exemplo n.º 1
0
        internal void _initModule(GameObject go, IShareableModule module)
        {
            var wrapper = go.GetComponent <WrapperEudiEntity>();

            wrapper.Instance._updateMap();

            // Key is Map, Value is Entity
            foreach (var mapEntities in MapManager.AllMaps)
            {
                if (!_isValidForMapping(go, mapEntities.Key))
                {
                    continue;
                }

                var entitiesList = mapEntities.Value;
                if (!entitiesList.Contains(wrapper.Instance))
                {
                    entitiesList.Add(wrapper.Instance);

                    var obj = mapEntities.Key.GetAssignedObject(typeof(TransformAccessArray));
                    if (obj != null)
                    {
                        var castedObj = (TransformAccessArray)obj;
                        castedObj.Capacity += 1;
                        castedObj.Add(go.transform);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public ModuleType SetModule <ModuleType>(ModuleType instance)
            where ModuleType : IShareableModule
        {
            var type         = typeof(ModuleType);
            var instanceType = instance.GetType();

            if (type != instanceType)
            {
                Debug.LogError("ERROR");
                return(instance);
            }

            if (instance is MonoBehaviour)
            {
                var instancedBehaviour = (MonoBehaviour)(object)instance;
                if (instancedBehaviour.gameObject != Wrapper.gameObject)
                {
                    throw new Exception("Adding a module from another gameobject, this is not accepted.");
                }
            }

            // first, check if we have a module of same type
            IShareableModule moduleToRemove = default(IShareableModule);
            var hadExistingModule           = false;

            foreach (var module in SharedModules)
            {
                if (module.GetType() == type)
                {
                    moduleToRemove    = module;
                    hadExistingModule = true;
                }
            }

            if (hadExistingModule)
            {
                _removeModuleButReplaceIt(moduleToRemove);
            }

            _addModule(instance);

            return(instance);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Will remove the module from the list but replace it into the tuples maps
 /// </summary>
 /// <param name="instance"></param>
 private void _removeModuleButReplaceIt(IShareableModule oldInstance)
 {
     SharedModules.Remove(oldInstance);
 }
Exemplo n.º 4
0
 internal void _addModule(IShareableModule instance)
 {
     SharedModules.Add(instance);
     Eudi.EntitiesManager._initModule(Wrapper.gameObject, instance);
 }