예제 #1
0
        /// <summary>
        /// 测试用于本地无网络状态下,人物的移动,这个方法和OnEnterMove没半毛钱关系
        ///
        /// </summary>
        public void OnLocalMove()
        {
//			if (mTimeStartup == 0) {
//				mTimeStartup = Time.realtimeSinceStartup;
//			}
//			//m_pcGOSSI.sServerSyncPos = m_pcGOSSI.sServerBeginPos + m_pcGOSSI.sServerDir * fMoveDist;
//			float fThisRealTimeSinceStartup = Time.realtimeSinceStartup;
//			Debug.Log (fThisRealTimeSinceStartup);
//		//	this.objTransform.position = this.objTransform.position + EntityFSMDirection * EntityFSMMoveSpeed * fThisRealTimeSinceStartup* Time.deltaTime;
//			this.RealEntity.Controller.Move (EntityFSMDirection * EntityFSMMoveSpeed * Time.deltaTime*10);
//
//			EntityFSMPosition = this.objTransform.position;
//			mTimeStartup = fThisRealTimeSinceStartup;
            //************************************************************************************************
            Vector3 entityPos2d = new Vector3(RealEntity.GetTransform().position.x, 60, RealEntity.GetTransform().position.z);
            //Vector3 sSyncDir = serverPos2d - entityPos2d;
            Vector3 sSyncDir = entityPos2d;

            sSyncDir.Normalize();            //单位向量
//			float fDistToServerPos = Vector3.Distance(serverPos2d, entityPos2d);
//			if (fDistToServerPos > 5)
//			{
//
//				RealEntity.GetTransform().position = m_pcGOSSI.sServerSyncPos;
//				OnCameraUpdatePosition();
//				return;
//			}
            //Vector3 pos = entityPos2d + sSyncDir * EntityFSMMoveSpeed * Time.deltaTime;
            this.RealEntity.Controller.Move(sSyncDir * EntityFSMMoveSpeed * Time.deltaTime * 10);
            float mDefaultHeight = 60;

            RealEntity.GetTransform().position = new Vector3(RealEntity.GetTransform().position.x, mDefaultHeight, RealEntity.GetTransform().position.z);
        }
예제 #2
0
        public override void OnExecuteEntityAdMove()
        {
            base.OnExecuteEntityAdMove();
            Quaternion DestQuaternion = Quaternion.LookRotation(EntityFSMDirection);
            Quaternion sMidQuater     = Quaternion.Lerp(RealEntity.GetTransform().rotation, DestQuaternion, 10 * Time.deltaTime);

            RealEntity.GetTransform().rotation = sMidQuater;
            this.RealEntity.PlayerRunAnimation();
        }
예제 #3
0
        /// <summary>
        /// 转动朝向
        /// </summary>
        private void TurnAngle()
        {
            float fAngle = Vector3.Angle(RealEntity.GetTransform().forward, EntityFSMDirection);

            if (fAngle > 2)
            {
                Quaternion DestQuaternion          = Quaternion.LookRotation(EntityFSMDirection);
                Quaternion sMidQuater              = Quaternion.Lerp(RealEntity.GetTransform().rotation, DestQuaternion, 5 * Time.deltaTime);
                RealEntity.GetTransform().rotation = sMidQuater;
            }
        }
예제 #4
0
 private void UpdataRange()
 {
     if (CircleArea == null)
     {
         return;
     }
     if (RealEntity == null)
     {
         return;
     }
     CircleArea.transform.localScale = new Vector3(this.AtkDis * 2.0f / RealEntity.GetTransform().localScale.x, 1.0f, this.AtkDis * 2.0f / RealEntity.GetTransform().localScale.z);
 }
