コード例 #1
0
    private bool InstantiateExplosion(Vector2Int position, Vector2Int offset, bool isBound)
    {
        bool stop = false;

        EEntityType entityType = _map.GetEntityType(position + offset);

        if (entityType != EEntityType.UnbreakableWall || entityType == EEntityType.Explosion)
        {
            if (entityType == EEntityType.DestructibleWall)
            {
                stop = true;
            }

            var explosion = Instantiate(_explosionCenter, transform);
            var animator  = explosion.GetComponent <Animator>();
            animator.SetBool(OffsetToSide(offset), true);
            animator.SetBool(ANIMATOR_IS_BOUND_KEY, isBound || stop);
            explosion.transform.localPosition = new Vector3(offset.x, offset.y, 0);

            _impactedCells.Add(position + offset);
        }
        else
        {
            stop = true;
        }

        return(stop);
    }
コード例 #2
0
ファイル: EEntityType.cs プロジェクト: yangfan111/CsharpCode
        public static EntityKey[] GetEntitysWithEntityKey(this Contexts contexts, EEntityType type)
        {
            switch (type)
            {
            case  EEntityType.Vehicle:
                return(contexts.vehicle.GetEntities().Select(x => x.hasEntityKey?x.entityKey.Value:EntityKey.Default).ToArray());

            case  EEntityType.Player:
                return(contexts.player.GetEntities().Select(x => x.hasEntityKey?x.entityKey.Value:EntityKey.Default).ToArray());

            case  EEntityType.Bullet:
                return(contexts.bullet.GetEntities().Select(x => x.hasEntityKey?x.entityKey.Value:EntityKey.Default).ToArray());

            case EEntityType.SceneObject:
                return(contexts.sceneObject.GetEntities().Select(x => x.hasEntityKey?x.entityKey.Value:EntityKey.Default).ToArray());

            case EEntityType.FreeMove:
                return(contexts.freeMove.GetEntities().Select(x => x.hasEntityKey?x.entityKey.Value:EntityKey.Default).ToArray());

            case EEntityType.Throwing:
                return(contexts.throwing.GetEntities().Select(x => x.hasEntityKey?x.entityKey.Value:EntityKey.Default).ToArray());

            case EEntityType.MapObject:
                return(contexts.mapObject.GetEntities().Select(x => x.hasEntityKey ? x.entityKey.Value : EntityKey.Default).ToArray());

            default:
                return(new EntityKey[0]);
            }
        }
コード例 #3
0
    public void Render()
    {
        RenderTexture.active = _renderTexture;

        //don't forget that you need to specify rendertexture before you call readpixels
        //otherwise it will read screen pixels.
        _texture.ReadPixels(new Rect(0, 0, _renderTexture.width, _renderTexture.height), 0, 0);

        int factorX = _renderTexture.width / _map.MapSize.x;
        int factorY = _renderTexture.height / _map.MapSize.y;

        for (int y = 0; y < _renderTexture.height; y += factorX)
        {
            for (int x = 0; x < _renderTexture.width; x += factorY)
            {
                Vector2Int  cellPosition = new Vector2Int(x / factorX, y / factorY);
                EEntityType entityType   = _map.GetEntityType(cellPosition);
                Color       color        = GetEntityColor(entityType);

                for (int j = 0; j < factorY; j++)
                {
                    for (int i = 0; i < factorX; i++)
                    {
                        _texture.SetPixel(x + i, y + j, color);
                    }
                }
            }
        }

        _texture.Apply();

        RenderTexture.active = null; //don't forget to set it back to null once you finished playing with it.
    }
コード例 #4
0
ファイル: BaseEntityFactory.cs プロジェクト: cnscj/THSTG
        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);
        }
コード例 #5
0
        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);
                }
            });
        }
