public RemoteHostBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                       SoundManager soundManager, GameSignalingClient gameSignalingClient,
                                       MeleeAttackEntity meleeAttackEntity, EventSystemWatcher eventSystemWatcher)
        {
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.EnemyTankTransform = botEntity.transform;
            botEntity.gameObject.layer     = LayerMask.NameToLayer("EnemyBot");
            botEntity.transform.position   = tileMapInfo.GetPlayer1StartPosition();
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("EnemyBullet")),
                true
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun,
                meleeAttackApplication, true
                );

            gameSignalingClient.ReceivedClientReceiveSignalData += data =>
            {
                if (data.commandApplyTarget == MatchType.Host)
                {
                    new BotCommandsTransformerService().FromCommandData(data.commandData, botApplication);
                }
            };
        }
Exemplo n.º 2
0
 public PlayGameInitData(
     BotEntity botEntityPrefab,
     BotEntity botEntityPrefab2P,
     CameraFollower cameraFollower,
     PlayerHpPresenter playerHpPresenter,
     TileMapInfo tileMapInfo,
     RunButtonEvent runButtonEvent,
     ScriptText scriptText,
     BulletEntity bulletPrefab,
     ErrorMsg errorMsg,
     SoundManager soundManager,
     MeleeAttackEntity meleeAttackPrefab,
     ProcessScrollViewPresenter processScrollViewPresenter,
     EventSystemWatcher eventSystemWatcher)
 {
     this.botEntityPrefab            = botEntityPrefab;
     this.botEntityPrefab2P          = botEntityPrefab2P;
     this.cameraFollower             = cameraFollower;
     this.playerHpPresenter          = playerHpPresenter;
     this.tileMapInfo                = tileMapInfo;
     this.runButtonEvent             = runButtonEvent;
     this.scriptText                 = scriptText;
     this.bulletPrefab               = bulletPrefab;
     this.errorMsg                   = errorMsg;
     this.soundManager               = soundManager;
     this.meleeAttackPrefab          = meleeAttackPrefab;
     this.processScrollViewPresenter = processScrollViewPresenter;
     this.eventSystemWatcher         = eventSystemWatcher;
 }
Exemplo n.º 3
0
        public PlayerBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                   CameraFollower cameraFollower, PlayerHpPresenter playerHpPresenter, RunButtonEvent runButtonEvent,
                                   ScriptText scriptText, ErrorMsg errorMsg, SoundManager soundManager, MeleeAttackEntity meleeAttackEntity,
                                   ProcessScrollViewPresenter processScrollViewPresenter, EventSystemWatcher eventSystemWatcher)
        {
            this.errorMsg          = errorMsg;
            this.playerHpPresenter = playerHpPresenter;
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.PlayerTankTransform = botEntity.transform;
            botEntity.gameObject.layer      = LayerMask.NameToLayer("PlayerBot");
            cameraFollower.SetPlayerPosition(botEntity.transform);
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();

            botEntity.transform.position = tileMapInfo.GetPlayer1StartPosition();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("PlayerBullet")),
                false
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun, meleeAttackApplication
                );

            javaScriptEngine = new JavaScriptEngine.JavaScriptEngine(botApplication);
            runButtonEvent.AddClickEvent(() => OnRunButtonClick(processScrollViewPresenter, scriptText));
        }
Exemplo n.º 4
0
    protected void CheckVisibleTer(int _pos_x, int _pos_z, int i, int j)
    {
        if (_pos_x >= m_map_W || _pos_x < 0 || _pos_z >= m_map_H || _pos_z < 0)
        {
            m_needVisibleTer[i, j].isShow = false;
            SetVisibleTerNUll(i, j);
            return;
        }
        int _index_x = _pos_x / m_tilemap_W;
        int _index_z = _pos_z / m_tilemap_H;

        TileMapInfo _mapInfo       = null;
        bool        hasTileMapInfo = GetTileMapInfo(_index_x, _index_z, out _mapInfo);

        int map_index = _pos_z * m_map_W + _pos_x;

        //地形
        int  terrainIndex = 0;
        bool hasMapObj    = false;

        if (hasTileMapInfo)
        {
            hasMapObj = _mapInfo.mapInfoDic.TryGetValue(map_index, out terrainIndex);
        }
        if (hasMapObj)
        {
            m_needVisibleTer[i, j].isShow   = true;
            m_needVisibleTer[i, j].terIndex = terrainIndex;
        }
        else
        {
            m_needVisibleTer[i, j].isShow = false;
            SetVisibleTerNUll(i, j);
        }
    }
