Exemplo n.º 1
0
    /// <summary>
    /// 能量最低的船
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    private static List <TeamDisplay> GetEnergyLowestShip(List <TeamDisplay> list)
    {
        List <TeamDisplay> result = new List <TeamDisplay>();
        float       tempValue     = float.MaxValue;
        TeamDisplay trans         = null;

        for (int i = 0; i < list.Count; i++)
        {
            // 获取能量最低的
            ClientShip ship = list[i].GetShip();
            if (ship == null)
            {
                continue;
            }
            if (tempValue > ship.Energy)
            {
                tempValue = ship.Energy;
                trans     = list[i];
            }
        }
        if (trans != null)
        {
            result.Add(trans);
        }
        return(result);
    }
Exemplo n.º 2
0
    public static void SetPlayerShip(ClientShip ship, Vector3 position)
    {
        ClientShip newShip = ClientShip.Clone(ship);

        newShip.Position = position;
        PlayerShipList.Add(newShip);
    }
Exemplo n.º 3
0
 private GameController()
 {
     Borders        = new IStaticObject[4];
     ServerShips    = new ClientShip[10];
     CurrentShips   = new ClientShip[10];
     ClientWindVane = new ClientWindVane();
 }
Exemplo n.º 4
0
 /// <summary>
 /// 判断所有舰船是否在技能范围
 /// </summary>
 /// <param name="trans"></param>
 /// <param name="list"></param>
 private void CheckAllSkillTarget(List <TeamDisplay> list)
 {
     for (int i = BattleArrowGroupList.Count - 1; i >= 0; i--)
     {
         if (BattleArrowGroupList[i] == null)
         {
             BattleArrowGroupList.RemoveAt(i);
         }
     }
     for (int i = 0; i < list.Count; i++)
     {
         GameObject team = list[i].GetTeamGo();
         if (team == null)
         {
             continue;
         }
         Transform targetTrans = team.transform;
         if (IsContainsArrow(targetTrans))
         {
             continue;
         }
         ClientShip ship = list[i].GetShip();
         float      vol  = ship.Reference.vol;
         SetArrowTarget(targetTrans, vol);
     }
 }
Exemplo n.º 5
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(0, 0, 100, 100), "开始战斗"))
        {
            List <ClientShip> playerShipList = new List <ClientShip>();
            List <ClientShip> enemyShipList  = new List <ClientShip>();

            // player
            ClientShip ship = new ClientShip();
            ship.ReadFromId(10000);
            ship.Position = new Vector3(100, 0, 0);
            playerShipList.Add(ship);

            ship = new ClientShip();
            ship.ReadFromId(10001);
            ship.Position = new Vector3(300, 0, 0);
            playerShipList.Add(ship);

            // enemy
            ship = new ClientShip();
            ship.ReadFromId(10000);
            ship.Position = new Vector3(100, 0, 400);
            enemyShipList.Add(ship);

            ship = new ClientShip();
            ship.ReadFromId(10001);
            ship.Position = new Vector3(300, 0, 400);
            enemyShipList.Add(ship);

            FightService.Instance.InitService(playerShipList, enemyShipList);
            FightService.Instance.BeginFight();
        }
    }
Exemplo n.º 6
0
    private GameObject CreateShipGroup(ClientShip targetShip, string targetShipResPath, float shipWrapRadius)
    {
        GameObject group = new GameObject();

        group.transform.SetParent(DeploySceneManager.Instance.PlayerGridDrawer.GridInstance.transform);

        //约定组名为目标舰船在数据索引值,记录之,方便传给战斗布阵单元的坐标
        group.name = PlayerSys.GetPlayerShipList().IndexOf(targetShip).ToString();
        // 初始化阵形
        BattleSys.SetFormation(true, targetShip);
        //成组上阵,组中舰船的数量
        int groupMemberCount = targetShip.Reference.stack ? targetShip.Reference.stack_num : 1;

        BoxCollider tempCollider = null;

        for (int i = 0; i < groupMemberCount; i++)
        {
            Vector3    pos    = targetShip.FormationList == null ? Vector3.zero : targetShip.FormationList[i];
            GameObject member = CreateShip(targetShipResPath, group.transform, GridDrawer.OffsetByWrapRadius(pos, shipWrapRadius));

            if (tempCollider == null)
            {
                tempCollider = member.GetComponent <BoxCollider>();
            }
            Destroy(member.GetComponent <BoxCollider>());
            DestoryTrailEffect(member);
        }

        //添加tag,用于点选式布阵的碰撞检测
        group.tag = "ShipModel";

        return(group);
    }