예제 #5
0
        /// <summary>
        /// 状态机执行Free消息
        /// </summary>
        public override void OnExecuteFree()
        {
            if (RealEntity == null || this.entityType == EntityType.Building)
            {
                return;
            }

            if (JxBlGame.Instance == null)
            {
                //RealEntity.PlayerRunAnimation ();
                GameMethod.GetMainCamera.FixedUpdatePosition();
                //statemanager == null 所以下面方法不执行的
                OnCameraUpdatePosition();
                TurnAngle();
                return;
            }
            //计算平面位置
            Vector3 synPos2D  = new Vector3(m_pcGOSSI.sServerSyncPos.x, 60, m_pcGOSSI.sServerSyncPos.z);
            Vector3 realPos2D = new Vector3(RealEntity.GetTransform().position.x, 60, RealEntity.GetTransform().position.z);

            float fDistToServerPos = Vector3.Distance(synPos2D, realPos2D);

            if (fDistToServerPos < 0.5f)
            {
                if (EntityStrategyHelper.IsTick(this, EntityStrategyHelper.IdleTimeTick))
                {
                    this.OnFSMStateChange(BlGame.FSM.EntityIdleFSM.Instance);
                    return;
                }
                RealEntity.PlayerFreeAnimation();
            }
            else if (fDistToServerPos > 5)
            {
                RealEntity.PlayerFreeAnimation();
                RealEntity.GetTransform().position = m_pcGOSSI.sServerBeginPos;
            }
            else
            {
                Vector3 sSyncDir = synPos2D - realPos2D;
                sSyncDir.Normalize();
                Vector3 pos = sSyncDir * 2 * Time.deltaTime + realPos2D;

                RealEntity.PlayerRunAnimation();
                this.RealEntity.Controller.Move(sSyncDir * 2 * Time.deltaTime);
            }

            OnCameraUpdatePosition();
            TurnAngle();
        }
예제 #6
0
        /// <summary>
        /// 状态机执行移动
        /// </summary>
        public override void OnExecuteMove()//Iplayer中
        {
            if (RealEntity == null || this.entityType == EntityType.Building)
            {
                return;
            }

            Quaternion DestQuaternion = Quaternion.LookRotation(EntityFSMDirection);
            Quaternion sMidQuater     = Quaternion.Lerp(RealEntity.GetTransform().rotation, DestQuaternion, 10 * Time.deltaTime);

            RealEntity.GetTransform().rotation = sMidQuater;                                         //实体方向旋转

            float fTimeSpan = Time.realtimeSinceStartup - m_pcGOSSI.fBeginTime;                      //时间间隔
            float fMoveDist = fTimeSpan * m_pcGOSSI.fServerSpeed;                                    //在此间隔内移动的距离

            m_pcGOSSI.sServerSyncPos = m_pcGOSSI.sServerBeginPos + m_pcGOSSI.sServerDir * fMoveDist; //新位置
            RealEntity.PlayerRunAnimation();                                                         //播放跑的动画

            //同步2D位置处理
            Vector3 serverPos2d = new Vector3(m_pcGOSSI.sServerSyncPos.x, 60, m_pcGOSSI.sServerSyncPos.z);                     //需要同步的位置,新的位置
            Vector3 entityPos2d = new Vector3(RealEntity.GetTransform().position.x, 60, RealEntity.GetTransform().position.z); //实体真实位置

            Vector3 sSyncDir = serverPos2d - entityPos2d;                                                                      //方向向量

            sSyncDir.Normalize();                                                                                              //向量归一化
            float fDistToServerPos = Vector3.Distance(serverPos2d, entityPos2d);                                               //距离差值

            if (fDistToServerPos > 5)                                                                                          //距离差值大5 说明速度太快,直接赋值,忽略碰撞体
            {
                RealEntity.GetTransform().position = m_pcGOSSI.sServerSyncPos;                                                 //移动到新位置上
                OnCameraUpdatePosition();                                                                                      //摄像机更新跟随
                return;
            }
            //当距离差值小于5的时候 速度说明慢,慢速的时候不能穿过碰撞体
            Vector3 pos = entityPos2d + sSyncDir * EntityFSMMoveSpeed * Time.deltaTime;//在原位置上移动一帧后的新位置

            //移动到新位置上 使用角色空控制器的Move时动力只受限制于碰撞。它将沿着碰撞器滑动,不应用于重力
            this.RealEntity.Controller.Move(sSyncDir * EntityFSMMoveSpeed * Time.deltaTime);

            //限制Y值始终在默认的高度上
            RealEntity.GetTransform().position = new Vector3(RealEntity.GetTransform().position.x, mDefaultHeight, RealEntity.GetTransform().position.z);


            OnCameraUpdatePosition();//摄像机更新
            //  EntityMoveCheck();  小谷注释
        }