Exemplo n.º 5
0
    bool GetTileMapInfo(int w, int h, out TileMapInfo info)
    {
        if (!m_tilemapInfoIsInit[w, h])
        {
            if (!m_terrainInfoAsset.MapInfoList[w * m_splitMap_X + h])
            {
                m_tilemapInfoIsInit[w, h] = true;
                info = null;
                return(false);
            }
            string name = string.Format(m_tilemapInfoName, w, h);
#if TILEMAP_TEST
            var mapInfo = AssetDatabase.LoadAssetAtPath <TileMapInfo>(string.Format("{0}/{1}.asset", m_tilemapInfoPath, name));
            if (mapInfo != null)
            {
                mapInfo.Init();
                m_tilemapInfo[w, h] = mapInfo;
            }
            m_tilemapInfoIsInit[w, h] = true;
#else
            LoadManager.Instance.LoadAsset(m_tilemapInfoPath, name, "asset", typeof(TileMapInfo), (data) =>
            {
                var mapInfo = data as TileMapInfo;
                if (mapInfo != null)
                {
                    mapInfo.Init();
                    m_tilemapInfo[w, h] = mapInfo;
                }
                m_tilemapInfoIsInit[w, h] = true;
            }, false, false, false, m_fullPath);
#endif
        }
        info = m_tilemapInfo[w, h];
        return(m_terrainInfoAsset.MapInfoList[w * m_splitMap_X + h]);
    }
Exemplo n.º 6
0
        public void PosFix(TileMapInfo tileMapInfo)
        {
            GridPosition myPos     = tileMapInfo.GetGridPosition(transform.position);
            var          gridMyPos = tileMapInfo.GetWorldPosition(myPos);

            transform.position = new Vector3(gridMyPos.x, gridMyPos.y, transform.position.z);
        }
Exemplo n.º 7
0
 bool Move(float x, float y, TileMapInfo tileMapInfo)
 {
     if (RockCheck(x, y, tileMapInfo) || TancCheck(x, y, tileMapInfo))
     {
         return(false);
     }
     transform.position += new Vector3(x, y, 0);
     return(true);
 }
Exemplo n.º 8
0
        bool RockCheck(float x, float y, TileMapInfo tileMapInfo)
        {
            var gridSizeHalf = Global.GridSize / 2;

            x = x > 0 ? x + gridSizeHalf : x < 0 ? x - gridSizeHalf : x;
            y = y > 0 ? y + gridSizeHalf : y < 0 ? y - gridSizeHalf : y;
            var tileType = tileMapInfo.GetTileType(transform.position + new Vector3(x, y, 0));

            return(tileType == TileType.Rock);
        }
Exemplo n.º 9
0
        private void Start()
        {
            _info = GetComponent <TileMapInfo>();
            GridPosition p1  = _info.GetGridPosition(new Vector3(-208, -160));
            GridPosition p11 = new GridPosition(1, 1);

            Debug.Assert(_info.GetTileType(p1) == TileType.Rock);
            Debug.Assert(_info.GetTileType(_info.GetGridPosition(_info.GetPlayer1StartPosition())) == TileType.Empty);
            Debug.Assert(_info.GetTileType(_info.GetGridPosition(_info.GetPlayer2StartPosition())) == TileType.Empty);
            Debug.Log(_info.GetTileType(new GridPosition(0, 0)));
        }
Exemplo n.º 10
0
        public void initializeLayer(TileMapInfo map, int layer)
        {
            MapLayer maplay = renderManager.getLayer(layer);

            maplay.Map = map.Map;
            maplay.AutoScrollEnabled = true;
            maplay.XSpeed            = map.XScrollSpeed;
            maplay.YSpeed            = map.YScrollSpeed;
            maplay.WidthWrap         = map.WidthWrap;
            maplay.HeightWrap        = map.HeightWrap;
            maplay.AutoXScroll       = map.AutoXSpeed;
            maplay.AutoYScroll       = map.AutoYSpeed;
            tileManager.addDynamicTiles(map.EventTiles);
        }
