Ejemplo n.º 1
0
        private void CheckGroundStatus(ComponentMove rCompMove, ComponentAnimator rCompAnim)
        {
            RaycastHit rHitInfo;
            Vector3    rActorPos = rCompMove.Trans.position + Vector3.up * 1.0f;

#if UNITY_EDITOR
            Debug.DrawLine(rActorPos, rActorPos + Vector3.down * rCompMove.groundCheckDistance);
#endif
            if (Physics.Raycast(rActorPos, Vector3.down, out rHitInfo, rCompMove.groundCheckDistance, 1 << LayerMask.NameToLayer("Road")))
            {
                rCompMove.mGroundNormal = rHitInfo.normal;
                rCompMove.mGroundedY    = rHitInfo.point.y;
            }
            else
            {
                rCompMove.mGroundNormal = Vector3.up;
                rCompMove.mGroundedY    = 0;
            }

            ApplyExtraRatation(rCompMove);
        }
Ejemplo n.º 2
0
        private void Move(ComponentMove rCompMove, ComponentAnimator rCompAnim)
        {
            if (rCompMove.MoveSpeed.magnitude > 1.0f)
            {
                rCompMove.MoveSpeed.Normalize();
            }

            rCompMove.MoveSpeed = rCompMove.Trans.InverseTransformDirection(rCompMove.MoveSpeed);
            CheckGroundStatus(rCompMove, rCompAnim);
            rCompMove.MoveSpeed      = Vector3.ProjectOnPlane(rCompMove.MoveSpeed, rCompMove.mGroundNormal);
            rCompMove.mTurnAmount    = Mathf.Atan2(rCompMove.MoveSpeed.x, rCompMove.MoveSpeed.z);
            rCompMove.mForwardAmount = rCompMove.MoveSpeed.z;

            // 和墙体的碰撞检测
            rCompMove.MoveSpeed = Move_RayForword(rCompMove, rCompMove.MoveSpeed);

            bool bIsMove = !rCompMove.MoveSpeed.Equals(Vector3.zero);

            rCompMove.Trans.Translate(rCompMove.MoveSpeed * 0.075f * (rCompAnim.IsRun ? 2 : 1));
            rCompMove.Trans.position = new Vector3(rCompMove.Trans.position.x, rCompMove.mGroundedY, rCompMove.Trans.position.z);

            // 应用角色的行走动画
            // ApplyAnimation(bIsMove, rCompAnim.IsRun);
        }
Ejemplo n.º 3
0
        public async Task Create(ActorNet rNetActor, Vector3 rBornPos)
        {
            // 创建Component net
            this.CompNet          = this.AddComponent <ComponentNet>();
            this.CompNet.NetActor = rNetActor;

            // 创建Component Professional
            ActorProfessional rProfessional = GameConfig.Instance.GetActorProfessional(rNetActor.ProfessionalID);

            if (rProfessional == null)
            {
                Debug.LogErrorFormat("Cannot find professional ID: {0}", rNetActor.ProfessionalID);
                return;
            }
            this.CompPrefessional = this.AddComponent <ComponentProfessional>();
            this.CompPrefessional.Professional = rProfessional;

            // 创建Component Hero
            ActorHero rHero = GameConfig.Instance.GetHero(rProfessional.HeroID);

            if (rHero == null)
            {
                Debug.LogErrorFormat("Cannot find hero ID: {0}", rProfessional.HeroID);
                return;
            }
            this.CompHero      = this.AddComponent <ComponentHero>();
            this.CompHero.Hero = rHero;

            // 创建Component Avatar
            ActorAvatar rAvatar = GameConfig.Instance.GetAvatar(rHero.AvatarID);

            if (rAvatar == null)
            {
                Debug.LogErrorFormat("Cannot find avatar ID: {0}", rHero.AvatarID);
                return;
            }
            this.CompAvatar        = this.AddComponent <ComponentAvatar>();
            this.CompAvatar.Avatar = rAvatar;

            // 根据Avatar加载角色
            var rAvatarRequest = await AvatarAssetLoader.Instance.Load(this.CompAvatar.Avatar.ABPath, this.CompAvatar.Avatar.AssetName);

            if (rAvatarRequest.AvatarGo == null)
            {
                Debug.LogError("Avatar load failed..");
                return;
            }

            // 创建Component GameObject
            this.CompUnitGo            = this.AddComponent <ComponentUnityGo>();
            this.CompUnitGo.GameObject = rAvatarRequest.AvatarGo;

            // 创建Component Unity Animator
            this.CompUnityAnimator          = this.AddComponent <ComponentUnityAnimator>();
            this.CompUnityAnimator.Animator = rAvatarRequest.AvatarGo.GetComponent <Animator>();

            // 创建其他的Component
            this.CompAnimator = this.AddComponent <ComponentAnimator>();

            this.CompCollider        = this.AddComponent <ComponentCollider>();
            this.CompCollider.Radius = rHero.Radius;
            this.CompCollider.Height = rHero.Height;

            this.CompMove = this.AddComponent <ComponentMove>();

            this.CompTrans          = this.AddComponent <ComponentTransform>();
            this.CompTrans.Position = rBornPos;
            this.CompTrans.Forward  = Vector3.forward;
            this.CompTrans.Scale    = Vector3.one * rHero.Scale;

            this.CompInput = this.AddComponent <ComponentInput>();
        }