示例#1
0
        public GameEntity CreateGridObject(string objectId)
        {
            var entity     = Contexts.sharedInstance.game.CreateEntity();
            var objectData = database.Get <GridObjectData>(objectId);
            var prefabPath = database.Get <string>(objectData.prefab);

            entity.AddGameObject(objectData.objectId, objectData.typeId, Utils.GenerateUniqueId(database));
            entity.AddResource(prefabPath);
            var defaultFootprint = new List <List <int> >()
            {
                new List <int>()
                {
                    1
                }
            };

            entity.AddGrid(null, new List <GameEntity>(), new Footprint(objectData.footprintData == null ? defaultFootprint : objectData.footprintData), objectData.canSwap);
            var view     = FactoryPool.GetPooled(prefabPath);
            var viewMono = view.GetComponent <ViewMonoComponent>();

            entity.AddView(view, viewMono != null ? viewMono.HUDpivot : view.transform);
            #if UNITY_EDITOR
            entity.viewObject.name = string.Format("ent_{0}_{1}_{2}", entity.objectId, entity.typeId, entity.uniqueId);
            #endif
            EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_GRID_ENTITY_CREATION, entity);

            return(entity);
        }
示例#2
0
        public FloatingUI CreateFloatingUI(string id)
        {
            var prefabPath = database.Get <string>(id);
            var view       = FactoryPool.GetPooled(prefabPath);

            view.transform.SetParent(floatingUIParent.transform, false);
            return(view.GetComponent <FloatingUI>());
        }
示例#3
0
        public static FactoryPool GetPool(string prefabPath)
        {
            foreach (var p in pools)
            {
                if (string.Equals(p.prefabPath, prefabPath))
                {
                    return(p);
                }
            }

            var pool = new FactoryPool(prefabPath);

            pools.Add(pool);
            return(pool);
        }
示例#4
0
        public static FactoryPool GetPool(GameObject prefab)
        {
            foreach (var p in pools)
            {
                if (string.Equals(p.prefab, prefab))
                {
                    return(p);
                }
            }

            var pool = new FactoryPool(prefab);

            pools.Add(pool);
            return(pool);
        }
示例#5
0
        public GameEntity CreateCell(int row, int column, string objectId, GameEntity occupant = null)
        {
            var entity     = Contexts.sharedInstance.game.CreateEntity();
            var objectData = database.Get <ObjectData>(objectId);
            var prefabPath = database.Get <string>(objectData.prefab);

            entity.AddGameObject(objectData.objectId, objectData.typeId, Utils.GenerateUniqueId(database));
            entity.AddResource(prefabPath);
            entity.AddCell(row, column, occupant);
            var view     = FactoryPool.GetPooled(prefabPath);
            var viewMono = view.GetComponent <ViewMonoComponent>();

            entity.AddView(view, viewMono != null ? viewMono.HUDpivot : view.transform);
            #if UNITY_EDITOR
            entity.viewObject.name = string.Format("cell_{0}_{1}_{2}_{3}_{4}", entity.objectId, entity.typeId, entity.row, entity.column, entity.uniqueId);
            #endif
            EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_CELL_ENTITY_CREATION, entity);

            return(entity);
        }
示例#6
0
        public GameEntity CreateVFX(string vfxId, Vector3 pos)
        {
            if (!string.IsNullOrEmpty(vfxId))
            {
                var entity  = Contexts.sharedInstance.game.CreateEntity();
                var vfxData = database.Get <VFXData>(vfxId);
                if (vfxData.isGUI)
                {
                    var split = vfxData.moveToPanel.Split('.');
                    if (split.Length == 2)
                    {
                        factoryGUI.AnimateFloatingUIWorldPos(vfxData.prefab, pos, split[0], split[1], vfxData.activeTime);
                    }
                }
                else
                {
                    var prefabPath = database.Get <string>(vfxData.prefab);
                    entity.AddResource(prefabPath);
                    var view = FactoryPool.GetPooled(prefabPath);
                    entity.AddView(view, view.transform);
                    entity.position = pos;
                }

                if (vfxData.activeTime > 0f)
                {
                    entity.AddAutoDestroy(vfxData.activeTime, vfxData.ignoreTimescale);
                }

                entity.position = pos;

                return(entity);
            }
            else
            {
                return(null);
            }
        }