Exemplo n.º 7
0
    /// <summary>
    /// 重置各种状态数据
    /// </summary>
    private void Reset()
    {
        //清除旗舰技能引用,因为下次进入该面板,有无都有可能
        CommandShip_ = null;
        //清除技能控制按钮
        if (CtrlBtn_ != null)
        {
            Destroy(CtrlBtn_.gameObject);
        }
        CtrlBtn_ = null;

        //清除技能按钮列表
        if (SkillList_ != null)
        {
            for (int i = SkillBtnCount - 1; i >= 0; i--)
            {
                BattleSceneDisplayManager.EventOnSkillSing    -= SkillList_[i].ForbidFireSkill;
                BattleSceneDisplayManager.EventOnSkillTrigger -= SkillList_[i].CoolDownSkill;
                Destroy(SkillList_[i].gameObject);
            }
        }
        SkillList_     = null;
        SkillListRoot_ = null;
        CtrlBtnRoot_   = null;
        BattleSceneDisplayManager.EventOnPlayerCommanderShipDead -= OnCommandShipDie;
    }
Exemplo n.º 8
0
    /// <summary>
    /// 拖拽上阵主逻辑
    /// </summary>
    private IEnumerator OnDeploying(Vector3 pos)
    {
        ClientShip deployingTarget = CurrShipToDeploy;

        if (deployingTarget == null)
        {
            Debugger.LogError("ClientShip Data is null!");
            yield break;
        }

        Ship ship = AssetLoader.GetShipDefine(deployingTarget.Reference.model_res);

        if (ship == null)
        {
            Debugger.LogError(string.Format("can't create ship, id : {0}, modelRes : {1}", deployingTarget.Reference.id, deployingTarget.Reference.model_res));
            yield break;
        }

        //保证缓存中有资源
        yield return(StartCoroutine(AssetLoader.PreloadShipModel(ship)));

        float shipWrapRadius = (float)deployingTarget.Reference.vol;

        GameObject group = CreateShipGroup(deployingTarget, ship.ModelPath, shipWrapRadius);

        EquipColliderForSnapping(group, shipWrapRadius);
        EquipSnappingComponent(group, shipWrapRadius);
        SyncUnitStateByDeployMode(pos);
    }
Exemplo n.º 9
0
    /// <summary>
    /// 扇形区域检测算法标准版,先实现这个
    /// </summary>
    /// <param name="parts">攻击部件</param>
    /// <param name="targetShip">敌方单位</param>
    /// <param name="squareRange">检测范围平方</param>
    /// <param name="theta">扇形角度</param>
    /// <returns></returns>
    private static bool IsInCritricalSector(ClientParts parts, ClientShip targetShip, float squareRange, float theta)
    {
//         float distanceSq = GetDistanceSq( parts.Owner, targetShip );
//         if( distanceSq > squareRange )
//             return false;
        // D = P - C
        float dx = targetShip.Position.x - parts.Owner.Position.x;
        float dz = targetShip.Position.z - parts.Owner.Position.z;

        // |D|^2 = (dx^2 + dz^2)
        float disntaceSq = dx * dx + dz * dz;

        // |D|^2 > r^2
        if (disntaceSq > squareRange)
        {
            return(false);
        }

        float distance = Mathf.Sqrt(disntaceSq);


        // Normalize D
        dx /= distance;
        dz /= distance;

        return(true);
    }
