void DoJump()
        {
            var roleGameOE = RoleMgr.GetInstance().GetMainRole();
            var jumpState  = EntityManager.GetComponentData <JumpData>(roleGameOE.Entity);
            var isMaxJump  = jumpState.JumpCount >= GameConst.MaxJumpCount;

            if (isMaxJump)
            {
                //已经最高跳段了,就不能再跳
                return;
            }
            RoleMgr.GetInstance().StopMainRoleRunning();
            var actionData = EntityManager.GetComponentData <ActionData>(roleGameOE.Entity);

            actionData.Jump = 1;
            EntityManager.SetComponentData <ActionData>(roleGameOE.Entity, actionData);
            //这里的timeline只作跳跃中的表现,如加粒子加女主尾巴等,状态和高度控制还是放在MovementUpdateSystem里,因为跳跃这个动作什么时候结束是未知的,你可能跳崖了,这时跳跃状态会一直维持至到碰到地面,所以不方便放在timeline里。
            var newJumpCount = math.clamp(jumpState.JumpCount + 1, 0, GameConst.MaxJumpCount);
            var roleInfo     = roleGameOE.GetComponent <RoleInfo>();
            var assetPath    = ResPath.GetRoleJumpResPath(roleInfo.Career, newJumpCount);
            var timelineInfo = new TimelineInfo {
                ResPath = assetPath, Owner = roleGameOE.Entity, StateChange = null
            };
            var uid = EntityManager.GetComponentData <UID>(roleGameOE.Entity);

            TimelineManager.GetInstance().AddTimeline(uid.Value, timelineInfo, EntityManager);
        }
        void CastSkill(int skillIndex = -1)
        {
            var roleGameOE = RoleMgr.GetInstance().GetMainRole();
            var roleInfo   = roleGameOE.GetComponent <RoleInfo>();
            var skillID    = SkillManager.GetInstance().GetSkillIDByIndex(skillIndex);

            string assetPath      = GameConst.GetRoleSkillResPath(skillID);
            bool   isNormalAttack = skillIndex == -1;//普通攻击

            if (!isNormalAttack)
            {
                SkillManager.GetInstance().ResetCombo();//使用非普攻技能时就重置连击索引
            }
            var uid = EntityManager.GetComponentData <UID>(roleGameOE.Entity);
            Action <TimelineInfo.Event> afterAdd = null;

            if (isNormalAttack)
            {
                //普攻的话增加连击索引
                afterAdd = (TimelineInfo.Event e) =>
                {
                    if (e == TimelineInfo.Event.AfterAdd)
                    {
                        SkillManager.GetInstance().IncreaseCombo();
                    }
                };
            }
            var timelineInfo = new TimelineInfo {
                ResPath = assetPath, Owner = roleGameOE.Entity, StateChange = afterAdd
            };

            TimelineManager.GetInstance().AddTimeline(uid.Value, timelineInfo, EntityManager);
        }
Exemple #3
0
        private void HandleCastSkill(SprotoType.scene_fight_event_info fight_event)
        {
            long   uid          = fight_event.attacker_uid;
            Entity scene_entity = SceneMgr.Instance.GetSceneObject(uid);
            var    isMainRole   = RoleMgr.GetInstance().IsMainRoleEntity(scene_entity);

            // isMainRole = false;//test
            if (scene_entity == Entity.Null || isMainRole)
            {
                return;
            }

            //TODO:预先判断是否能使用技能
            bool is_can_cast = true;

            if (!is_can_cast)
            {
                return;
            }

            string assetPath = SkillManager.GetInstance().GetSkillResPath((int)fight_event.skill_id);

            Debug.Log("OnAckFightEvents assetPath : " + assetPath);
            var param = new Dictionary <string, object>();

            param["FlyHurtWord"] = fight_event.defenders;
            var timelineInfo = new TimelineInfo {
                ResPath = assetPath, Owner = scene_entity, Param = param
            };

            TimelineManager.GetInstance().AddTimeline(uid, timelineInfo, SceneMgr.Instance.EntityManager);
        }