Exemplo n.º 11
0
 public BotApplication(BotEntity botEntity, BotEntityAnimation botEntityAnimation, TileMapInfo tileMapInfo,
                       EventSystemWatcher eventSystemWatcher, Gun gun,
                       MeleeAttackApplication.MeleeAttackApplication meleeAttackApplication, bool noPosFix = false)
 {
     this.botEntity            = botEntity;
     botEntity.HitBulletEvent += (sender, e) => Hp = Hp.DamageHp(1);
     this.botEntityAnimation   = botEntityAnimation;
     this.tileMapInfo          = tileMapInfo;
     Hp = new BotHp(3);
     this.meleeAttackApplication = meleeAttackApplication;
     this.noPosFix           = noPosFix;
     this.eventSystemWatcher = eventSystemWatcher;
     this.gun = gun;
 }
        public MoveCommandObject(BotEntity botEntity, BotEntityAnimation botEntityAnimation, Direction direction,
                                 Action directionChangeCallback, uint gridDistance, TileMapInfo tileMapInfo,
                                 Action movingCallback, bool noPosFix)
        {
            this.botEntity               = botEntity;
            this.botEntityAnimation      = botEntityAnimation;
            this.direction               = direction;
            this.directionChangeCallback = directionChangeCallback;
            this.tileMapInfo             = tileMapInfo;
            this.movingCallback          = movingCallback;
            this.noPosFix = noPosFix;

            moveCount = (int)(gridDistance * Global.GridSize / speed);
        }
Exemplo n.º 13
0
        protected override TileMapInfo GenerateComponentData(Entity entity, TileMapComponent component)
        {
            var physicsComponent = entity.Get <PhysicsTriggerComponentBase>();
            var isValidPhysics   = physicsComponent is StaticColliderComponent || physicsComponent is RigidbodyComponent;

            var info = new TileMapInfo()
            {
                TileMapComponent    = component,
                TileGrid            = component.Grid,
                PhysicsComponent    = isValidPhysics ? physicsComponent : null,
                PhysicsShapeBuilder = component.PhysicsShapeBuilder,
            };

            return(info);
        }
Exemplo n.º 14
0
    public void MoveTo(float x, float z)
    {
        int start_x = Mathf.FloorToInt(x);
        int start_z = Mathf.FloorToInt(z);

        if (start_x == m_lastPos_x && start_z == m_lastPos_z)
        {
            return;
        }
        m_lastPos_x = start_x;
        m_lastPos_z = start_z;
        for (int i = 0; i < m_visibleObj.GetLength(0); i++)
        {
            for (int j = 0; j < m_visibleObj.GetLength(1); j++)
            {
                int _pos_x = start_x + i;
                int _pos_z = start_z + j;
                if (_pos_x >= m_map_W || _pos_x < 0 || _pos_z >= m_map_H || _pos_z < 0)
                {
                    SetVisibleObjNUll(i, j);
                    continue;
                }
                int         _index_x = _pos_x / m_tilemap_W;
                int         _index_z = _pos_z / m_tilemap_H;
                TileMapInfo _mapInfo = GetTileMapInfo(_index_x, _index_z);
                // int map_x = _pos_x % m_tilemap_W;
                // int map_y = _pos_z % m_tilemap_H;
                int            map_index = _pos_z * m_map_W + _pos_x;
                TileMapObjInfo mapObjInfo;
                if (_mapInfo.mapInfoDic.TryGetValue(map_index, out mapObjInfo))
                {
                    int objIndex = mapObjInfo.objIndex;
                    int objRotY  = mapObjInfo.objRotY;
                    SetVisibleObj(i, j, objIndex, i, j, objRotY);
                }
                else
                {
                    SetVisibleObjNUll(i, j);
                }
            }
        }
        pos_temp.x = start_x;
        pos_temp.z = start_z;
        Root.transform.position = pos_temp;
    }
        public ClientBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                   CameraFollower cameraFollower, PlayerHpPresenter playerHpPresenter, RunButtonEvent runButtonEvent,
                                   ScriptText scriptText, ErrorMsg errorMsg, SoundManager soundManager,
                                   GameSignalingClient gameSignalingClient,
                                   MeleeAttackEntity meleeAttackEntity, ProcessScrollViewPresenter processScrollViewPresenter,
                                   EventSystemWatcher eventSystemWatcher)
        {
            this.errorMsg          = errorMsg;
            this.playerHpPresenter = playerHpPresenter;
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.PlayerTankTransform = botEntity.transform;
            botEntity.gameObject.layer      = LayerMask.NameToLayer("PlayerBot");
            cameraFollower.SetPlayerPosition(botEntity.transform);
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();

            botEntity.transform.position = tileMapInfo.GetPlayer2StartPosition();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("PlayerBullet")),
                false
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun,
                meleeAttackApplication, true
                );
            var hookBotApplication = new ClientBotCommandsHook(botApplication, gameSignalingClient);

            javaScriptEngine = new JavaScriptEngine.JavaScriptEngine(hookBotApplication);
            runButtonEvent.AddClickEvent(async() =>
            {
                var tokenSource = new CancellationTokenSource();
                var token       = tokenSource.Token;
                var panel       =
                    processScrollViewPresenter.AddProcessPanel(
                        () => { tokenSource.Cancel(); });
                var task = javaScriptEngine.ExecuteJS(scriptText.GetScriptText(), token, panel.ProcessId);
                await task;
                panel.Dispose();
            });
        }