Exemplo n.º 10
0
    private IEnumerator CreateShip(bool bPlayer, ClientShip clientShip)
    {
        if (clientShip == null)
        {
            Debug.LogError("can't create,clientShip is null");
            yield break;
        }
        Ship ship = AssetLoader.GetShipDefine(clientShip.Reference.model_res);

        if (ship == null)
        {
            Debug.LogError("can't create ship,id is:" + clientShip.Reference.id + ",modelres is:" + clientShip.Reference.model_res);
            yield break;
        }

        TeamDisplay       display  = new TeamDisplay();
        List <GameObject> shipList = new List <GameObject>();
        int stackNum = 1;

        if (clientShip.Reference.stack)
        {
            stackNum = clientShip.Reference.stack_num;
        }
        for (int i = 0; i < stackNum; i++)
        {
            GameObject shipGo = AssetLoader.GetInstantiatedGameObject(ship.ModelPath);
            if (!shipGo)
            {
                yield return(StartCoroutine(AssetLoader.PreloadShipModel(ship)));

                shipGo = AssetLoader.GetInstantiatedGameObject(ship.ModelPath);
            }
            AssetLoader.ReplaceShader(shipGo);
            shipGo.name = (bPlayer ? "PlayerShip" : "EnemyShip") + clientShip.InFightID;
            if (clientShip.IsCommanderShip())
            {
                shipGo.name += "_Commander";
            }
            AssetLoader.SetShowParts(ship, shipGo);

            Animation animation = shipGo.GetComponent <Animation>();
            if (animation != null)
            {
                animation.cullingType = AnimationCullingType.AlwaysAnimate;
            }
            shipList.Add(shipGo);
        }

        display.Init(clientShip, ship, shipList, bPlayer);
        if (bPlayer)
        {
            PlayerTeamDisplayList.Add(clientShip.InFightID, display);
        }
        else
        {
            EnemyTeamDisplayList.Add(clientShip.InFightID, display);
        }
    }
Exemplo n.º 11
0
    private Vector3 GetDeployCameraOriginPostion()
    {
        ClientShip ship     = BattleSys.GetFarestEnemy();
        float      vol      = ship.Reference.vol;
        Vector3    position = ship.Position + new Vector3(DeployOriginPositionX, 0, 18f + vol / 2);

        position.y = DeployOriginPositionY;
        return(position);
    }
Exemplo n.º 12
0
    /// <summary>
    /// 初始化各种状态数据
    /// </summary>
    private void Init()
    {
        //取旗舰技能
        CommandShip_ = BattleSys.GetCommanderShip();

        if (CommandShip_ != null)
        {
            InitSkillPanel();
            InitCtrlBtn();
            InitSkillBtnList();
            InitCancelBtn();
        }
        else
        {
        }
        CanClick_ = true;
    }
Exemplo n.º 13
0
    private static void SetEnemyShipList()
    {
        EnemyShipList.Clear();
        // todo 临时敌人,到时用服务器下发数据

        var enemyUnitList = GlobalConfig.GetUnitLisByBattlefieldByID(NowMapID_);
        int id            = 50;

        for (int i = 0; i < enemyUnitList.Count; i++)
        {
            ClientShip ship = new ClientShip();
            ship.ReadFromId(enemyUnitList[i].units_id);
            ship.Position  = new Vector3(enemyUnitList[i].x_position, 0, enemyUnitList[i].z_position);
            ship.InFightID = id++;
            EnemyShipList.Add(ship);
        }
    }
Exemplo n.º 14
0
        public void UpdateWorld(byte[] dataBytes, int step, bool isStarted)
        {
            if (dataBytes == null)
            {
                return;
            }

            if (step == 0)
            {
                int pos = 0;

                // Корабли
                int countOfShips = CommonSerializer.GetInt(ref pos, dataBytes);
                for (int i = 0; i < countOfShips; i++)
                {
                    if (ServerShips[i] == null)
                    {
                        ServerShips[i]  = new ClientShip(new Corvette());
                        CurrentShips[i] = new ClientShip(new Corvette());
                    }
                    ServerShips[i].Ship.DeSerialize(ref pos, dataBytes);
                }

                // Флюгер
                ClientWindVane.WindVane.DeSerialize(ref pos, dataBytes);

                // Ядра
                Bullets = new List <ClientBullet>();
                int countOfBullets = CommonSerializer.GetInt(ref pos, dataBytes);
                for (int i = 0; i < countOfBullets; i++)
                {
                    var bullet = new Bullet();
                    bullet.DeSerialize(ref pos, dataBytes);
                    Bullets.Add(new ClientBullet(bullet));
                }
            }

            if (!isStarted)
            {
                InitCurrentShips();
            }
            else
            {
                UpdateCurrentShips(step);
            }
        }