Exemple #4
0
        private void HandleCastSkill(SprotoType.scene_skill_event_info skillEvent)
        {
            long   uid          = skillEvent.attacker_uid;
            Entity scene_entity = SceneMgr.Instance.GetSceneObject(uid);
            var    isMainRole   = RoleMgr.GetInstance().IsMainRoleEntity(scene_entity);

            // isMainRole = false;//test
            if (scene_entity == Entity.Null || isMainRole)
            {
                return;
            }

            //更新朝向
            Transform trans = SceneMgr.Instance.EntityManager.GetComponentObject <Transform>(scene_entity);

            // trans.rotation = Quaternion.Euler(trans.eulerAngles.x, skillEvent.direction/100, trans.eulerAngles.z);
            trans.LookAt(new Vector3(skillEvent.target_pos_x / GameConst.RealToLogic, trans.localPosition.y, skillEvent.target_pos_z / GameConst.RealToLogic));

            //播放攻击动作
            string assetPath = SkillManager.GetInstance().GetSkillResPath((int)skillEvent.skill_id);
            // Debug.Log("OnAckFightEvents assetPath : "+assetPath);
            // var param = new Dictionary<string, object>();
            // param["FlyHurtWord"] = event.defenders;
            var timelineInfo = new TimelineInfo {
                ResPath = assetPath, Owner = scene_entity, Param = null
            };

            TimelineManager.GetInstance().AddTimeline(uid, timelineInfo, SceneMgr.Instance.EntityManager);
        }
        private void GenNameboardLooksNode(Entity owner, NameboardData nameboardData)
        {
            if (!EntityManager.Exists(owner))
            {
                return;
            }
            var looksNode = ResMgr.GetInstance().GetGameObject("Nameboard");

            looksNode.transform.SetParent(nameboardCanvas);
            looksNode.transform.localScale = new Vector3(-1, 1, 1);
            var    nameboardBehav = looksNode.GetComponent <Nameboard>();
            var    uid            = EntityManager.GetComponentData <UID>(owner);
            string name           = SceneMgr.Instance.GetNameByUID(uid.Value);
            // nameboardBehav.Name = name;
            var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(owner);

            nameboardBehav.CurColorStyle = isMainRole ? Nameboard.ColorStyle.Green : Nameboard.ColorStyle.Red;
            nameboardData.LooksNode      = looksNode.transform;
            nameboardData.UIResState     = NameboardData.ResState.Loaded;
            nameboardData.SetName(name);
            bool hasHPData = EntityManager.HasComponent <HealthStateData>(owner);

            if (hasHPData)
            {
                var hpData = EntityManager.GetComponentData <HealthStateData>(owner);
                nameboardBehav.MaxHp = hpData.MaxHp;
                nameboardBehav.CurHp = hpData.CurHp;
            }

            var sceneObjType = EntityManager.GetComponentData <SceneObjectTypeData>(owner);

            nameboardBehav.SetBloodVisible(sceneObjType.Value == SceneObjectType.Role || sceneObjType.Value == SceneObjectType.Monster);
        }
