Beispiel #1
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);//支持间隔上阵
        }
    }
Beispiel #2
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());
    }
Beispiel #3
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));
    }