Exemplo n.º 15
0
    /// <summary>
    /// 扇形区域检测,U3D版本
    /// </summary>
    /// <param name="parts"></param>
    /// <param name="targetShip"></param>
    /// <returns></returns>
    private static bool IsInCricularSector2(ClientParts parts, ShipEntity targetUnit, float squareRange, float theta)
    {
        ClientShip targetShip = targetUnit.Ship;
        float      dx         = targetShip.Position.x - parts.Owner.Position.x;
        float      dz         = targetShip.Position.z - parts.Owner.Position.z;

        // |D|^2 = (dx^2 + dz^2)
        float disntaceSq = dx * dx + dz * dz;

        // |D|^2 > r^2
        if (disntaceSq > squareRange)
        {
            return(false);
        }

        Vector3 targetDir = targetShip.Position - parts.Owner.Position;


        Vector3 forward = new Vector3(0, 0, 1);

        if (targetUnit.CampType == FightServiceDef.CampType.Camp_Attacker)
        {
            forward.z = -1;
        }

        float angle = Vector3.Angle(targetDir.normalized, forward);

        // 角度小于扇形的角度,说明目标的原型在扇形区域内
        if (angle * 2 <= theta)
        {
            return(true);
        }

        // 近防距离检查
        if (parts.Reference.closein_range > 0)
        {
            int closein_range = (parts.Reference.closein_range + targetShip.Reference.vol) * ((parts.Reference.closein_range + targetShip.Reference.vol));
            if (closein_range >= disntaceSq)
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 16
0
    public static void SetFormation(bool bPlayer, ClientShip ship)
    {
        if (ship == null)
        {
            return;
        }
        // 随机一个阵形
        int stackNum = 1;

        if (ship.Reference.stack)
        {
            stackNum = ship.Reference.stack_num;
        }
        if (stackNum > 1)
        {
            ship.FormationList = GlobalConfig.GetFormationList(bPlayer);
        }
    }
Exemplo n.º 17
0
    /// <summary>
    /// 释放当前选中的技能, by lxl
    /// </summary>
    private void FireSkill(int currentClickIndex)
    {
        // 旗舰
        ClientShip commandShip = BattleSys.GetCommanderShip();

        if (commandShip == null)
        {
            return;
        }
        bool isSelectedSkillTarget = BattleSceneDisplayManager.IsSelectedSkillTarget;

        // 玩家还没选择目标,给提示
        if (!isSelectedSkillTarget)
        {
            // 提示玩家选择目标
            ShowSelecteTargetNotice();
            return;
        }
        // 得到选中的技能
        ClientSkill skill   = BattleSceneDisplayManager.SelectedSkill;
        Vector3     pos     = Vector3.zero;
        int         fightID = -1;

        // 如果是玩家选择的技能
        if (skill.Prop.skill_select_type == Def.SkillSelectType.PlayerSelect)
        {
            // 得到玩家选择的位置或目标
            if (skill.Prop.shape_type == Def.ShapeType.Default)
            {
                TeamDisplay display = (TeamDisplay)BattleSceneDisplayManager.Instance.SkillSelectParam;
                fightID = display.GetShip().InFightID;
            }
            else if (skill.Prop.shape_type == Def.ShapeType.Circle)
            {
                pos = (Vector3)BattleSceneDisplayManager.Instance.SkillSelectParam;
            }
        }
        // 使用技能
        FightService.Instance.UseCommanderSkill(commandShip.InFightID, skill.ID, fightID, pos);

        // 技能释放完毕后要重设选择状态
        BattleSceneDisplayManager.CastSkillComplete();
        BattleSceneDisplayManager.CheckCommanderAttackRange();
    }
Exemplo n.º 18
0
    /// <summary>
    /// 创建所有舰船
    /// </summary>
    /// <returns></returns>
    private IEnumerator CreateAllShips()
    {
        CoroutineJoin join = new CoroutineJoin(AssetLoader.Instance);

        // player
        for (int i = 0; i < BattleSys.GetShipCount(true); i++)
        {
            ClientShip clientShip = BattleSys.GetShipByIndex(true, i);
            join.StartSubtask(CreateShip(true, clientShip));
        }

        // enemy
        for (int i = 0; i < BattleSys.GetShipCount(false); i++)
        {
            ClientShip clientShip = BattleSys.GetShipByIndex(false, i);
            join.StartSubtask(CreateShip(false, clientShip));
        }
        yield return(join.WaitForAll());
    }
Exemplo n.º 19
0
    private IEnumerator GenerateEnemyFormation()
    {
        GameObject root = new GameObject("__EnemyRoot__");

        root.transform.SetParent(transform);
        root.transform.localPosition = Vector3.zero;
        root.transform.localScale    = Vector3.one;

        int shipCount = BattleSys.GetShipCount(false);

        for (int i = 0; i < shipCount; i++)
        {
            ClientShip cs   = BattleSys.GetShipByIndex(false, i);
            Ship       ship = AssetLoader.GetShipDefine(cs.Reference.model_res);
            if (ship == null)
            {
                Debug.LogError(string.Format("can't create ship, id : {0}, modelRes : {1}",
                                             cs.Reference.id,
                                             cs.Reference.model_res));
                yield break;
            }

            //成组上阵,组中舰船的数量
            int stackNum = cs.Reference.stack ? cs.Reference.stack_num : 1;

            GameObject group = new GameObject(string.Format("id_{0}", cs.Reference.id));
            group.transform.SetParent(root.transform);
            group.transform.position = cs.Position;

            //保证缓存中有资源
            yield return(StartCoroutine(AssetLoader.PreloadShipModel(ship)));

            for (int j = 0; j < stackNum; j++)
            {
                GameObject go = AssetLoader.GetInstantiatedGameObject(ship.ModelPath);
                AssetLoader.ReplaceShader(go);
                go.transform.SetParent(group.transform);
                go.transform.localPosition = cs.FormationList == null ? Vector3.zero : cs.FormationList[j];
                go.transform.eulerAngles   = new Vector3(0f, 180f, 0f);//朝向与攻击方相反
            }
            //yield return new WaitForSeconds(0.2f);//支持间隔上阵
        }
    }
Exemplo n.º 20
0
    public ShipEntity(ClientShip ship, int campType)
    {
        base.ID  = ship.InFightID;
        CampType = campType;
        Ship     = ship;
        InitAllAttr();
        FsmInstance    = new StateMachine <ShipEntity>(this);
        BuffManager    = new BuffManager(this);
        StackAliveNum_ = ship.Reference.stack_num;

        if (CampType == FightServiceDef.CampType.Camp_Attacker)
        {
            FsmInstance.SetCurrentState(SeekState.Instance);
        }
        else
        {
            FsmInstance.SetCurrentState(DefendState.Instance);
        }
    }
Exemplo n.º 21
0
    void SetupFightTeam(List <ClientShip> AttackerTeam, List <ClientShip> DefenderTeam)
    {
        Combating = false;
        EntityManager.Instance.ClearAll();
        MessageDispatcher.Instance.ClearAll();
        for (int i = 0; i < AttackerTeam.Count; ++i)
        {
            ClientShip clientship = ClientShip.Clone(AttackerTeam[i]);
            ShipEntity ship       = new ShipEntity(clientship, FightServiceDef.CampType.Camp_Attacker);
            EntityManager.Instance.RegisterEntity(ship);
        }

        for (int i = 0; i < DefenderTeam.Count; i++)
        {
            ClientShip clientship = ClientShip.Clone(DefenderTeam[i]);
            ShipEntity ship       = new ShipEntity(clientship, FightServiceDef.CampType.Camp_Defender);
            EntityManager.Instance.RegisterEntity(ship);
        }
    }
Exemplo n.º 22
0
    /// <summary>
    /// 记录布阵情况(索引,对应世界坐标)
    /// </summary>
    public void RecordDeployInfo()
    {
        Transform formationRoot = DeploySceneManager.Instance.PlayerGridDrawer.GridInstance.transform;

        for (int i = 0; i < formationRoot.childCount; i++)
        {
            Transform t     = formationRoot.transform.GetChild(i);
            int       index = int.Parse(t.name);
            //Debug.Log( string.Format( "<color=green>RecordDeployInfo, index : {0}, position : {1}</color>", index, t.position ) );
            ClientShip cs = PlayerSys.GetPlayerShipList()[index];
            if (cs == null)
            {
                Debugger.LogError("RecordDeployInfo Failed! At index : " + index);
                return;
            }

            PlayerSys.Formation(index, t.position + new Vector3(cs.Reference.vol % GridDrawer.GRID_SPACE_UNIT_SIZE, 0f, cs.Reference.vol % GridDrawer.GRID_SPACE_UNIT_SIZE));//纠正偏移
        }
    }
Exemplo n.º 23
0
    public static ClientShip GetFarestEnemy()
    {
        ClientShip result = null;

        for (int i = 0; i < EnemyShipList.Count; i++)
        {
            ClientShip ship = EnemyShipList[i];
            if (result == null)
            {
                result = ship;
            }
            else
            {
                if (result.Position.z < ship.Position.z)
                {
                    result = ship;
                }
            }
        }
        return(result);
    }
Exemplo n.º 24
0
    //
    public static ClientShip Clone(ClientShip ship)
    {
        var newShip = new ClientShip();

        newShip.Id            = ship.Id;
        newShip.InFightID     = ship.InFightID;
        newShip.Level         = ship.Level;
        newShip.Reference     = ship.Reference;
        newShip.Position      = ship.Position;
        newShip.DefenseClass_ = ship.DC;
        newShip.FormationList = ship.FormationList;

        for (int i = 0; i < ship.PartsList.Count; i++)
        {
            var parts = ship.PartsList[i];
            parts.Owner        = newShip;
            parts.CoolDownTime = 0;
            newShip.PartsList.Add(parts);
        }

        foreach (var part in ship.PartsDic)
        {
            newShip.PartsDic[part.Key] = part.Value;
        }

        foreach (var skill in ship.SkillDic)
        {
            skill.Value.CoolDownTime    = 0;
            newShip.SkillDic[skill.Key] = skill.Value;
        }

        newShip.ShipProperty_ = ClientProperty.Clone(ship.ShipProperty_);
        newShip.Durability    = newShip.ShipProperty_.MaxDurability;

        newShip.Armor  = ship.Armor;
        newShip.Energy = ship.Energy;
        return(newShip);
    }
Exemplo n.º 25
0
    /// <summary>
    /// 显示trans所属队伍的选中状态,关闭所属队伍列表内其他队伍的选中状态
    /// </summary>
    /// <param name="trans"></param>
    private void ShowSelect(Transform trans)
    {
        if (trans == null)
        {
            return;
        }
        Dictionary <int, TeamDisplay> teamList = GetTeamDisplayList(trans);
        TeamDisplay display = GetTeamDisplay(trans);

        if (display == null)
        {
            return;
        }
        ResetSelect(teamList, display.IsPlayerShip());
        display.SetSelect(true);
        if (!display.IsPlayerShip())
        {
            return;
        }
        GameObject teamGo = display.GetTeamGo();

        if (teamGo == null)
        {
            return;
        }
        Transform  teamGoTrans = teamGo.transform;
        ClientShip ship        = display.GetShip();
        float      vol         = ship.Reference.vol;

        if (SelectedPlayerShipArrowGroup_ == null)
        {
            SelectedPlayerShipArrowGroup_ = BattleArrowGroup.InitArrowGroup(teamGoTrans, vol, false);
        }
        else
        {
            SelectedPlayerShipArrowGroup_.ChangeParent(teamGoTrans, vol);
        }
    }
Exemplo n.º 26
0
    public static void Login()
    {
        // todo 临时的,以后用实际数据
        // 旗舰
        ClientShip ship = new ClientShip();

        ship.ReadFromId(40000);
        ship.InFightID = 0;
        Info_.ClientShipList_.Add(ship);

        int fightID = 1;

        // 导弹护卫舰
        for (int i = 0; i < 3; i++)
        {
            ship = new ClientShip();
            ship.ReadFromId(30000);
            ship.InFightID = fightID;
            Info_.ClientShipList_.Add(ship);
            fightID++;
        }

        // 机炮艇
        for (int i = 0; i < 4; i++)
        {
            ship = new ClientShip();
            ship.ReadFromId(10000);
            ship.InFightID = fightID;
            Info_.ClientShipList_.Add(ship);
            fightID++;
        }

        if (EventOnLogin != null)
        {
            EventOnLogin();
        }
    }
Exemplo n.º 27
0
    /// <summary>
    /// 布阵相机协程
    /// </summary>
    /// <returns></returns>
    private IEnumerator DeployCameraThread()
    {
        // 相机开始移动
        //yield return new WaitForSeconds( 2f );
        MainCamera_.transform.position         = Vector3.zero;
        MainCamera_.transform.localEulerAngles = Vector3.zero;

        // 相机要指向的位置缓存
        int firstID  = 30000;
        int secondID = 40000;
        int thirdID  = 60000;

        Dictionary <int, Vector3> posList = new Dictionary <int, Vector3>();
        int shipCount = BattleSys.GetShipCount(false);

        for (int i = 0; i < shipCount; i++)
        {
            ClientShip cs = BattleSys.GetShipByIndex(false, i);
            if (cs.Reference.id == firstID || cs.Reference.id == secondID || cs.Reference.id == thirdID)
            {
                if (!posList.ContainsKey(cs.Reference.id))
                {
                    posList.Add(cs.Reference.id, cs.Position);
                }
            }
        }
        Animator animator = MainCamera.AddComponent <Animator>();

        animator.runtimeAnimatorController = Resources.Load("Camera/camera_control") as RuntimeAnimatorController;

        Vector3 pos;

        posList.TryGetValue(firstID, out pos);
        MainCamera_.transform.position        = pos;
        MainCamera.transform.position         = new Vector3(29.3f, 19.9f, -40.8f);
        MainCamera.transform.localEulerAngles = new Vector3(15, 315, 0);
        animator.SetTrigger("DeployCameraStep01");
        yield return(new WaitForSeconds(2.3f));

        posList.TryGetValue(secondID, out pos);
        MainCamera_.transform.position        = pos;
        MainCamera.transform.position         = new Vector3(38.3f, 4.3f, 49.7f);
        MainCamera.transform.localEulerAngles = new Vector3(-2.3f, 238.54f, 0);
        animator.SetTrigger("DeployCameraStep02");
        yield return(new WaitForSeconds(3.51f));

        posList.TryGetValue(thirdID, out pos);
        MainCamera_.transform.position        = pos;
        MainCamera.transform.position         = new Vector3(46.8f, 8.1f, -9.7f);
        MainCamera.transform.localEulerAngles = new Vector3(0, 258, 0);
        animator.SetTrigger("DeployCameraStep03");
        yield return(new WaitForSeconds(3.2f));

        // 显示敌人指挥中心信息
        StartCoroutine(PlayEffectOfMainEnemy(pos));
        yield return(new WaitForSeconds(2.1f));

        posList.Clear();

        // 得到相机和边线的z值差
        proto.BattlefieldReference reference = GlobalConfig.GetBattlefieldReferenceByID(BattleSys.NowMapID);
        if (reference == null)
        {
            yield break;
        }
        // 战场长度
        float length = reference.basearea_len + reference.deptharea_len + reference.deployarea_len;

        Vector3 position = new Vector3(DeployOriginPositionX, DeployOriginPositionY, -length - 23.8f);
        Vector3 angle    = new Vector3(DeployOriginRotationX, DeployOriginRotationY, DeployOriginRotationZ);

        // 初始化基地区域相机属性
        CameraInfo info = GetCameraInfo(CameraStatusType.DeployMoveToBase);

        info.position = position + new Vector3(0, 0, length - reference.basearea_len / 2);
        info.angles   = angle;
        // 初始化布阵区域相机属性
        info          = GetCameraInfo(CameraStatusType.DeployMoveToDeploy);
        info.position = position;
        info.angles   = angle;
        // 设置相机位置和旋转
        MainCamera.transform.position          = Vector3.zero;
        MainCamera.transform.localEulerAngles  = Vector3.zero;
        MainCamera_.transform.position         = position;
        MainCamera_.transform.localEulerAngles = angle;
        animator.SetTrigger("DeployCameraStep04");
        yield return(new WaitForSeconds(2));

        Destroy(animator);

        // 移动完毕,修改模式为可操作模式
        SetCameraType(CameraStatusType.Deploy);
        // 显示布阵界面
        UIManager.ShowPanel <DeployPanel>();
        UIManager.ShowPanel <DeployCameraControl>();
        // 开启相机线程
        StartCoroutine(CameraThread(null));
    }
Exemplo n.º 28
0
 /// <summary>
 /// 距离平方
 /// 快速判断距离办法
 /// </summary>
 /// <param name="Attacker"></param>
 /// <param name="Target"></param>
 /// <returns></returns>
 private static float GetDistanceSq(ClientShip Attacker, ClientShip Target)
 {
     return(((Target.Position.x - Attacker.Position.x) * (Target.Position.x - Attacker.Position.x)) + ((Target.Position.z - Attacker.Position.z) * (Target.Position.z - Attacker.Position.z)));
 }
Exemplo n.º 29
0
 /// <summary>
 /// 扇形区域算法优化版
 /// 1、优化半径检测开平方
 /// 2、优化夹角选择开平方
 /// </summary>
 /// <param name="?"></param>
 /// <returns></returns>
 private static bool IsInCricularSector1(ClientParts parts, ClientShip targetShip)
 {
     return(true);
 }
Exemplo n.º 30
0
    public void Init(ClientShip clientShip, Ship ship, List <GameObject> shipList, bool bPlayer)
    {
        IsDead = false;

        RootGo_ = new GameObject("Root_" + (bPlayer ? "Player" : "Enemy") + "_");  //+ clientShip.Reference.name );
        RootGo_.transform.position = clientShip.Position;

        ClientShip_ = clientShip;
        //Ship_ = ship;
        Vector3[] tempFormationList = clientShip.FormationList;

        for (int i = 0; i < shipList.Count; i++)
        {
            ShipDisplay display = shipList[i].AddComponent <ShipDisplay>();
            display.Init(this, ship, clientShip.Position, tempFormationList == null ? Vector3.zero : tempFormationList[i], bPlayer);
            ShipList_.Add(display);
        }
        bool isAdvancedShip = (clientShip.Reference.id == 40000 || clientShip.Reference.id == 60000);//暂时这样写,到时候根据tag来

        BattleShipInfo_ = BattleShipInfo.Create(RootGo_.transform, this, clientShip.Name, ship.shieldRadius, bPlayer, isAdvancedShip);

        foreach (var iter in clientShip.PartsList)
        {
            float atkRangeMin  = iter.Reference.atk_range_min;
            float atkRangeMax  = iter.Reference.atk_range_max;
            float atkMoveRange = iter.Reference.attack_move_range;
            float angle        = iter.Reference.atk_angle;
            // 最近和最远的攻击范围
            AttackRangeDisplayList_.Add(AttackRangeDisplay.InitSectorAttackRange(bPlayer, RootGo_.transform, atkRangeMin, atkRangeMax, angle, Color.red));
            // 移动攻击范围
            AttackRangeDisplayList_.Add(AttackRangeDisplay.InitSectorAttackRange(bPlayer, RootGo_.transform, 0, atkMoveRange, angle, Color.gray));
        }

        // 是玩家并且是旗舰,生成技能范围
        if (bPlayer && clientShip.IsCommanderShip())
        {
            for (int i = 0; i < 3; i++)
            {
                ClientSkill        skill   = clientShip.GetSkillByIndex(i);
                AttackRangeDisplay display = null;
                if (skill != null)
                {
                    proto.SkillReference reference = skill.Prop;
                    // 扇形
                    if (reference.skill_select_type == Def.SkillSelectType.CastScope)
                    {
                        display = AttackRangeDisplay.InitSectorAttackRange(true, RootGo_.transform, 0, reference.cast_range, reference.cast_angle, Color.blue);
                    }
                    //else if( reference.skill_select_type == Def.SkillSelectType.PlayerSelect ) {
                    // 圆形
                    //if( reference.shape_type == Def.ShapeType.Circle ) {
                    //    display = AttackRangeDisplay.InitCircleAttackRange( RootGo_.transform, reference.aoe_range, Color.blue );
                    //}
                    //}
                    else if (reference.skill_select_type == Def.SkillSelectType.NoSelection)
                    {
                        // 矩形或圆形
                        if (reference.shape_type == Def.ShapeType.Rectangle)
                        {
                            display = AttackRangeDisplay.InitRectangleAttackRange(RootGo_.transform, reference.radiate_len, reference.radiate_wid * 2, Color.blue);
                        }
                        else if (reference.shape_type == Def.ShapeType.Circle)
                        {
                            display = AttackRangeDisplay.InitCircleAttackRange(RootGo_.transform, reference.aoe_range, Color.blue);
                        }
                    }
                    if (display != null)
                    {
                        display.gameObject.name += "_skill";
                    }
                }
                SkillAttackRangeDisplayList.Add(display);
            }
        }

        if (HaloTemplate_ == null)
        {
            HaloTemplate_ = Resources.Load("Effect/Halo");
        }

        HaloGo_ = GameObject.Instantiate(HaloTemplate_) as GameObject;
        HaloGo_.transform.GetChild(0).localPosition = Vector3.zero;
        HaloGo_.transform.parent           = RootGo_.transform;
        HaloGo_.transform.localEulerAngles = Vector3.zero;
        HaloGo_.transform.localPosition    = Vector3.zero + new Vector3(0, -1, 0);
        HaloGo_.transform.localScale       = Vector3.one * clientShip.Reference.vol;
    }