Exemplo n.º 16
0
        public CpuBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                SoundManager soundManager, MeleeAttackEntity meleeAttackEntity, EventSystemWatcher eventSystemWatcher)
        {
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.EnemyTankTransform = botEntity.transform;
            botEntity.gameObject.layer     = LayerMask.NameToLayer("EnemyBot");
            botEntity.transform.position   = tileMapInfo.GetPlayer2StartPosition();
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("EnemyBullet")),
                true
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun, meleeAttackApplication
                );
            cpuAi.Start(botApplication);
        }
Exemplo n.º 17
0
        bool TancCheck(float x, float y, TileMapInfo tileMapInfo)
        {
            var gridSizeHalf = Global.GridSize / 2 + 1;

            x = x > 0 ? x + gridSizeHalf : x < 0 ? x - gridSizeHalf : x;
            y = y > 0 ? y + gridSizeHalf : y < 0 ? y - gridSizeHalf : y;
            GridPosition movePos  = tileMapInfo.GetGridPosition(transform.position + new Vector3(x, y, 0));
            var          tileType = tileMapInfo.GetTileType(transform.position + new Vector3(x, y, 0));

            if (tileType == TileType.Tank)
            {
                GridPosition myPos = tileMapInfo.GetGridPosition(transform.position);
                if (!(movePos.X == myPos.X && movePos.Y == myPos.Y))
                {
                    PosFix(tileMapInfo);
                    return(true);
                }

                ;
            }

            return(false);
        }
Exemplo n.º 18
0
 protected override bool IsAssociatedDataValid(Entity entity, TileMapComponent component, TileMapInfo associatedData)
 {
     return(associatedData.TileMapComponent == component &&
            associatedData.TileGrid == component.Grid &&
            associatedData.PhysicsShapeBuilder == component.PhysicsShapeBuilder &&
            associatedData.PhysicsComponent == entity.Get <PhysicsTriggerComponentBase>());
 }
 public GetMyPositionCommandObject(TileMapInfo tileMapInfo, BotEntity botEntity)
 {
     this.tileMapInfo = tileMapInfo;
     this.botEntity   = botEntity;
 }
Exemplo n.º 20
0
 //縦に移動する(岩か敵があったら停止してfalse返す)
 public bool MoveY(float y, TileMapInfo tileMapInfo)
 {
     return(Move(0, y, tileMapInfo));
 }