Exemple #6
0
        private void ApplyChangeInfoSceneChange(Entity entity, SprotoType.info_item change_info)
        {
            //本条信息变更只会收到自己的
            var mainRoleGOE = RoleMgr.GetInstance().GetMainRole();

            entity = mainRoleGOE != null?mainRoleGOE.Entity:Entity.Null;
            // Debug.Log("ApplyChangeInfoSceneChange : "+change_info.value+" entity:"+entity);
            string[] strs    = change_info.value.Split(',');
            int      sceneID = int.Parse(strs[0]);

            LoadingView.Instance.SetActive(true);
            LoadingView.Instance.ResetData();
            SceneMgr.Instance.LoadScene(sceneID);

            if (entity != Entity.Null && SceneMgr.Instance.EntityManager.Exists(entity))
            {
                long      new_x = Int64.Parse(strs[2]);
                long      new_y = Int64.Parse(strs[3]);
                long      new_z = Int64.Parse(strs[4]);
                Transform trans = SceneMgr.Instance.EntityManager.GetComponentObject <Transform>(entity);
                trans.localPosition = SceneMgr.Instance.GetCorrectPos(new Vector3(new_x / GameConst.RealToLogic, new_y / GameConst.RealToLogic, new_z / GameConst.RealToLogic));
                SceneMgr.Instance.EntityManager.SetComponentData(entity, new TargetPosition {
                    Value = trans.localPosition
                });
                long uid = Int64.Parse(strs[1]);
                SceneMgr.Instance.ChangeRoleUID(entity, uid);
                mainRoleGOE.name = "MainRole_" + uid;
                // SceneMgr.Instance.EntityManager.SetComponentData<UID>(entity, new UID{Value=uid});
                // MoveQuery moveQuery = SceneMgr.Instance.EntityManager.GetComponentObject<MoveQuery>(entity);
                // if (moveQuery != null)
                //     moveQuery.ChangeUID(uid);
            }
        }
Exemple #7
0
        void DoJump()
        {
            var roleGameOE = RoleMgr.GetInstance().GetMainRole();
            var jumpState  = EntityManager.GetComponentData <JumpState>(roleGameOE.Entity);

            if (jumpState.JumpStatus == JumpState.State.None)
            {
                jumpState.JumpCount = 0;
                EntityManager.SetComponentData <JumpState>(roleGameOE.Entity, jumpState);
            }
            var isMaxJump = jumpState.JumpCount >= GameConst.MaxJumpCount;

            if (isMaxJump)
            {
                //已经最高跳段了,就不能再跳
                return;
            }
            var newJumpCount = math.clamp(jumpState.JumpCount + 1, 0, GameConst.MaxJumpCount);
            var roleInfo     = roleGameOE.GetComponent <RoleInfo>();
            var assetPath    = GameConst.GetRoleJumpResPath(roleInfo.Career, newJumpCount);
            var timelineInfo = new TimelineInfo {
                ResPath = assetPath, Owner = roleGameOE.Entity, StateChange = null
            };
            var uid = EntityManager.GetComponentData <UID>(roleGameOE.Entity);

            TimelineManager.GetInstance().AddTimeline(uid.Value, timelineInfo, EntityManager);
        }