예제 #7
0
        /// <summary>
        /// 状态机执行移动
        /// </summary>
        public override void OnExecuteMove()
        {
            if (RealEntity == null || this.entityType == EntityType.Building)
            {
                return;
            }
            Quaternion DestQuaternion = Quaternion.LookRotation(EntityFSMDirection);
            Quaternion sMidQuater     = Quaternion.Lerp(RealEntity.GetTransform().rotation, DestQuaternion, 10 * Time.deltaTime);

            RealEntity.GetTransform().rotation = sMidQuater;
            float fTimeSpan = Time.realtimeSinceStartup - m_pcGOSSI.fBeginTime;
            float fMoveDist = fTimeSpan * m_pcGOSSI.fServerSpeed;

            m_pcGOSSI.sServerSyncPos = m_pcGOSSI.sServerBeginPos + m_pcGOSSI.sServerDir * fMoveDist;
            RealEntity.PlayerRunAnimation();

            //同步2D位置处理
            Vector3 serverPos2d = new Vector3(m_pcGOSSI.sServerSyncPos.x, 60, m_pcGOSSI.sServerSyncPos.z);
            Vector3 entityPos2d = new Vector3(RealEntity.GetTransform().position.x, 60, RealEntity.GetTransform().position.z);


            Vector3 sSyncDir = serverPos2d - entityPos2d;

            sSyncDir.Normalize();
            float fDistToServerPos = Vector3.Distance(serverPos2d, entityPos2d);

            if (fDistToServerPos > 5)
            {
                RealEntity.GetTransform().position = m_pcGOSSI.sServerSyncPos;
                OnCameraUpdatePosition();
                return;
            }
            Vector3 pos = entityPos2d + sSyncDir * EntityFSMMoveSpeed * Time.deltaTime;

            this.RealEntity.Controller.Move(sSyncDir * EntityFSMMoveSpeed * Time.deltaTime);

            //if (RealEntity.transform.position.y - mDefaultHeight > float.Epsilon)
            //{
            RealEntity.GetTransform().position = new Vector3(RealEntity.GetTransform().position.x, mDefaultHeight, RealEntity.GetTransform().position.z);
            //}

            OnCameraUpdatePosition();
            EntityMoveCheck();
        }
예제 #8
0
        //public bool CheckGuideMove(Vector3 pos) {
        //    if (!SceneGuideTaskManager.Instance().CheckObstructTaskCanMove(pos)) {
        //        RealEntity.PlayerFreeAnimation();
        //        OnCameraUpdatePosition();
        //        if (FSM != null && FSM.State != FsmState.FSM_STATE_FREE)
        //            CGLCtrl_GameLogic.Instance.EmsgToss_AskStopMove();
        //        return false;
        //    }
        //    return true;
        //}

        /// <summary>
        /// 执行强制移动
        /// (好像不能Iselfplay使用,因为没有RealEntity.Collider,暂时不知道在哪里赋值)
        /// 其他对象可以用这个状态,应该是网络慢的情况下,快速移动各对象到正确位置
        /// </summary>
        public override void OnExecuteForceMove()
        {
            //base.OnExecuteForceMove();
            Quaternion DestQuaternion = Quaternion.LookRotation(EntityFSMDirection);
            Quaternion sMidQuater     = Quaternion.Lerp(RealEntity.GetTransform().rotation, DestQuaternion, 10 * Time.deltaTime);

            RealEntity.GetTransform().rotation = sMidQuater;
            float fTimeSpan = Time.realtimeSinceStartup - m_pcGOSSI.fBeginTime;
            float fMoveDist = fTimeSpan * m_pcGOSSI.fForceMoveSpeed;

            m_pcGOSSI.sServerSyncPos = m_pcGOSSI.sServerBeginPos + m_pcGOSSI.sServerDir * fMoveDist;
            SkillMoveConfig skillInfo = ConfigReader.GetSkillMoveConfig(EntitySkillModelId);

            if (skillInfo != null)
            {
                this.RealEntity.PlayerAnimation(skillInfo.action);
            }

            //2D位置同步
            Vector3 serverPos2D = new Vector3(m_pcGOSSI.sServerSyncPos.x, 60, m_pcGOSSI.sServerSyncPos.z);
            Vector3 realPos2D   = new Vector3(RealEntity.GetTransform().position.x, 60, RealEntity.GetTransform().position.z);



            Vector3 sSyncDir = serverPos2D - realPos2D;

            sSyncDir.y = 0;
            sSyncDir.Normalize();
            float fDistToServerPos = Vector3.Distance(serverPos2D, realPos2D);
            float fThisMoveSpeed   = EntityFSMMoveSpeed;

            if (fDistToServerPos > 10)
            {
                RealEntity.GetTransform().position = m_pcGOSSI.sServerBeginPos;
                GameMethod.GetMainCamera.FixedUpdatePosition();
                return;
            }
            Vector3 pos = realPos2D + EntityFSMMoveSpeed * Time.deltaTime * sSyncDir;

            //this.realObject.transform.position = pos;
            this.RealEntity.Controller.Move(sSyncDir * m_pcGOSSI.fForceMoveSpeed * Time.deltaTime);
            GameMethod.GetMainCamera.FixedUpdatePosition();
        }
