/// <summary> /// 有限状态机状态进入时调用。 /// </summary> /// <param name="fsm">有限状态机引用。</param> protected override void OnEnter(IFsm <Monster> fsm) { base.OnEnter(fsm); hurtTimeCounter = 0; // 积累受伤次数 if (preHurtTime != 0 && Time.time - preHurtTime < 2.5f) { hurtTimes++; } else { preHurtTime = 0; hurtTimes = 0; } // 累积受伤3次,则向后弹一段距离 //if (hurtTimes == 3) { // Vector3 pos = PositionUtility.GetAjustPositionWithMap (fsm.Owner.CachedTransform.position - fsm.Owner.CachedTransform.forward * 2); // fsm.Owner.CachedTransform.DOMove (pos, 0.5f); // hurtTimes = 0; //} // 播放动画 fsm.Owner.ChangeAnimation(FightEntityAnimationState.hurt); // 执行受伤逻辑 int damageHP = fsm.GetData <VarInt> (Constant.EntityData.DamageHP).Value; fsm.Owner.OnDamage(damageHP); preHurtTime = Time.time; }
protected override void OnLeave(IFsm <ProcedureGame> procedureOwner, bool isShutdown) { var editState = procedureOwner.GetData <VarInt>("EditState"); if (editState == ProcedureGame.ConfirmEdit) { GameEntry.TempData.ObjectScene.ConfirmEditToBuilded(); } else if (editState == ProcedureGame.CancelEdit) { GameEntry.TempData.ObjectScene.CancelEdit(); } GameEntry.Event.Fire(this, ReferencePool.Acquire <EvtTempDataUpdated>()); if (!isShutdown) { UIZooView.Inst.UI.m_BtnHand.visible = false; } GameEntry.Fsm.DestroyFsm(m_Fsm); ZooController.Inst.SwipeGesture.onEnd.Remove(OnSwipeEnd); ZooController.Inst.SwipeGesture.onBegin.Remove(OnSwipeBegin); ZooController.Inst.SwipeGesture.onMove.Remove(OnSwipeMove); GameEntry.Event.Unsubscribe(EvtChangeTouchState.EventId, OnEvtChangeTouchState); GameEntry.Event.Unsubscribe(EvtClickScene.EventId, OnEvtClickScene); GameEntry.Event.Unsubscribe(EvtEditRestore.EventId, OnEvtEditRestore); GameEntry.Event.Unsubscribe(EvtEditRotation.EventId, OnEvtEditRotation); Log.Info("StateBuild OnLeave"); base.OnLeave(procedureOwner, isShutdown); }
protected override void OnEnter(IFsm <FsmOwer> fsm) { base.OnEnter(fsm); Log.Debug("进入Status1"); Log.Debug(fsm.GetData("data").GetValue()); SubscribeEvent(1, AAA); }
protected override void OnUpdate(IFsm <ProcedureGame> procedureOwner, float elapseSeconds, float realElapseSeconds) { base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds); if (procedureOwner.GetData <VarInt>("EditState") != ProcedureGame.Editing) { ChangeState <StateNormal>(procedureOwner); } }
//进入流程 public override void OnEnter(IFsm <IProcedureManager> procedureOwner) { m_GotoMenu = false; //返回菜单标志位false //获取游戏类型并初始化 GameMode gameMode = (GameMode)procedureOwner.GetData <VarInt>(Constant.ProcedureData.GameMode).Value; m_CurrentGame = m_Games[gameMode]; m_CurrentGame.Initialize(); }
/// <summary> /// 执行攻击逻辑 /// </summary> /// <param name="fsm"></param> private void Attack(IFsm <Hero> fsm) { WeaponAttackType attackType = (WeaponAttackType)fsm.GetData <VarInt> ("AttackType").Value; switch (attackType) { case WeaponAttackType.手动触发: ManualAttack(fsm); break; case WeaponAttackType.自动触发: break; case WeaponAttackType.技能触发: int weaponID = fsm.GetData <VarInt> ("WeaponID").Value; SkillAttack(fsm, attackType, weaponID); break; } }
/// <summary> /// 有限状态机状态进入时调用。 /// </summary> /// <param name="fsm">有限状态机引用。</param> protected override void OnEnter(IFsm <Hero> fsm) { base.OnEnter(fsm); hurtTimeCounter = 0; fsm.Owner.ChangeAnimation(FightEntityAnimationState.hurt); int damageHP = fsm.GetData <VarInt> (Constant.EntityData.DamageHP).Value; fsm.Owner.OnDamage(damageHP); }
protected internal override void OnEnter(IFsm <ProcedureManager> procedureOwner) { base.OnEnter(procedureOwner); Log.Debug("procedure main enter"); if (procedureOwner.HasData("fromGame")) { bool fromGame = procedureOwner.GetData <bool>("fromGame"); if (fromGame) { Open(UIFormId.detail); } } }
private int m_BackgroundMusicId = 0; //切换场景时的背景音乐 //流程进入回调 public override void OnEnter(IFsm <IProcedureManager> procedureOwner) { m_IsChangeSceneComplete = false; //订阅事件 GameEntry.Event.Subscribe(LoadSceneSuccessEventArgs.EventId, OnLoadSceneSuccess); GameEntry.Event.Subscribe(LoadSceneFailureEventArgs.EventId, OnLoadSceneFailure); GameEntry.Event.Subscribe(LoadSceneUpdateEventArgs.EventId, OnLoadSceneUpdate); GameEntry.Event.Subscribe(LoadSceneDependencyAssetEventArgs.EventId, OnLoadSceneDependencyAsset); //停止所有声音 GameEntry.Sound.StopAllLoadingSounds(); //停止正在加载所有声音 GameEntry.Sound.StopAllLoadedSounds(); //停止加载完成的声音 //隐藏所有实体 GameEntry.Entity.HideAllLoadingEntities(); //加载中的实体 GameEntry.Entity.HideAllLoadedEntities(); //加载完成的实体 //卸载所有场景 string[] loadedSceneAssetNames = GameEntry.Scene.GetLoadedSceneAssetNames(); for (int i = 0; i < loadedSceneAssetNames.Length; i++) { GameEntry.Scene.UnloadScene(loadedSceneAssetNames[i]); } //还原游戏进度 GameEntry.Base.ResetNormalGameSpeed(); //获取场景数据 int sceneId = procedureOwner.GetData <VarInt>(Constant.ProcedureData.NextSceneId).Value; m_ChangeToMenu = sceneId == MenuSceneId; //是否切换到菜单场景 IDataTable <DRScene> dtScene = GameEntry.DataTable.GetDataTable <DRScene>(); DRScene drScene = dtScene.GetDataRow(sceneId); if (drScene == null) { HotLog.Warning("Can not load scene '{0}' from data table.", sceneId.ToString()); return; } //加载场景 GameEntry.Scene.LoadScene(RuntimeAssetUtility.GetSceneAsset(drScene.AssetName), RuntimeConstant.AssetPriority.SceneAsset, this); m_BackgroundMusicId = drScene.BackgroundMusicId; }
protected override void OnLeave(IFsm <ProcedureGame> procedureOwner, bool isShutdown) { var editState = procedureOwner.GetData <VarInt>("EditState"); if (editState == ProcedureGame.ConfirmEdit) { GameEntry.TempData.ObjectScene.ConfirmEditToBuilded(); } else if (editState == ProcedureGame.CancelEdit) { GameEntry.TempData.ObjectScene.CancelEdit(); } GameEntry.Event.Fire(this, ReferencePool.Acquire <EvtTempDataUpdated>()); ZooController.Inst.RefreshScene(); ZooController.Inst.EnableSwipe = true; ZooController.Inst.SwipeGesture.onBegin.Remove(OnSwipeMove); ZooController.Inst.SwipeGesture.onMove.Remove(OnSwipeMove); GameEntry.Event.Unsubscribe(EvtClickScene.EventId, OnEvtClickScene); Log.Info("StateBuildFenceArea OnLeave"); base.OnLeave(procedureOwner, isShutdown); }
protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds) { base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds); VarString nextScene = procedureOwner.GetData <VarString>("NextScene"); SceneLoadEnum next = (SceneLoadEnum)Enum.Parse(typeof(SceneLoadEnum), nextScene); switch (next) { case SceneLoadEnum.CreateRoleScene: UIManger.Instance._UIComponent.OpenUIForm(ConfigEnum.LoadingForm, ConfigEnum.CreateRoleForm); ChangeState <ProcedureCreatePeople>(procedureOwner); SceneManger.Instance._SceneCompent.LoadScene(SceneLoadEnum.CreateRoleScene); break; case SceneLoadEnum.HomeScene: UIManger.Instance._UIComponent.OpenUIForm(ConfigEnum.LoadingForm, ConfigEnum.MainForm); ChangeState <ProcedureHome>(procedureOwner); SceneManger.Instance._SceneCompent.LoadScene(SceneLoadEnum.HomeScene); break; default: break; } }
/// <summary> /// 有限状态机状态轮询时调用。 /// </summary> /// <param name="fsm">有限状态机引用。</param> /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param> /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param> protected override void OnUpdate(IFsm <Monster> fsm, float elapseSeconds, float realElapseSeconds) { base.OnUpdate(fsm, elapseSeconds, realElapseSeconds); if (GlobalGame.IsPause) { ChangeState <MonsterIdleState> (fsm); } atkTimeCounter += elapseSeconds; if (atkTimeCounter > fsm.Owner.MonsterData.AtkAnimTime) { int lockAimID = fsm.GetData <VarInt> (Constant.EntityData.LockAimID).Value; FightEntity aim = (FightEntity)GameEntry.Entity.GetEntity(lockAimID).Logic; if (aim.IsDead == false) { fsm.Owner.transform.LookAt(aim.transform); fsm.Owner.PerformAttack(); } ChangeState <MonsterIdleState> (fsm); } }