コード例 #6
0
    public void UpdateMinimap()
    {
        for (int y = 0; y < _map.MapSize.y; y++)
        {
            for (int x = 0; x < _map.MapSize.x; x++)
            {
                Vector2Int  cellPosition = new Vector2Int(x, y);
                EEntityType entity       = _map.GetEntityType(cellPosition);

                Image cell = GetCell(x, (_map.MapSize.y - 1) - y);
                cell.sprite = _sprites[entity];
                cell.color  = Color.white;

                if (entity == EEntityType.Player)
                {
                    Player player = _gameManager.GetPlayerAt(cellPosition);

                    if (player != null)
                    {
                        cell.color = player.Color;
                    }
                }
            }
        }
    }
コード例 #7
0
    private Color GetEntityColor(EEntityType entityType)
    {
        Color color = Color.black;

        if (entityType == EEntityType.None)
        {
            color = Color.white;
        }
        else if (entityType == EEntityType.DestructibleWall)
        {
            color = Color.black;
        }
        else if (entityType == EEntityType.Player)
        {
            color = Color.green;
        }
        else if (entityType == EEntityType.Bomb)
        {
            color = Color.red;
        }
        else if (entityType == EEntityType.Bonus)
        {
            color = Color.yellow;
        }
        else if (entityType == EEntityType.Explosion)
        {
            color = Color.magenta;
        }

        return(color);
    }
コード例 #8
0
    public EntityData(EEntityType eType, string pPublicName, string pAssetsName, float fHealth)
    {
        m_eType = eType;

        m_pPublicName = pPublicName;
        m_pAssetsName = pAssetsName;

        m_fHealth = fHealth;
    }