Exemplo n.º 21
0
    public static void Export()
    {
        //加载MapInfo
        Dictionary <string, List <GameObject> > layerObjDic;
        string mapInfo;

        LoadMap(m_MapName, out layerObjDic, out mapInfo);

        //加载全局设置信息
        var          settingsInfoPath = AssetDatabase.GUIDToAssetPath(uteGLOBAL3dMapEditor.uteSettingstxt);
        StreamReader rd      = new StreamReader(settingsInfoPath);
        string       setting = rd.ReadToEnd();

        rd.Close();
        string[] infoSplited     = setting.Split(':');
        var      globalGridSizeX = System.Convert.ToInt32(infoSplited[3]);
        var      globalGridSizeZ = System.Convert.ToInt32(infoSplited[4]);

        //计算map分块大小,创建分块map配置
        int map_w = globalGridSizeX / m_MapSpiltSize.x;
        int map_h = globalGridSizeZ / m_MapSpiltSize.y;

        TileMapInfo[,] mapList = new TileMapInfo[m_MapSpiltSize.x, m_MapSpiltSize.y];
        for (int w = 0; w < m_MapSpiltSize.x; w++)
        {
            for (int h = 0; h < m_MapSpiltSize.y; h++)
            {
                mapList[w, h]             = GetStriptableObject <TileMapInfo>(string.Format("Assets/Map/MapInfo_{0}_{1}.asset", w, h));
                mapList[w, h].mapIndex    = h * map_w + w;
                mapList[w, h].posIndex    = new List <int>();
                mapList[w, h].posY        = new List <double>();
                mapList[w, h].objInfoList = new List <TileMapObjInfo>();
            }
        }

        //创建地形obj配置
        ObjRefInfo objRefInfo = GetStriptableObject <ObjRefInfo>("Assets/Map/ObjRefInfo.asset");

        objRefInfo.objRef = new List <ObjInfo>();
        objRefInfo.mats   = new List <Material>();
        var terrainObjList = layerObjDic["DEFAULT"];

        objRefInfo.gameObjectRef = terrainObjList;
        for (int i = 0; i < terrainObjList.Count; i++)
        {
            //顶点和UV
            MeshFilter     meshFilter = terrainObjList[i].GetComponent <MeshFilter>();
            List <Vector3> v          = new List <Vector3>();
            List <Vector2> v2         = new List <Vector2>();
            meshFilter.sharedMesh.GetVertices(v);
            for (int j = 0; j < v.Count; j++)
            {
                v2.Add(new Vector2(v[j].x, v[j].z));
            }
            List <Vector2> uvs = new List <Vector2>();
            meshFilter.sharedMesh.GetUVs(0, uvs);
            //材质
            MeshRenderer meshRender = terrainObjList[i].GetComponent <MeshRenderer>();
            Material     mat        = meshRender.sharedMaterial;
            int          matIndex   = 0;
            if (!objRefInfo.mats.Contains(mat))
            {
                matIndex = objRefInfo.mats.Count;
                objRefInfo.mats.Add(mat);
            }
            else
            {
                for (int j = 0; j < objRefInfo.mats.Count; j++)
                {
                    if (objRefInfo.mats[j].name == mat.name)
                    {
                        matIndex = j;
                    }
                }
            }
            objRefInfo.objRef.Add(new ObjInfo(v2.ToArray(), uvs.ToArray(), matIndex));
        }
        UnityEditor.EditorUtility.SetDirty(objRefInfo);

        //地形分块数据
        string[] myMapInfoAll = mapInfo.Split("$"[0]);
        for (int i = 0; i < myMapInfoAll.Length - 1; i++)
        {
            string[] myMapParts = myMapInfoAll[i].Split(":"[0]);
            string   layerName  = myMapParts[10].ToString();
            if (layerName == "DEFAULT")
            {
                int    objID      = System.Convert.ToInt32(myMapParts[0]);
                int    pX         = System.Convert.ToInt32(myMapParts[1]) - 500 + globalGridSizeX / 2 - 1;
                double pY         = System.Convert.ToDouble(myMapParts[2]);
                int    pZ         = System.Convert.ToInt32(myMapParts[3]) - 500 + globalGridSizeZ / 2 - 1;
                int    rY         = System.Convert.ToInt32(myMapParts[5]);
                string staticInfo = myMapParts[7];                //1:static

                int index_x   = Mathf.FloorToInt(pX / map_w);
                int index_z   = Mathf.FloorToInt(pZ / map_h);
                var _mapinfo  = mapList[index_x, index_z];
                int _posIndex = pZ * globalGridSizeX + pX;
                if (_mapinfo.posIndex.Contains(_posIndex))
                {
                    Debug.LogWarningFormat("有地块重叠:X:{0},Z:{1},会取Y比较大的地块", System.Convert.ToInt32(myMapParts[1]), System.Convert.ToInt32(myMapParts[3]));
                    int index = 0;
                    for (int j = 0; j < _mapinfo.posIndex.Count; j++)
                    {
                        if (_mapinfo.posIndex[j] == _posIndex)
                        {
                            index = j;
                            break;
                        }
                    }
                    if (_mapinfo.posY[index] < pY)
                    {
                        _mapinfo.posIndex[index]    = _posIndex;
                        _mapinfo.posY[index]        = pY;
                        _mapinfo.objInfoList[index] = new TileMapObjInfo(objID, rY);
                    }
                }
                else
                {
                    _mapinfo.posIndex.Add(_posIndex);
                    _mapinfo.posY.Add(pY);
                    _mapinfo.objInfoList.Add(new TileMapObjInfo(objID, rY));
                }

                UnityEditor.EditorUtility.SetDirty(_mapinfo);
            }
        }

        UnityEditor.AssetDatabase.SaveAssets();
    }
