コード例 #1
0
ファイル: OtherEntourage.cs プロジェクト: atom-chen/tianyu
    /// <summary>
    /// 创建净数据对象
    /// </summary>
    /// <param name="_id"></param>
    /// <returns></returns>
    public static OtherEntourage CreateDummy(MercenaryInfo _info)
    {
        GameObject newGO = null;

        if (GameCenter.instance.dummyOpcPrefab != null)
        {
            newGO      = Instantiate(GameCenter.instance.dummyOpcPrefab) as GameObject;
            newGO.name = "Dummy OPE [" + _info.ServerInstanceID + "]";
        }
        else
        {
            newGO = new GameObject("Dummy OPE[" + _info.ServerInstanceID + "]");
        }
        newGO.tag = "Entourage";
        newGO.SetMaskLayer(LayerMask.NameToLayer("Entourage"));
        OtherEntourage newOPC = newGO.AddComponent <OtherEntourage>();

        newOPC.isDummy_     = true;
        newOPC.moveFSM      = newGO.AddComponent <ActorMoveFSM>();
        newOPC.id           = _info.ServerInstanceID;
        newOPC.actorInfo    = _info;
        newOPC.curMoveSpeed = newOPC.actorInfo.StaticSpeed * MOVE_SPEED_BASE;
        newOPC.CurRealSpeed = newOPC.curMoveSpeed;
        newOPC.RegistMoveEvent(true);
        newOPC.transform.localRotation = new Quaternion(0, _info.RotationY, 0, 0);
        GameCenter.curGameStage.PlaceGameObjectFromServer(newOPC, _info.ServerPos.x, _info.ServerPos.z, (int)newOPC.transform.localEulerAngles.y);
        GameCenter.curGameStage.AddObject(newOPC);
        return(newOPC);
    }
コード例 #2
0
ファイル: OtherEntourage.cs プロジェクト: atom-chen/tianyu
    IEnumerator CreateAsync(System.Action _callback = null)
    {
        if (isDummy_ == false)
        {
            Debug.LogError("You can only start create other player in dummy: " + actorInfo.ServerInstanceID);
            yield break;
        }
        //
        isDownloading_ = true;                          //判断是否正在下载,防止重复创建

        OtherEntourage         opc            = null;
        SmartActorRendererCtrl myRendererCtrl = null;
        bool faild = false;

        pendingDownload = Create(actorInfo, delegate(OtherEntourage _opc, EResult _result)
        {
            if (_result != EResult.Success)
            {
                faild = true;
                return;
            }

            opc             = _opc;
            pendingDownload = null;
            myRendererCtrl  = opc.gameObject.GetComponentInChildrenFast <SmartActorRendererCtrl>();
            myRendererCtrl.Show(false);
        });
        while (opc == null || opc.inited == false)
        {
            if (faild)
            {
                yield break;
            }
            yield return(null);
        }

        pendingDownload = null;
        isDownloading_  = false;

        if (!actorInfo.IsAlive)
        {
            opc.Dead(true);
        }
        if (_callback != null)
        {
            _callback();
        }
    }
コード例 #3
0
    /// <summary>
    /// 获取路径最近指定关系随从 by吴江
    /// </summary>
    /// <param name="_gameStage"></param>
    /// <param name="_player"></param>
    /// <param name="_needAlive"></param>
    /// <returns></returns>
    public static OtherEntourage GetClosestEntourage(this GameStage _gameStage, SmartActor _player, RelationType _relationType, ref float _distance)
    {
        List <OtherEntourage> opcs        = _gameStage.GetOtherEntourages();
        FDictionary           distanceDic = new FDictionary();
        FDictionary           opcDic      = new FDictionary();
        int       selfCamp     = _player.Camp;
        SceneType sceneType    = GameCenter.curGameStage.SceneType;
        Vector3   selfPosition = _player.transform.position;

        for (int i = 0; i < opcs.Count; i++)
        {
            OtherEntourage opc = opcs[i];
            if (opc.isDummy || !opc.IsShowing)
            {
                continue;
            }
            if (opc.gameObject != null && !opc.isDead && !opc.IsActor &&
                ConfigMng.Instance.GetRelationType(selfCamp, opc.Camp, sceneType) == _relationType)
            {
                Vector3[] path = GameStageUtility.StartPath(selfPosition, opc.transform.position);
                if (path != null)
                {
                    if (path.Length != 2)
                    {
                        distanceDic.Add(opc.id, path.CountPathDistance());//距离计算方法改变
                    }
                    else
                    {
                        distanceDic.Add(opc.id, Vector3.Distance(selfPosition, opc.transform.position));
                    }
                    opcDic.Add(opc.id, opc);
                }
            }
        }
        int   closestOne = -1;
        float distance   = -1;

        foreach (int id in distanceDic.Keys)
        {
            if (distance < 0 || distance >= (float)distanceDic[id])
            {
                closestOne = id;
                distance   = (float)distanceDic[id];
                _distance  = distance;
            }
        }
        return(opcDic.ContainsKey(closestOne) ? opcDic[closestOne] as OtherEntourage : null);
    }