private void ExecuteSoundEffect() { var display = GetDisplay(); Jyx2ResourceHelper.LoadAsset <AudioClip>(display.AudioEft, soundEffect => { if (soundEffect == null) { return; } AudioSource.PlayClipAtPoint(soundEffect, Camera.main.transform.position, 1); }); }
static public void PlayMusicAtPath(string path) { if (_currentPlayMusic == path) { return; } Jyx2ResourceHelper.LoadAsset <AudioClip>(path, audioClip => { if (audioClip != null) { var audioSource = GetAudioSource(); audioSource.clip = audioClip; audioSource.Play(); _currentPlayMusic = path; } }); }
void PlayNextStory() { //剧情结束 if (m_CurrentIndex >= m_CurrentStorys.Length) { FinishCurrentMapEvt(); return; } string currentStroy = m_CurrentStorys[m_CurrentIndex].Trim(); m_CurrentIndex++; //跳过注释 if (currentStroy.StartsWith("//")) { PlayNextStory(); return; } var split = currentStroy.Split('*'); string cmd = split[0]; string value = split.Length > 1 ? split[1] : string.Empty; if (string.IsNullOrEmpty(cmd)) { var tmp = value.Split('#'); string roleKey = tmp[0]; string content = tmp[1]; BlockPlayerControl = true; //dialogPanel.Show(roleKey, content, () => //{ // BlockPlayerControl = false; // PlayNextStory(); //}); Jyx2_UIManager.Instance.ShowUI("ChatUIPanel", ChatType.RoleKey, roleKey, content, new Action(() => { BlockPlayerControl = false; PlayNextStory(); })); } else if (cmd == "Select") { var tmp = value.Split('#'); string roleKey = tmp[0]; string content = tmp[1]; List <string> selectionContent = new List <string>(); for (int i = 2; i < tmp.Length; i++) { selectionContent.Add(tmp[i]); } BlockPlayerControl = true; //dialogPanel.ShowSelection(roleKey, content, selectionContent, delegate (int index) //{ // dialogPanel.gameObject.SetActive(false); // BlockPlayerControl = false; // PlayResult(index); //}); Jyx2_UIManager.Instance.ShowUI("ChatUIPanel", ChatType.Selection, roleKey, content, selectionContent, new Action <int>((index) => { BlockPlayerControl = false; PlayResult(index); })); } else if (cmd == "SelectJump") { var tmp = value.Split('#'); string roleKey = tmp[0]; string content = tmp[1]; List <string> selectionContent = new List <string>(); List <string> jumpTo = new List <string>(); for (int i = 2; i < tmp.Length; i++) { var tip = tmp[i].Split(':'); selectionContent.Add(tip[0]); jumpTo.Add(tip[1]); } BlockPlayerControl = true; //dialogPanel.ShowSelection(roleKey, content, selectionContent, delegate (int index) //{ // dialogPanel.gameObject.SetActive(false); // BlockPlayerControl = false; // JumpToTag(jumpTo[index]); //}); Jyx2_UIManager.Instance.ShowUI("ChatUIPanel", ChatType.Selection, roleKey, content, selectionContent, new Action <int>((index) => { BlockPlayerControl = false; JumpToTag(jumpTo[index]); })); } else if (cmd == "NpcMove") { string npcKey = value.Split('#')[0]; GameObject npc = FindNpc(npcKey); if (npc == null) { return; } string navPointPath = value.Split('#')[1]; GameObject navTarget = FindGameObjectOrNext(navPointPath); if (navTarget == null) { return; } var agent = npc.GetComponent <NavMeshAgent>(); agent.destination = navTarget.transform.position; agent.isStopped = false; PlayNextStory(); } else if (cmd == "LookAt") { string npcKey = value.Split('#')[0]; GameObject npc = FindNpc(npcKey); if (npc == null) { return; } string lookToNpcKey = value.Split('#')[1]; GameObject lookToNpc = FindNpc(lookToNpcKey); if (lookToNpc == null) { return; } var lookAtPos = new Vector3(lookToNpc.transform.position.x, npc.transform.position.y, lookToNpc.transform.position.z); npc.transform.DOLookAt(lookAtPos, 0.5f); PlayNextStory(); } else if (cmd == "LookAtObject") { string npcKey = value.Split('#')[0]; GameObject npc = FindNpc(npcKey); if (npc == null) { return; } GameObject lookAt = GetGameObject(value.Split('#')[1]); if (lookAt == null) { return; } var lookAtPos = new Vector3(lookAt.transform.position.x, npc.transform.position.y, lookAt.transform.position.z); npc.transform.DOLookAt(lookAtPos, 0.5f); PlayNextStory(); } else if (cmd == "Music") { Jyx2ResourceHelper.LoadAsset <AudioClip>(value, audioClip => { if (audioClip != null) { m_AudioSource.clip = audioClip; m_AudioSource.Play(); } PlayNextStory(); }); } else if (cmd == "Sound") { Jyx2ResourceHelper.LoadAsset <AudioClip>(value, audioClip => { if (audioClip != null) { m_SoundAudioSource.clip = audioClip; m_SoundAudioSource.Play(); //m_AudioSource.PlayOneShot(audioClip); } PlayNextStory(); }); } else if (cmd == "NpcGuide") { string npcKey = value.Split('#')[0]; GameObject npc = FindNpc(npcKey); if (npc == null) { return; } var mapRole = npc.GetComponent <MapRole>(); mapRole.SetBehavior(MapRoleBehavior.Guide); mapRole.m_BehaviorParas.Clear(); mapRole.m_BehaviorParas.Add(float.Parse(value.Split('#')[1])); mapRole.m_BehaviorParas.Add(float.Parse(value.Split('#')[2])); PlayNextStory(); } else if (cmd == "BlockSuggest") { //fullSuggestPanel.Show(value, PlayNextStory); GameUtil.ShowFullSuggest(value, "", PlayNextStory); } //else if (cmd == "CameraLocalMove") //{ // var tmp = value.Split(','); // followCamera.deltaPos = new Vector3(float.Parse(tmp[0]), float.Parse(tmp[1]), float.Parse(tmp[2])); // PlayNextStory(); //} else if (cmd == "Timeline") { PlayTimeline(value, PlayNextStory); } else if (cmd == "Say") { string npcKey = value.Split('#')[0]; GameObject npc = FindNpc(npcKey); if (npc == null) { return; } var mapRole = npc.GetComponent <MapRole>(); var duration = float.Parse(value.Split('#')[2]); mapRole.Say(value.Split('#')[1], duration); HSUtilsEx.CallWithDelay(this, PlayNextStory, duration); } else if (cmd == "EnableTrigger") { GameObject triggerRoot = GameObject.Find("Level/Triggers"); var t = triggerRoot.transform.Find(value); if (t != null) { t.gameObject.SetActive(true); } } else if (cmd == "DisableTrigger") { GameObject triggerRoot = GameObject.Find("Level/Triggers"); var t = triggerRoot.transform.Find(value); if (t != null) { t.gameObject.SetActive(false); } } else if (cmd == "ShowBattleRole") { foreach (var roleKey in value.Split('#')) { FindNpc(roleKey).SetActive(true); } HSUtilsEx.CallWithDelay(this, PlayNextStory, 0.01f); } else if (cmd == "HideNPC") { foreach (var roleKey in value.Split('#')) { FindNpc(roleKey).SetActive(false); } HSUtilsEx.CallWithDelay(this, PlayNextStory, 0.01f); } else if (cmd == "CreateEnemy") { foreach (var data in value.Split('#')) { var roleKey = data.Split('@')[0]; var pointKey = data.Split('@')[1]; RoleInstance roleInstance = new RoleInstance(roleKey); roleInstance.CreateRoleView(); var pointObj = FindGameObjectOrNext("Level/Dynamic/NPC/" + pointKey); roleInstance.View.SetBehavior(MapRoleBehavior.Enemy); roleInstance.View.transform.SetParent(pointObj.transform, false); roleInstance.View.transform.position = Vector3.zero; roleInstance.View.RefreshModel(); } HSUtilsEx.CallWithDelay(this, PlayNextStory, 0.01f); } else if (cmd == "Battle") { //var m_BattleHelper = FindObjectOfType<BattleHelper>(); int range = 16; bool playerJoin = true; if (!string.IsNullOrEmpty(value)) { if (value.Contains("#")) { range = int.Parse(value.Split('#')[0]); playerJoin = (value.Split('#')[1] == "true") ? true : false; } else { range = int.Parse(value); } } BattleStartParams pa = new BattleStartParams() { range = range, playerJoin = playerJoin, backToBigMap = false, callback = new Action <BattleResult>((result) => { if (result == BattleResult.Win) { PlayResult(0); } else if (result == BattleResult.Lose) { PlayResult(1); } }), }; BattleManager.Instance.StartBattle(pa); //m_BattleHelper.StartBattle(delegate (BattleResult result) //{ // if (result == BattleResult.Win) // { // PlayResult(0); // } // else if (result == BattleResult.Lose) // { // PlayResult(1); // } //}, range, false, playerJoin); } //else if (cmd == "ReplaceSkill") //{ // GameRuntimeData.Instance.Player.Skill = new BattleSkillInstance(value, GameRuntimeData.Instance.Player); // PlayNextStory(); //} else if (cmd == "SetLevel") { GameRuntimeData.Instance.TeamLevel = Convert.ToInt32(value); PlayNextStory(); } else if (cmd == "ForceChangePlayerWeapon") { //GameRuntimeData.Instance.Player.View.ChangeWeaponTo(int.Parse(value)); PlayNextStory(); } else if (cmd == "Select") { PlayResult(0); } else if (cmd == "Join") { if (GameRuntimeData.Instance == null || GameRuntimeData.Instance.Team == null || GameRuntimeData.Instance.Team.Find(r => r.Key == value) != null) { PlayNextStory(); return; } var role = MapRuntimeData.Instance.Roles.Find(r => { return(r.Key == value); }); role.View.SetBehavior(MapRoleBehavior.Teammate); role.View.m_BehaviorParas.Add(32); GameRuntimeData.Instance.Team.Add(role); //加入到当前队伍 if (GameRuntimeData.Instance.CurrentTeam.Count < 4 && GameRuntimeData.Instance.Team.Contains(role) && !GameRuntimeData.Instance.CurrentTeam.Contains(role)) { GameRuntimeData.Instance.CurrentTeam.Add(role); } Debug.Log($"队伍人数:{GameRuntimeData.Instance.Team.Count}"); //fullSuggestPanel.Show(value + "加入队伍!", PlayNextStory); GameUtil.ShowFullSuggest(value, "", PlayNextStory); PlayNextStory(); } else if (cmd == "ExploreJoin") { if (GameRuntimeData.Instance == null || GameRuntimeData.Instance.Team == null || GameRuntimeData.Instance.Team.Find(r => r.Key == value) != null) { PlayNextStory(); return; } var role = MapRuntimeData.Instance.Roles.Find(r => { return(r.Key == value); }); role.View.SetBehavior(MapRoleBehavior.Teammate); role.View.m_BehaviorParas.Add(32); MapRuntimeData.Instance.ExploreTeam.Add(role); //fullSuggestPanel.Show(value + "临时加入队伍!", PlayNextStory); GameUtil.ShowFullSuggest(value, "", PlayNextStory); PlayNextStory(); } else if (cmd == "ClearTeammate") { if (GameRuntimeData.Instance == null || GameRuntimeData.Instance.Team == null) { PlayNextStory(); return; } if (GameRuntimeData.Instance.Team.Count > 1) { GameRuntimeData.Instance.Team.RemoveRange(1, GameRuntimeData.Instance.Team.Count - 1); } Debug.Log($"队伍人数:{GameRuntimeData.Instance.Team.Count}"); PlayNextStory(); } else if (cmd == "Popinfo") { DisplayPopInfo(value); PlayNextStory(); } else if (cmd == "MiddleTopSuggest") { //middleTopMessageSuggestPanel.Show(value); Jyx2_UIManager.Instance.ShowUI("CommonTipsUIPanel", TipsType.MiddleTop, value); PlayNextStory(); } else if (cmd == "Judge") //跳转指令 { //string conditionJudgeContent = value.Split('#')[0]; //string jumpTag = value.Split('#')[1]; ////如果满足条件则跳转,否则向下执行 //if (TriggerManager.IsTrue(conditionJudgeContent)) //{ // if (IsJumpTag(jumpTag)) // { // JumpToTag(jumpTag); // } // else // { // Debug.LogError("剧本配置错误,跳转标签格式不对,应该用[]括起来"); // } //} //else //{ // PlayNextStory(); //} } else if (cmd == "Goto" || cmd == "Jump") { JumpToTag(value); } else if (cmd == "Money") { int add = int.Parse(value); if (add != 0) { //RuntimeHelper.Instance.AddMoney(add); if (add > 0) { DisplayPopInfo($"获得银两 {add}"); } else { DisplayPopInfo($"减少银两 {-add}"); } } PlayNextStory(); } else if (cmd == "SetKey") //设置一个KeyValue { runtime.SetKeyValues(value.Split('#')[0], value.Split('#')[1]); PlayNextStory(); } else if (cmd == "ResetTeamStatus") //恢复探索队伍血量,复活死亡队友 { foreach (var role in MapRuntimeData.Instance.ExploreTeam) { role.Resurrect(); } PlayNextStory(); } else if (cmd == "Transport") { var levelMaster = FindObjectOfType <LevelMaster>(); levelMaster.Transport(value); PlayNextStory(); } else if (IsJumpTag(cmd)) //这是一个跳转标签,直接往下播放 { PlayNextStory(); } else if (cmd.ToLower() == "end") //直接结束当前剧情 { if (!string.IsNullOrEmpty(value)) //如果有指定结果,则直接跳转 { FinishCurrentMapEvt(int.Parse(value)); } else//直接指针移到队尾 { m_CurrentIndex = m_CurrentStorys.Length; PlayNextStory(); } } }