public void AddView(string code) { Callback <GameObject, int> callback = null; EEntityType entityType = EntityUtil.GetEntityTypeByCode(code); if (entityType == EEntityType.Hero || entityType == EEntityType.Boss ) { callback = SpriteManager.GetInstance().GetOrNewSprite(code, true); } else { int maxCount = 50; callback = SpriteManager.GetInstance().GetOrNewSprite(code, true, maxCount); } callback?.onSuccess.Set((showGO) => { if (showGO != null) { showGOs = showGOs ?? new List <GameObject>(); showGOs.Add(showGO); showGO.transform.SetParent(body.transform, false); rendererCom.Add(showGO); colliderCom.Add(showGO); animatorCom.Add(showGO); shaderEffectCom.Add(showGO); } }); }
protected void AddCommonComponent(GameEntity entity, string code) { //用这个法子创建的组件是复用原有的,因此必须手动初始化下 var transCom = entity.CreateComponent <TransformComponent>(GameComponentsLookup.Transform); var colliderCom = entity.CreateComponent <ColliderComponent>(GameComponentsLookup.Collider); var movementCom = entity.CreateComponent <MovementComponent>(GameComponentsLookup.Movement); var viewCom = entity.CreateComponent <ViewComponent>(GameComponentsLookup.View); var destroyCom = entity.CreateComponent <DestroyedComponent>(GameComponentsLookup.Destroyed); EEntityType type = EntityUtil.GetEntityTypeByCode(code); CSVObject infos = EntityConfiger.GetEntityInfo(code); if (infos != null) { var entityDataCom = entity.CreateComponent <EntityDataComponent>(GameComponentsLookup.EntityData); entityDataCom.entityCode = code; entityDataCom.entityType = type; entityDataCom.entityData = infos; entity.AddComponent(GameComponentsLookup.EntityData, entityDataCom); } //// entity.AddComponent(GameComponentsLookup.Transform, transCom); entity.AddComponent(GameComponentsLookup.Collider, colliderCom); entity.AddComponent(GameComponentsLookup.Movement, movementCom); entity.AddComponent(GameComponentsLookup.View, viewCom); entity.AddComponent(GameComponentsLookup.Destroyed, destroyCom); }
public GameEntity CreateEntity(string code) { EEntityType entityType = EntityUtil.GetEntityTypeByCode(code); BaseEntityFactory factory = GetOrNewEntityFactory(entityType); if (factory != null) { return(factory.CreateEntity(code)); } return(null); }
public Callback <GameObject, int> GetOrNewSprite(string viewCode, bool usePool = false, int maxCount = 20) { string viewName = null; GameObject prefabInstance = null; var callback = Callback <GameObject, int> .GetOrNew(); if (!usePool) { EEntityType entityType = EntityUtil.GetEntityTypeByCode(viewCode); if (poolInfos.TryGetValue(entityType, out var poolInfo)) { usePool = true; maxCount = poolInfo.maxCount; } } if (usePool) { if (!GameObjectPoolManager.GetInstance().HasPool(viewCode)) { AssetManager.GetInstance().LoadSprite(viewCode).onSuccess.Set((prefab) => { GameObjectPoolManager.GetInstance().NewPool(viewCode, prefab, maxCount); prefabInstance = GameObjectPoolManager.GetInstance().GetOrCreateGameObject(viewCode); GameObject viewGO = new GameObject(viewName); prefabInstance.transform.SetParent(viewGO.transform, false); callback.onSuccess?.Invoke(prefabInstance); }); } else { prefabInstance = GameObjectPoolManager.GetInstance().GetOrCreateGameObject(viewCode); GameObject viewGO = new GameObject(viewName); prefabInstance.transform.SetParent(viewGO.transform, false); callback.onSuccess?.Invoke(prefabInstance); } } else { AssetManager.GetInstance().LoadSprite(viewCode).onSuccess.Set((prefab) => { if (prefab) { prefabInstance = Object.Instantiate(prefab); callback.onSuccess?.Invoke(prefabInstance); } }); } return(callback); }
public static CSVObject GetEntityInfo(string code) { //按类型区分 EEntityType entityType = EntityUtil.GetEntityTypeByCode(code); CSVObject obj = null; switch (entityType) { case EEntityType.Hero: obj = GetRoleInfo(code); break; case EEntityType.Wingman: obj = GetWingmanInfo(code); break; case EEntityType.Mob: for (int i = 0; i < 2; i++) { code = ReplaceChar(code, code.Length - i, '0'); obj = GetMobInfo(code); if (obj != null) { break; } } break; case EEntityType.Boss: obj = GetBossInfo(code); break; case EEntityType.Bullet: { for (int i = 0; i < 2; i++) { code = ReplaceChar(code, code.Length - i, '0'); obj = GetBulletInfo(code); if (obj != null) { break; } } } break; } return(obj); }