Exemplo n.º 22
0
 //横に移動する(岩か敵があったら停止してfalse返す)
 public bool MoveX(float x, TileMapInfo tileMapInfo)
 {
     return(Move(x, 0, tileMapInfo));
 }
 public GetTileTypeCommandObject(TileMapInfo tileMapInfo, GridPosition gridPosition)
 {
     this.tileMapInfo  = tileMapInfo;
     this.gridPosition = gridPosition;
 }
Exemplo n.º 24
0
 private void initTileMapInfo()
 {
     mapInfo = TileMapInfo.CreateFromJSON(jsonMapData.text);
 }
Exemplo n.º 25
0
 public GetPositionRadianCommandObject(TileMapInfo tileMapInfo, BotEntity botEntity, GridPosition targetGridPos)
 {
     this.tileMapInfo   = tileMapInfo;
     this.botEntity     = botEntity;
     this.targetGridPos = targetGridPos;
 }
Exemplo n.º 26
0
    void Start()
    {
        tileMapInfos = new TileMapInfo[gridRoots.Length];

        // 타일맵 인포 삽입작업
        for (int i = 0; i < gridRoots.Length; i++)
        {
            tileMapInfos[i] = new TileMapInfo(gridRoots[i]);
            gridMapIndex.Add(i);
        }

        selected = gridMapIndex[Random.Range(0, gridRoots.Length)];
        // Debug
        // 레트로, 자연, 흑목, 수중, 동굴
        //selected = 0;
        prevSelectedMap = selected;

        // selected 된 맵 인덱스의 BGM 을 재생한다
        PlayMusic(selected);


        Vector3 newPos;

        // Ver 1.1
        //selectedMap = Random.Range(0, tileMapInfos[selected].maps.Length);
        //MapInfo info = tileMapInfos[selected].maps[selectedMap];

        // Ver 1.2
        selectedMap = Random.Range(0, tileMapInfos[selected].maps.Length);
        MapInfo info = mapBridge.ActiveMapBridge(EntranceType.MIDDLE, EntranceType.MIDDLE, tileMapInfos[selected].parent.tag);

        // 추가
        tileMapInfos[selected].parent.SetActive(true);

        info.transform.localPosition = new Vector3(3.5f, 0, 0);
        info.gameObject.SetActive(true);
        info.SetItemLocate(scoreItems, scoreSprite);
        //usedMap++;

        currMap          = info;
        currMapTransform = currMap.tileMap.transform;

        // 현재 맵 endType 추출
        MapManager.EntranceType mapEndType = info.GetEndType();
        nextMapIndex.Clear();
        for (int i = 0; i < tileMapInfos[selected].maps.Length; i++)
        {
            if (tileMapInfos[selected].maps[i].GetStartType() == mapEndType)
            {
                // 현재 진행 중인 맵 인덱스는 빼버림
                if (i != selectedMap)
                {
                    nextMapIndex.Add(i);
                }
            }
        }

        int selectedNextMap = nextMapIndex[Random.Range(0, nextMapIndex.Count)];



        newPos = tileMapInfos[selected].maps[selectedMap].tileMap.transform.localPosition +
                 tileMapInfos[selected].maps[selectedNextMap].tileMap.size;
        newPos.y = newPos.z = 0;

        tileMapInfos[selected].maps[selectedNextMap].tileMap.transform.localPosition = newPos;
        tileMapInfos[selected].maps[selectedNextMap].tileMap.gameObject.SetActive(true);
        nextMap = tileMapInfos[selected].maps[selectedNextMap];
        nextMap.SetItemLocate(scoreItems, scoreSprite);
        nextMapTransform = nextMap.tileMap.transform;
        usedMap++;

        if (!isStop)
        {
            coMoveMap = StartCoroutine(CoroutineMoveMap());
        }
    }