예제 #9
0
        /// <summary>
        /// 状态机执行Free消息
        /// </summary>
        public override void OnExecuteFree()  //覆盖父类的OnExecuteFree
        {
            if (RealEntity == null || this.entityType == EntityType.Building)
            {
                return;
            }

            //计算平面位置
            Vector3 synPos2D  = new Vector3(m_pcGOSSI.sServerSyncPos.x, 60, m_pcGOSSI.sServerSyncPos.z);                     //服务器传过来的位置
            Vector3 realPos2D = new Vector3(RealEntity.GetTransform().position.x, 60, RealEntity.GetTransform().position.z); //玩家真实位置

            float fDistToServerPos = Vector3.Distance(synPos2D, realPos2D);                                                  //距离差值

            if (fDistToServerPos < 0.5f)                                                                                     //当差值小于0.5时,
            {
                if (EntityStrategyHelper.IsTick(this, EntityStrategyHelper.IdleTimeTick))
                {
                    this.OnFSMStateChange(HolyTech.FSM.EntityIdleFSM.Instance);//进入Idle状态
                    return;
                }
                RealEntity.PlayerFreeAnimation(); //播放free动画
            }
            else if (fDistToServerPos > 5)        //当差值大于5时,
            {
                RealEntity.PlayerFreeAnimation(); //播放free动画
                RealEntity.GetTransform().position = m_pcGOSSI.sServerBeginPos;
            }
            else //当差值在0.5 到5之间
            {
                Vector3 sSyncDir = synPos2D - realPos2D;
                sSyncDir.Normalize();
                Vector3 pos = sSyncDir * 2 * Time.deltaTime + realPos2D;

                RealEntity.PlayerRunAnimation();
                this.RealEntity.Controller.Move(sSyncDir * 2 * Time.deltaTime);//在距离方向上移动过去。
            }

            OnCameraUpdatePosition(); //摄像机为直角度的更新
            TurnAngle();              //转动朝向
        }
예제 #10
0
        /// <summary>
        /// 转动朝向
        /// </summary>
        private void TurnAngle()
        {
            float fAngle = Vector3.Angle(RealEntity.GetTransform().forward, EntityFSMDirection);

            if (fAngle > 2)
            {
                //尝试解决这个问题
                //Look rotation viewing vector is zero
                Quaternion DestQuaternion;
                if (EntityFSMDirection.x == 0 && EntityFSMDirection.y == 0 && EntityFSMDirection.z == 0)
                {
                    DestQuaternion = Quaternion.LookRotation(new Vector3(0.01f, 0, 0));
                }
                else
                {
                    DestQuaternion = Quaternion.LookRotation(EntityFSMDirection);
                }

                Quaternion sMidQuater = Quaternion.Lerp(RealEntity.GetTransform().rotation, DestQuaternion, 5 * Time.deltaTime);
                RealEntity.GetTransform().rotation = sMidQuater;
            }
        }
예제 #11
0
        //
        public void initAreaCircle()
        {
            //if (SceneGuideTaskManager.Instance().IsNewsGuide() == SceneGuideTaskManager.SceneGuideType.NoGuide)
            //    return;
            if (RealEntity == null)
            {
                return;
            }

            if (CircleArea == null)
            {
                string path = GameConstDefine.LoadGameOtherEffectPath;
                //GameObject obj = Resources.Load(path + "guangquan_fanwei") as GameObject;
                ResourceUnit objUnit = ResourcesManager.Instance.loadImmediate(path + "guangquan_fanwei", ResourceType.PREFAB);
                GameObject   obj     = objUnit.Asset as GameObject;

                if (obj == null)
                {
                    GameMethod.DebugError("CircleArea obj null");
                    return;
                }

                //root = GameObject.Instantiate (obj) as GameObject;
                CircleArea = GameObject.Instantiate(obj) as GameObject;
                CircleArea.transform.parent   = RealEntity.GetTransform();
                CircleArea.transform.position = RealEntity.GetTransform().position + new Vector3(0.0f, 0.2f, 0.0f);
                EventCenter.AddListener(EGameEvent.eGameEvent_LocalPlayerRange, UpdataRange);
                CircleArea.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
            }
            CapsuleCollider capsule = RealEntity.GetComponent <CapsuleCollider>();

            if (capsule)
            {
                capsule.enabled = false;
            }
        }