Exemple #8
0
        private void HandleHurtEvent(SprotoType.scene_hurt_event_info hurtEvent)
        {
            // long uid = hurtEvent.attacker_uid;
            var entityMgr = SceneMgr.Instance.EntityManager;

            if (hurtEvent.defenders == null || hurtEvent.defenders.Count <= 0)
            {
                return;
            }
            for (int i = 0; i < hurtEvent.defenders.Count; i++)
            {
                var defender = hurtEvent.defenders[i];
                // Debug.Log("defender uid : "+defender.uid+" count:"+hurtEvent.defenders.Count+" hp:"+defender.cur_hp+" damagetype:"+defender.flag);
                var defenderEntity = SceneMgr.Instance.GetSceneObject(defender.uid);
                // Debug.Log("has LocomotionState : "+entityMgr.HasComponent<LocomotionState>(defenderEntity)+" isdead:"+ECSHelper.IsDead(defenderEntity, entityMgr)+" isnull:"+defenderEntity.Equals(Entity.Null));
                if (defenderEntity.Equals(Entity.Null) || ECSHelper.IsDead(defenderEntity, entityMgr))
                {
                    continue;
                }
                if (entityMgr.HasComponent <LocomotionState>(defenderEntity))
                {
                    var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(defenderEntity);
                    //进入受击状态
                    bool playBehit = UnityEngine.Random.RandomRange(0, 100) > 30.0f;
                    if (!isMainRole && playBehit)
                    {
                        var locomotionState = entityMgr.GetComponentData <LocomotionState>(defenderEntity);
                        locomotionState.LocoState    = LocomotionState.State.BeHit;
                        locomotionState.StateEndType = LocomotionState.EndType.PlayAnimationOnce;
                        // locomotionState.StartTime = Time.time;
                        entityMgr.SetComponentData <LocomotionState>(defenderEntity, locomotionState);
                    }
                    bool isNeedShakeCamera = (isMainRole && playBehit) || !isMainRole;
                    if (isNeedShakeCamera && entityMgr.HasComponent <CinemachineImpulseSource>(defenderEntity))
                    {
                        var impulseCom = entityMgr.GetComponentObject <CinemachineImpulseSource>(defenderEntity);
                        var velocity   = Vector3.one * defender.change_num / 5;
                        impulseCom.GenerateImpulse();
                    }
                    if (entityMgr.HasComponent <BeHitEffect>(defenderEntity))
                    {
                        var behitEffect = entityMgr.GetComponentObject <BeHitEffect>(defenderEntity);
                        behitEffect.EndTime = TimeEx.ServerTime + 300;
                        behitEffect.Status  = EffectStatus.WaitForRender;
                    }
                    //显示战斗飘字
                    var          defenderTrans = entityMgr.GetComponentObject <Transform>(defenderEntity);
                    var          flyWordObj    = ResMgr.GetInstance().GetGameObject("FightFlyWord");
                    FightFlyWord flyWord       = flyWordObj.GetComponent <FightFlyWord>();
                    flyWord.SetData(defender.change_num, defender.flag);
                    var pos = defenderTrans.position;
                    pos += Vector3.up * 1;
                    flyWord.transform.SetParent(UnityMMO.SceneMgr.Instance.FlyWordContainer);
                    flyWord.transform.position = pos;
                    flyWord.StartFly();
                }
                ChangeHP(defenderEntity, defender.cur_hp, defender.flag, hurtEvent.attacker_uid);
            }
        }
Exemple #9
0
        private void ChangeHP(Entity entity, long hp, long flag, long attackerUID)
        {
            float curHp      = (float)hp;
            var   healthData = SceneMgr.Instance.EntityManager.GetComponentData <HealthStateData>(entity);

            healthData.CurHp = curHp;
            SceneMgr.Instance.EntityManager.SetComponentData(entity, healthData);
            bool hasNameboardData = SceneMgr.Instance.EntityManager.HasComponent <NameboardData>(entity);
            var  isRelive         = flag == 5; //复活
            var  isDead           = hp == 0;   //死亡

            if (hasNameboardData)
            {
                var nameboardData = SceneMgr.Instance.EntityManager.GetComponentData <NameboardData>(entity);
                if (nameboardData.UIResState == NameboardData.ResState.Loaded)
                {
                    var nameboardNode = SceneMgr.Instance.EntityManager.GetComponentObject <Nameboard>(nameboardData.UIEntity);
                    if (nameboardNode != null)
                    {
                        nameboardNode.CurHp = curHp;
                        //remove nameboard when dead
                        if (isDead)
                        {
                            SceneMgr.Instance.World.RequestDespawn(nameboardNode.gameObject);
                            nameboardData.UIResState = NameboardData.ResState.DontLoad;
                            nameboardData.UIEntity   = Entity.Null;
                            SceneMgr.Instance.EntityManager.SetComponentData(entity, nameboardData);
                        }
                    }
                }
                else if (nameboardData.UIResState == NameboardData.ResState.DontLoad)
                {
                    // var isRelive = flag==5;
                    Debug.Log("isRelive : " + isRelive);
                    if (isRelive)
                    {
                        nameboardData.UIResState = NameboardData.ResState.WaitLoad;
                        SceneMgr.Instance.EntityManager.SetComponentData(entity, nameboardData);
                    }
                }
            }
            if (isDead || isRelive)
            {
                // var isRelive = strs[1]=="relive";
                var locoState = SceneMgr.Instance.EntityManager.GetComponentData <LocomotionState>(entity);
                locoState.LocoState = isRelive?LocomotionState.State.Idle:LocomotionState.State.Dead;
                Debug.Log("Time : " + TimeEx.ServerTime.ToString() + " isRelive:" + isRelive + " state:" + locoState.LocoState.ToString());
                // locoState.StartTime = Time.time - (TimeEx.ServerTime-change_info.time)/1000.0f;//CAT_TODO:dead time
                SceneMgr.Instance.EntityManager.SetComponentData(entity, locoState);
                if (isDead && RoleMgr.GetInstance().IsMainRoleEntity(entity))
                {
                    // var attackerName = SceneMgr.Instance.GetNameByUID(attackerUID);
                    XLuaFramework.CSLuaBridge.GetInstance().CallLuaFuncNum(GlobalEvents.MainRoleDie, attackerUID);
                }
            }
        }