Exemplo n.º 27
0
        protected override void OnEntityComponentRemoved(Entity entity, TileMapComponent component, TileMapInfo data)
        {
            base.OnEntityComponentRemoved(entity, component, data);

            data.PhysicsShapeBuilder?.RemoveAssociatedColliderShapes(data.PhysicsComponent);
        }
Exemplo n.º 28
0
        public static TileMapInfo fromStream(Level level, Stream stream, TileSet ts)
        {
            BinaryReader           reader = new BinaryReader(stream);
            int                    w = reader.ReadInt32(), h = reader.ReadInt32();
            List <Event.EventTile> eventTiles = new List <Event.EventTile>();
            TileMap                map        = new TileMap(w, h, ts);

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    int data = reader.ReadInt32();

                    if ((data & 1 << 31) == 1 << 31)
                    {
                        TileData buffer = new TileData(data);

                        bool flipped = false;
                        data = data ^ 1 << 31;

                        // additional data
                        byte flags = reader.ReadByte();

                        if ((flags & 1 << 0) == 1 << 0)
                        {
                            flipped = true;
                            buffer  = new ExtendedTileData(data, flipped);
                        }

                        if ((flags & 1 << 6) == 1 << 6)
                        {
                            Event.TEvent[] events = null;

                            if ((flags & 1 << 7) == 1 << 7)
                            {
                                int count = reader.ReadInt32();
                                events = new Event.TEvent[count];

                                for (int i = 0; i < count; i++)
                                {
                                    events[i] = level.TileManager.createEvent(reader.ReadInt32(), level.World, x, y);
                                    events[i].getSBCompound().readCompound(reader);
                                }
                            }

                            int idscount = reader.ReadInt32();

                            List <int> ids = new List <int>();

                            for (int i = 0; i < idscount; i++)
                            {
                                ids.Add(reader.ReadInt32());
                            }

                            int  interval = reader.ReadInt32();
                            bool pingpong = reader.ReadBoolean();

                            TileAnimation anim = new TileAnimation(ids.ToArray(), interval, pingpong, flipped, x, y, events);
                            buffer = anim;
                            eventTiles.Add(anim);
                        }
                        else
                        if ((flags & 1 << 7) == 1 << 7)
                        {
                            int            count  = reader.ReadInt32();
                            Event.TEvent[] events = new Event.TEvent[count];

                            for (int i = 0; i < count; i++)
                            {
                                events[i] = level.TileManager.createEvent(reader.ReadInt32(), level.World, x, y);
                                events[i].getSBCompound().readCompound(reader);
                            }

                            Event.EventTile evT = new Event.EventTile(data, flipped, x, y, events /*events...*/);
                            buffer = evT;
                            eventTiles.Add(evT);
                        }

                        map.setTile(x, y, buffer);
                    }
                    else
                    {
                        map.setTile(x, y, new TileData(data));
                    }
                }
            }

            if (h == 0 || w == 0)
            {
                map = new TileMap(1, 1, ts);
            }

            TileMapInfo info = new TileMapInfo(map)
            {
                XScrollSpeed = reader.ReadSingle(),
                YScrollSpeed = reader.ReadSingle(),
                AutoXSpeed   = reader.ReadSingle(),
                AutoYSpeed   = reader.ReadSingle(),
                WidthWrap    = reader.ReadBoolean(),
                HeightWrap   = reader.ReadBoolean(),
                EventTiles   = eventTiles.ToArray()
            };

            return(info);
        }