/// <summary>
 /// 单位回收
 /// </summary>
 /// <param name="deadUnit"></param>
 internal void UnitBackPool(GameUnit.GameUnit deadUnit)
 {
     //回收单位
     GameUnitPool.Instance().PushUnit(deadUnit.gameObject);
     //移除对应地图块儿下的死亡单位
     BattleMap.BattleMap.Instance().RemoveUnitOnBlock(deadUnit);
 }
Beispiel #2
0
        private Unit InitAndInstantiateGameUnit(JsonData data, int x, int y)
        {
            Unit       newUnit;
            GameObject _object;
            //TODO:怎么没有根据所有者分别做处理
            OwnerEnum owner;

            switch (data["Controler - Enemy, Friendly or Self"].ToString())
            {
            case ("Enemy"):
                owner = OwnerEnum.Enemy; break;

            case ("Friendly"):
                owner = OwnerEnum.Neutrality; break;

            case ("Self"):
                owner = OwnerEnum.Player; break;

            default:
                owner = OwnerEnum.Enemy; break;
            }
            //从对象池获取单位
            _object = GameUnitPool.Instance().GetInst(data["name"].ToString(), owner, (int)data["Damaged"]);
            //修改单位对象的父级为地图方块
            _object.transform.SetParent(_mapBlocks[x, y].transform);
            _object.transform.localPosition = Vector3.zero;


            //TODO 血量显示 test版本, 此后用slider显示
            var   TextHp     = _object.transform.GetComponentInChildren <Text>();
            var   gameUnit   = _object.GetComponent <GameUnit.GameUnit>();
            float hp         = gameUnit.hp /* - Random.Range(2, 6)*/;
            float maxHp      = gameUnit.MaxHP;
            float hpDivMaxHp = hp / maxHp * 100;

            TextHp.text = string.Format("Hp: {0}%", hpDivMaxHp);

            newUnit = _object.GetComponent <Unit>();
            return(newUnit);
        }
Beispiel #3
0
        /// <summary>
        /// 初始战斗地图上的单位
        /// </summary>
        /// <param name="encounterID">遭遇id</param>
        private void InitAndInstantiateGameUnit(string encounterID)
        {
            JsonData data = encounter.GetEncounterDataByID(encounterID);

            if (data == null)
            {
                return;
            }

            JsonData   unitData      = data["UnitMessage"];
            int        unitDataCount = unitData.Count;
            OwnerEnum  owner;
            GameObject _object;

            for (int i = 0; i < unitDataCount; i++)
            {
                int x = (int)unitData[i]["Pos_X"];
                int y = (int)unitData[i]["Pos_Y"];
                //单位控制者:0为玩家,1为敌方AI_1,2为敌方AI_2,...
                switch (unitData[i]["UnitControler"].ToString())
                {
                case ("0"):
                    owner = OwnerEnum.Player; break;

                case ("1"):
                    owner = OwnerEnum.Enemy; break;

                default:
                    owner = OwnerEnum.Enemy; break;
                }
                //从对象池获取单位
                _object = GameUnitPool.Instance().GetInst(unitData[i]["UnitID"].ToString(), owner);

                Unit unit = _object.GetComponent <Unit>();
                //修改单位对象的父级为地图方块
                _mapBlocks[x, y].AddUnit(unit);
                // _object.transform.SetParent(_mapBlocks[x, y].transform);
                //_object.transform.localPosition = Vector3.zero;
                _unitsList.Add(unit);
                unit.mapBlockBelow = _mapBlocks[x, y];

                AI.SingleController controller;
                //初始化AI控制器与携带的仇恨列表
                if (_unitsList.Count == 0 || _unitsList.Count == 3 || _unitsList.Count == 5)
                {
                    controller = new AI.SingleAutoControllerAtker(unit); //无脑型
                }
                else
                {
                    controller = new AI.SingleAutoControllerDefender(unit);//防守型
                }
                controller.hatredRecorder.Reset(unit);
                GamePlay.Gameplay.Instance().autoController.singleControllers.Add(controller);


                //TODO 血量显示 test版本, 此后用slider显示
                var   TextHp     = _object.transform.GetComponentInChildren <Text>();
                var   gameUnit   = _object.GetComponent <GameUnit.GameUnit>();
                float hp         = gameUnit.hp /* - Random.Range(2, 6)*/;
                float maxHp      = gameUnit.MaxHP;
                float hpDivMaxHp = hp / maxHp * 100;
                TextHp.text = string.Format("Hp: {0}%", hpDivMaxHp);
            }
        }