Exemple #10
0
        void TestSkill1()
        {
            string assetPath = "Assets/AssetBundleRes/role/career_2/skill/timeline/Attack.playable";

            ResourceManager.GetInstance().LoadAsset <PlayableAsset>(assetPath, delegate(UnityEngine.Object[] objs)
            {
                if (objs == null || objs.Length <= 0)
                {
                    return;
                }
                var mainRole                 = RoleMgr.GetInstance().GetMainRole();
                var playerDirector           = mainRole.GetComponent <PlayableDirector>();
                playerDirector.playableAsset = objs[0] as PlayableAsset;
                var animator                 = mainRole.GetComponentInChildren <Animator>();
                Debug.Log("animator : " + (animator != null).ToString());
                // EntityManager.GetComponentData<
                // mainRole.transform.Find("")
                Dictionary <string, PlayableBinding> bindingDict = new Dictionary <string, PlayableBinding>();
                foreach (var at in playerDirector.playableAsset.outputs)
                {
                    // if (!bindingDict.ContainsKey(at.streamName))
                    // {
                    //     Debug.Log("at.streamName : "+at.streamName);
                    //     bindingDict.Add(at.streamName, at);
                    // }
                    if (at.streamName.StartsWith("AnimationTrack"))
                    {
                        playerDirector.SetGenericBinding(at.sourceObject, animator);
                    }
                    else if (at.streamName.StartsWith("ParticleTrack"))
                    {
                        var ct = at.sourceObject as ControlTrack;
                        Debug.Log(" ct : " + (ct != null).ToString());
                        var looksInfo      = EntityManager.GetComponentData <LooksInfo>(mainRole.Entity);
                        var looksEntity    = looksInfo.LooksEntity;
                        var looksTrans     = EntityManager.GetComponentObject <Transform>(looksEntity);
                        var particleParent = looksTrans.Find("root");
                        foreach (var info in ct.GetClips())
                        {
                            Debug.Log("info.displayName : " + info.displayName);
                            if (info.displayName == "particle")
                            {
                                var cpa = info.asset as ControlPlayableAsset;
                                Debug.Log(" cpa : " + (cpa != null).ToString());
                                Debug.Log("cpa.sourceGameObject.exposedName : " + cpa.sourceGameObject.exposedName);
                                playerDirector.SetReferenceValue(cpa.sourceGameObject.exposedName, particleParent.gameObject);
                            }
                        }
                    }
                }
                playerDirector.Play();
            });
        }