コード例 #9
0
ファイル: EntityManager.cs プロジェクト: cnscj/THSTG
        public GameEntity CreateEntity(string code)
        {
            EEntityType       entityType = EntityUtil.GetEntityTypeByCode(code);
            BaseEntityFactory factory    = GetOrNewEntityFactory(entityType);

            if (factory != null)
            {
                return(factory.CreateEntity(code));
            }

            return(null);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: EntityManager.cs プロジェクト: cnscj/THSTG
 ////////////////////////////
 public void DestroyEntity(GameEntity entity)
 {
     if (entity != null && entity.hasEntityData)
     {
         EEntityType       entityType = entity.entityData.entityType;
         BaseEntityFactory factory    = GetOrNewEntityFactory(entityType);
         if (factory != null)
         {
             factory.DestroyEntity(entity);
         }
         else
         {
             entity.Destroy();
         }
     }
 }
コード例 #13
0
ファイル: EntityManager.cs プロジェクト: cnscj/THSTG
        ////////////////////////////

        public BaseEntityFactory GetOrNewEntityFactory(EEntityType entityType)
        {
            if (!entityFactoryMap.TryGetValue(entityType, out BaseEntityFactory factory))
            {
                if (s_factoryType.TryGetValue(entityType, out Type clsType))
                {
                    factory = (BaseEntityFactory)Activator.CreateInstance(clsType);
                }

                if (factory != null)
                {
                    entityFactoryMap.Add(entityType, factory);
                }
            }

            return(factory);
        }
コード例 #14
0
ファイル: LevelMap.cs プロジェクト: Wurze/C-2-TheCozening
        private void InitEntitiesPosition()
        {
            // test if a entity layer exists
            if (mMapData.Layers.Length <= (int)ELayer.ENTITIES)
            {
                return;
            }

            // test if the layer is an object layer ( it's the case on the tilemap)
            if (!(mMapData.Layers[(int)ELayer.ENTITIES] is ObjectLayer layer))
            {
                return;
            }

            foreach (var item in layer.Objects)
            {
                // verify is the item as an entityType property & object is a tileObject ( means the object is from an image)
                if (item.Properties.ContainsKey("EntityType") && item is TileObject tileObject)
                {
                    //get entityType ( need parsing because in the file properties are string)
                    EEntityType entityType = (EEntityType)int.Parse(tileObject.Properties["EntityType"]);

                    // set entityPos ( need to substract tileObject.Height because the object is draw by the bottom side)
                    Vector2 entityPos = new Vector2((int)tileObject.X, (int)(tileObject.Y - tileObject.Height));

                    switch (entityType)
                    {
                    case EEntityType.PLAYER:
                        PlayerPosition = entityPos;
                        break;

                    case EEntityType.NPC:
                        NpcPosition = entityPos;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #15
0
ファイル: EEntity.cs プロジェクト: Tiaoyu/TServer
 public static int GenerateEntityId(EEntityType type)
 {
     return((int)type * 100000000 + ++BaseId[(int)type]);
 }
コード例 #16
0
        /// <summary>
        /// Reads Daisy's Garden file stream
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <returns>DGF if successful, otherwise "null"</returns>
        public static IDGF ReadDGFStream(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            IDGF ret = null;

            if (!stream.CanRead)
            {
                throw new AccessViolationException("Specified DGF stream can not be read from.");
            }
            using (BinaryReader binary_reader = new BinaryReader(stream, Encoding.ASCII, true))
            {
                if (binary_reader.ReadInt32() != dgfFileHeader)
                {
                    throw new InvalidDataException("File header does not match the expected file header");
                }
                if (ReadDGFString(binary_reader) != gameName)
                {
                    throw new InvalidDataException("Game name does not match the expected game name.");
                }
                if ((binary_reader.ReadInt16() != 0x7) || (binary_reader.ReadByte() != 0x0))
                {
                    throw new InvalidDataException($"Unknown constant after game name does not match the documented unknown constant after game name.");
                }
                string edit_password = ReadAndDecryptDGFString(binary_reader);
                string play_password = ReadAndDecryptDGFString(binary_reader);
                string apply_play_password_until_garden_number_string = ReadAndDecryptDGFString(binary_reader);
                if (!ushort.TryParse(apply_play_password_until_garden_number_string, out ushort apply_play_password_until_garden_number))
                {
                    throw new InvalidDataException($"Failed to parse \"apply play password until garden number\".");
                }
                string author_name          = ReadDGFString(binary_reader);
                string comments             = ReadDGFString(binary_reader);
                string garden_one_midi_path = ReadDGFString(binary_reader);
                ushort number_of_garden     = binary_reader.ReadUInt16();
                byte   constant             = binary_reader.ReadByte();
                bool   failure = true;
                if (constant == 0x0)
                {
                    failure = false;
                }
                else if (constant == 0xFF)
                {
                    if (binary_reader.ReadInt32() == 0x090001FF)
                    {
                        failure = binary_reader.ReadByte() != 0x0;
                    }
                }
                if (failure)
                {
                    throw new InvalidDataException($"Unknown constant after the number of garden does not match to any of the documented values.");
                }
                if (Encoding.ASCII.GetString(binary_reader.ReadBytes(daisysGardenClassName.Length)) != daisysGardenClassName)
                {
                    throw new InvalidDataException($"Incorrect Daisy's Garden class name.");
                }
                ushort program_version = binary_reader.ReadUInt16();
                if ((program_version != 0x1) && (program_version != 0x2))
                {
                    throw new InvalidDataException($"Program version \"{ program_version }\" is not supported.");
                }
                List <IGarden> garden = new List <IGarden>();
                for (ushort garden_index = 0; garden_index != number_of_garden; garden_index++)
                {
                    if ((garden_index > 0) && (binary_reader.ReadInt32() != dgfFileGardenSeparator))
                    {
                        throw new InvalidDataException($"Incorrect garden seperator.");
                    }
                    string garden_name       = ReadDGFString(binary_reader);
                    string garden_midi_path  = ReadDGFString(binary_reader);
                    ushort garden_width      = binary_reader.ReadUInt16();
                    ushort garden_height     = binary_reader.ReadUInt16();
                    ushort garden_time       = binary_reader.ReadUInt16();
                    uint   garden_tile_count = binary_reader.ReadUInt32();
                    if (garden_tile_count != (garden_width * garden_height))
                    {
                        throw new InvalidDataException($"Garden tile count does not match with garden width times garden height.");
                    }
                    ETile[,] tile_grid = new ETile[garden_width, garden_height];
                    for (uint cell_index = 0U; cell_index != garden_tile_count; cell_index++)
                    {
                        byte   tile_id       = binary_reader.ReadByte();
                        ushort tile_variant  = binary_reader.ReadUInt16();
                        ETile  computed_tile = (ETile)(tile_id | (tile_variant << 8));
                        if (tileEnumItems.Contains(computed_tile))
                        {
                            tile_grid[cell_index % garden_width, cell_index / garden_width] = computed_tile;
                        }
                    }
                    uint           number_of_entities = binary_reader.ReadUInt32();
                    List <IEntity> entities           = new List <IEntity>();
                    for (uint entity_index = 0; entity_index < number_of_entities; entity_index++)
                    {
                        byte        entity_type     = binary_reader.ReadByte();
                        ushort      entity_variant  = binary_reader.ReadUInt16();
                        EEntityType computed_entity = (EEntityType)(entity_type | (entity_variant << 8));
                        if (entityEnumItems.Contains(computed_entity))
                        {
                            IPosition position = new Position(binary_reader.ReadUInt16(), binary_reader.ReadUInt16());
                            IBounds   bounds   = Bounds.Infinite;
                            string    hint     = string.Empty;
                            switch (computed_entity)
                            {
                            case EEntityType.Daisy:
                            case EEntityType.RedKey:
                            case EEntityType.YellowKey:
                            case EEntityType.GreenKey:
                            case EEntityType.Apple:
                            case EEntityType.Lemon:
                            case EEntityType.Cherry:
                            case EEntityType.Pineapple:
                            case EEntityType.Garlic:
                            case EEntityType.Mushroom:
                            case EEntityType.Spinach:
                            case EEntityType.Carrot:
                            case EEntityType.Sunflower:
                            case EEntityType.Tulip:
                            case EEntityType.YellowDaisy:
                            case EEntityType.Rose:
                                break;

                            case EEntityType.Marmot:
                            case EEntityType.RightMovingWorm:
                            case EEntityType.LeftMovingWorm:
                            case EEntityType.UpMovingLift:
                            case EEntityType.DownMovingLift:
                            case EEntityType.LeftMovingLift:
                            case EEntityType.RightMovingLift:
                                short left   = binary_reader.ReadInt16();
                                short top    = binary_reader.ReadInt16();
                                short right  = binary_reader.ReadInt16();
                                short bottom = binary_reader.ReadInt16();
                                bounds = new Bounds(top, bottom, left, right);
                                break;

                            case EEntityType.QuestionMark:
                                hint = ReadDGFString(binary_reader);
                                break;

                            default:
                                throw new InvalidDataException($"Invalid entity type \"{ (int)computed_entity }\"");
                            }
                            entities.Add(new Entity(computed_entity, position, bounds, hint));
                        }
                    }
                    garden.Add(new Garden(garden_name, garden_midi_path, garden_time, tile_grid, entities));
                }
                ret = new DGF(edit_password, play_password, apply_play_password_until_garden_number, author_name, comments, garden_one_midi_path, garden);
            }
            return(ret);
        }
コード例 #17
0
ファイル: EEntity.cs プロジェクト: Tiaoyu/TServer
 private static bool IsEntity(int id, EEntityType type)
 {
     return(id / 100000000 == (int)type);
 }
コード例 #18
0
 public EntityData(EEntityType eType)
     : this(eType, "Undefined", "Undefined", 0.0f)
 {
 }
コード例 #19
0
    public void SetEntityType(EEntityType entityType, Vector3 worldPosition)
    {
        Vector2Int cellPosition = CellPosition(worldPosition);

        _entitiesMap[cellPosition.x, cellPosition.y] = entityType;
    }
コード例 #20
0
 public void SetEntityType(EEntityType entityType, Vector2Int cellPosition)
 {
     _entitiesMap[cellPosition.x, cellPosition.y] = entityType;
 }