Exemple #11
0
        public void CastSkill(int skillID)
        {
            // var skillID = GetSkillIDByIndex(skillIndex);
            var isInCD = IsSkillInCD(skillID);

            if (isInCD)
            {
                XLuaFramework.CSLuaBridge.GetInstance().CallLuaFuncStr(GlobalEvents.MessageShow, "技能冷却中...");
                return;
            }
            var roleGameOE = RoleMgr.GetInstance().GetMainRole();
            var roleInfo   = roleGameOE.GetComponent <RoleInfo>();

            string assetPath      = ResPath.GetRoleSkillResPath(skillID);
            bool   isNormalAttack = IsNormalAttack(skillID);//普通攻击

            // Debug.Log("isNormalAttack : "+isNormalAttack);
            if (!isNormalAttack)
            {
                ResetCombo();//使用非普攻技能时就重置连击索引
            }
            var uid = SceneMgr.Instance.EntityManager.GetComponentData <UID>(roleGameOE.Entity);
            Action <TimelineInfo.Event> afterAdd = null;

            if (isNormalAttack)
            {
                //普攻的话增加连击索引
                afterAdd = (TimelineInfo.Event e) =>
                {
                    if (e == TimelineInfo.Event.AfterAdd)
                    {
                        IncreaseCombo();
                    }
                };
            }
            var timelineInfo = new TimelineInfo {
                ResPath = assetPath, Owner = roleGameOE.Entity, StateChange = afterAdd
            };

            TimelineManager.GetInstance().AddTimeline(uid.Value, timelineInfo, SceneMgr.Instance.EntityManager);
        }
        public void SampleInput(ref UserCommand command, float deltaTime)
        {
            Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
            // GameInput.GetInstance().JoystickDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
            float angle = Vector2.Angle(Vector2.up, moveInput);

            if (moveInput.x < 0)
            {
                angle = 360 - angle;
            }
            float magnitude = Mathf.Clamp(moveInput.magnitude, 0, 1);

            command.moveYaw       = angle;
            command.moveMagnitude = magnitude;

            var roleGameOE = RoleMgr.GetInstance().GetMainRole();

            EntityManager.SetComponentData <ActionData>(roleGameOE.Entity, ActionData.Empty);

            float invertY = 1.0f;

            Vector2 deltaMousePos = new Vector2(0, 0);

            if (deltaTime > 0.0f)
            {
                deltaMousePos += new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y") * invertY);
            }

            const float configMouseSensitivity = 1.5f;

            command.lookYaw += deltaMousePos.x * configMouseSensitivity;
            command.lookYaw  = command.lookYaw % 360;
            while (command.lookYaw < 0.0f)
            {
                command.lookYaw += 360.0f;
            }

            command.lookPitch += deltaMousePos.y * configMouseSensitivity;
            command.lookPitch  = Mathf.Clamp(command.lookPitch, 0, 180);

            command.jump   = (command.jump != 0 || Input.GetKeyDown(KeyCode.Space))?1:0;
            command.sprint = (command.sprint != 0 || Input.GetKey(KeyCode.LeftShift))?1:0;

            if (GameInput.GetInstance().GetKeyUp(KeyCode.J))
            {
                SkillManager.GetInstance().CastSkillByIndex(-1);
            }
            else if (GameInput.GetInstance().GetKeyUp(KeyCode.I))
            {
                SkillManager.GetInstance().CastSkillByIndex(0);
            }
            else if (GameInput.GetInstance().GetKeyUp(KeyCode.O))
            {
                SkillManager.GetInstance().CastSkillByIndex(1);
            }
            else if (GameInput.GetInstance().GetKeyUp(KeyCode.K))
            {
                SkillManager.GetInstance().CastSkillByIndex(2);
            }
            else if (GameInput.GetInstance().GetKeyUp(KeyCode.L))
            {
                SkillManager.GetInstance().CastSkillByIndex(3);
            }
            else if (GameInput.GetInstance().GetKeyUp(KeyCode.Space))
            {
                DoJump();
            }
        }
Exemple #13
0
 private void OnEnable()
 {
     mainRoleGOE       = RoleMgr.GetInstance().GetMainRole();
     mainRoleTrans     = mainRoleGOE.transform;
     mainRoleMoveQuery = mainRoleGOE.GetComponent <MoveQuery>();
 }