123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityGameFramework.Runtime;
- using System;
- using YLTask;
- using TMPro;
- public enum NpcInteractiveType
- {
- Function = 0, // 功能
- Main, // 主线
- Daily, // 日常
- College, // 学院
- Wanted, // 悬赏
- About, // 关于
- Leave // 离开
- }
- public class NpcInfoVo
- {
- public NpcInfoVo(int id, Role r)
- {
- npcId = id;
- role = r;
- }
- public int npcId;
- public Role role;
- public SceneEventNpcLogic npcLogic;
- }
- public class SceneEventNpcLogic : MonoBehaviour
- {
- public GameObject mapIconObj = null;
- public SceneEventNpc info = null;
- private bool isEntry = false;
- Button btnInteractive;
- NpcInfoVo npcVo = null;
- GameObject signObj = null;
- static bool isOpen = false;
- Collider nowCollider = null;
- private void Awake()
- {
- isEntry = false;
- info = this.gameObject.GetComponent<SceneEventNpc>();
- }
- // Start is called before the first frame update
- void Start()
- {
- NpcManager.Instance.AddNpcItem(this);
- AddNameBillboard();
- AddNpcSignToMiniMap(mapIconObj);
- RefreshCollider();
- }
- private void OnEnable()
- {
- // 解锁状态
- int curMapId = UserProxy.Instance.player.newMap.curMapId;
- List<string> unlockInfo = MapProxy.Instance.getMapUnlockInfoList(curMapId);
- foreach (var item in unlockInfo)
- {
- string[] unlock = item.Split('_');
- if (curMapId != int.Parse(unlock[0]))
- {
- continue;
- }
- if (int.Parse(unlock[1]) != (int)(SceneEventExplore.ExploreType.Npc))
- {
- continue;
- }
- if (info.npcId == int.Parse(unlock[2]))
- {
- AnimUnlock();
- }
- }
- }
- public void AnimLock()
- {
- Animator anim = GetComponent<Animator>();
- anim.Play("lock", 0);
- }
- public void AnimUnlock()
- {
- Animator anim = GetComponent<Animator>();
- anim.Play("unlock", 0);
- }
- public void AddNameBillboard()
- {
- ResourceHelper.Instance.LoadAssetBundle("NameBillboard", ab =>
- {
- if (ab != null)
- {
- GameObject billboard = (GameObject)Instantiate(ab.LoadAsset("NameBillboard"));
- billboard.SetActive(true);
- billboard.transform.SetParent(this.transform);
- billboard.transform.localRotation = Quaternion.identity;
- TextMesh tm = billboard.transform.Find("NameBillboard").GetComponent<TextMesh>();
- sm_npc npcInfo = sm_npc.GetMoById(info.npcId);
- tm.text = npcInfo.name;
- }
- });
- }
- public void OnTriggerEnter(Collider collider)
- {
- nowCollider = null;
- if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
- {
- return;
- }
- if (isOpen)
- {
- OnTriggerExit(collider);
- }
- ////// 移动中不弹窗
- ////if (HeroPlayerController.Instance != null && HeroPlayerController.Instance.GetMoveMagnitude() > 0)
- ////{
- //// return;
- ////}
- nowCollider = collider;
- SetInteractiveBtn();
- }
- public void RefreshInteractiveIcon(ref UI_BaseMainWindow.InteractiveType ittType)
- {
- // 添加任务
- List<TaskCardVo> taskVos = UserProxy.Instance.player.collectTaskCard.GetActivingCards();
- foreach (var item in taskVos)
- {
- // 当前步骤
- List<Ins_TaskStepVo> stepVos = item.curSteps;
- foreach (var step in stepVos)
- {
- if (step.isFinish())
- {
- continue;
- }
- if (step.mo().cmd != (int)Enum_TaskCmdType.PlotOver)
- {
- continue;
- }
- string[] paramList = step.mo().paras.Split(',');
- int stepNpcID = int.Parse(paramList[0]);
- int stepStageID = int.Parse(paramList[1]);
- int showLevel = 0;
- if (stepNpcID != info.npcId)
- {
- continue;
- }
- if (item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief)
- {
- ittType = UI_BaseMainWindow.InteractiveType.NpcTask_Chief;
- showLevel = 4;
- return;
- }
- else if(showLevel < 3 && item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Daily)
- {
- ittType = UI_BaseMainWindow.InteractiveType.NpcTask_Daily;
- showLevel = 3;
- }
- else if (showLevel < 2 && item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_College)
- {
- ittType = UI_BaseMainWindow.InteractiveType.NpcTask_College;
- showLevel = 2;
- }
- else if (showLevel < 1 && item.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Wanted)
- {
- ittType = UI_BaseMainWindow.InteractiveType.NpcTask_Wanted;
- showLevel = 1;
- }
- }
- }
- }
- public void SetInteractiveBtn()
- {
- UI_BaseMainWindow.InteractiveType ittType = UI_BaseMainWindow.InteractiveType.NpcDialog;
- switch (info.iconType)
- {
- case SceneEventNpc.NpcIconType.Default:
- ittType = UI_BaseMainWindow.InteractiveType.NpcDialog;
- break;
- case SceneEventNpc.NpcIconType.Store:
- ittType = UI_BaseMainWindow.InteractiveType.Grocery;
- break;
- case SceneEventNpc.NpcIconType.Smithy:
- ittType = UI_BaseMainWindow.InteractiveType.Weapon;
- break;
- case SceneEventNpc.NpcIconType.Storehouse:
- ittType = UI_BaseMainWindow.InteractiveType.Storage;
- break;
- case SceneEventNpc.NpcIconType.Teleporter:
- ittType = UI_BaseMainWindow.InteractiveType.Teleport;
- break;
- case SceneEventNpc.NpcIconType.Reword:
- ittType = UI_BaseMainWindow.InteractiveType.Wanted;
- break;
- case SceneEventNpc.NpcIconType.Email:
- ittType = UI_BaseMainWindow.InteractiveType.Email;
- break;
- case SceneEventNpc.NpcIconType.Ranking:
- ittType = UI_BaseMainWindow.InteractiveType.Ranking;
- break;
- case SceneEventNpc.NpcIconType.Entry:
- ittType = UI_BaseMainWindow.InteractiveType.Teleport;
- break;
- case SceneEventNpc.NpcIconType.Export:
- ittType = UI_BaseMainWindow.InteractiveType.Teleport;
- break;
- }
- RefreshInteractiveIcon(ref ittType);
- UI_BaseMainWindow.Instance().ShowInteractiveIcon(ittType, (_btn) =>
- {
- UI_BaseMainWindow.Instance().HideInteractive();
- OpenNpcWindow();
- });
- }
- public void OpenNpcWindow()
- {
- // 唤灵师界面启动时,不开启。
- if (UI_NewHeroTeamNewWindow.Instance() != null && UI_NewHeroTeamNewWindow.Instance().gameObject.activeInHierarchy)
- {
- return;
- }
- // 唤灵师界面启动时,不开启。
- if (UI_YanLingZhaoHuanWindow.Instance() != null && UI_YanLingZhaoHuanWindow.Instance().gameObject.activeInHierarchy)
- {
- return;
- }
- // UI_YanLingZhaoHuanWindow
-
- isOpen = true;
- HideBattleBtn();
- npcVo = new NpcInfoVo(info.npcId, nowCollider.gameObject.GetComponent<Role>());
- npcVo.npcLogic = this;
- PanelHelper.Instance.ShowPanel("UI_NpcWindow", (GameObject panel) =>
- {
- }, npcVo);
- }
- public void OnTriggerExit(Collider collider)
- {
- if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
- {
- return;
- }
- UI_BaseMainWindow.Instance().HideInteractive();
- PanelHelper.Instance.ClosePanel("UI_NpcWindow");
- ShowBattleBtn();
- isOpen = false;
- }
- public void HideBattleBtn()
- {
- if (BattleCanvas.Instance)
- {
- BattleCanvas.Instance.SetSkillButtonSatus(false);
- }
- }
- public void ShowBattleBtn()
- {
- if (BattleCanvas.Instance)
- {
- BattleCanvas.Instance.SetSkillButtonSatus(true);
- }
- }
- public void EnableCollider()
- {
- }
- public void OnClickInteractive()
- {
- isEntry = true;
- EventComponent e = GameEntry.GetComponent<EventComponent>();
- e.FireNow(this, new BattleEventOpenDialog(info.npcId, info.stageIndex));
- UI_BaseMainWindow.Instance().HideInteractive();
- }
- public void RefreshTaskSign()
- {
- if (signObj)
- {
- GameObject.Destroy(signObj);
- }
- if (mapIconObj)
- {
- AddNpcSignToMiniMap(mapIconObj);
- }
- if (BattleCanvas.Instance && BattleCanvas.Instance.mapCmpt)
- {
- BattleCanvas.Instance.mapCmpt.RemoveNpcArrowTarget(this.gameObject);
- }
- // 添加任务
- List<TaskCardVo> taskVos = TaskProxy.Instance.GetTaskTrackInfo();
- foreach (var item in taskVos)
- {
- DoTrackTaskCard(item);
- }
- }
- /// <summary>
- /// 进行一项追踪的任务
- /// </summary>
- public void DoTrackTaskCard(TaskCardVo vo)
- {
- // 当前步骤
- List<Ins_TaskStepVo> stepVos = vo.curSteps;
- for (int i = 0; i < stepVos.Count; ++i)
- {
- if (stepVos[i].mo().cmd != (int)Enum_TaskCmdType.PlotOver)
- {
- continue;
- }
- string[] paramList = stepVos[i].mo().paras.Split(',');
- int stepNpcID = int.Parse(paramList[0]);
- int stepStageID = int.Parse(paramList[1]);
- if (stepNpcID != info.npcId)
- {
- continue;
- }
- if (stepVos[i].isFinish())
- {
- if (BattleCanvas.Instance && BattleCanvas.Instance.mapCmpt)
- {
- BattleCanvas.Instance.mapCmpt.RemoveNpcArrowTarget(this.gameObject);
- }
- continue;
- }
- // 添加领取标志
- if (vo.nMo.GetTaskCardExt().type == (int)TaskCardType.TaskCardType_Chief)
- {
- // 添加完成标志
- if (i >= stepVos.Count - 1)
- {
- AddTaskCompleteSign();
- }
- // 添加接取标志
- else
- {
- AddTaskAcceptSign();
- }
- }
- // 添加支线
- else
- {
- // 添加完成标志
- if (i >= stepVos.Count - 1)
- {
- AddTaskCompleteSignBranch();
- }
- // 添加接取标志
- else
- {
- AddTaskAcceptSignBranch();
- }
- }
- }
- }
- /// <summary>
- /// 添加任务领取标志 主线任务
- /// </summary>
- public void AddTaskAcceptSign()
- {
- // 3D场景
- ResourceHelper.Instance.LoadAssetBundle("taskSignExclamation", ab =>
- {
- if (signObj)
- {
- GameObject.Destroy(signObj);
- }
- signObj = (GameObject)Instantiate(ab.LoadAsset("taskSignExclamation"));
- signObj.transform.parent = this.transform;
- signObj.transform.localPosition = new Vector3(0, 2.5f, 0);
- });
- // 小地图
- if (mapIconObj)
- {
- AddTaskAcceptSignToMiniMap(mapIconObj);
- BattleCanvas.Instance.mapCmpt.AddNpcArrowTarget(this.gameObject, () =>
- {
- AddTaskAcceptSignToMiniMap(mapIconObj);
- this.gameObject.SetActive(false);
- // Invoke("RefreshCollider", 0.0f);和孟沟通以后,暂时去掉这个任务状态改变后,触发npc窗体的,测试。想法是让玩家手动再触发。
- });
- }
- }
- /// <summary>
- /// 添加任务完成标志 主线任务
- /// </summary>
- public void AddTaskCompleteSign()
- {
- ResourceHelper.Instance.LoadAssetBundle("taskSignQuestion", ab =>
- {
- if (signObj)
- {
- GameObject.Destroy(signObj);
- }
- signObj = Instantiate(ab.LoadAsset("taskSignQuestion")) as GameObject;
- if (signObj)
- {
- signObj.transform.parent = this.transform;
- signObj.transform.localPosition = new Vector3(0, 3.2f, 0);
- }
- });
- // 小地图
- if (mapIconObj)
- {
- AddTaskCompleteSignToMiniMap(mapIconObj);
- }
- }
- /// <summary>
- /// 添加任务领取标志 分支任务
- /// </summary>
- public void AddTaskAcceptSignBranch()
- {
- // 3D场景
- ResourceHelper.Instance.LoadAssetBundle("taskSignExclamation", ab =>
- {
- if (signObj)
- {
- GameObject.Destroy(signObj);
- }
- signObj = (GameObject)Instantiate(ab.LoadAsset("taskSignExclamation"));
- signObj.transform.parent = this.transform;
- signObj.transform.localPosition = new Vector3(0, 2.5f, 0);
- });
- // 小地图
- if (mapIconObj)
- {
- AddTaskAcceptSignToMiniMapBranch(mapIconObj);
- }
- }
- /// <summary>
- /// 添加任务完成标志 分支任务
- /// </summary>
- public void AddTaskCompleteSignBranch()
- {
- ResourceHelper.Instance.LoadAssetBundle("taskSignQuestion", ab =>
- {
- if (signObj)
- {
- GameObject.Destroy(signObj);
- }
- signObj = (GameObject)Instantiate(ab.LoadAsset("taskSignQuestion"));
- signObj.transform.parent = this.transform;
- signObj.transform.localPosition = new Vector3(0, 3.2f, 0);
- });
- // 小地图
- if (mapIconObj)
- {
- AddTaskCompleteSignToMiniMapBranch(mapIconObj);
- }
- }
- public void RefreshCollider()
- {
- this.gameObject.SetActive(true);
- }
- /// <summary>
- /// 任务标识
- /// </summary>
- /// <param name="mapIconObj"></param>
- public void AddNpcSignToMiniMap(GameObject mapIconObj)
- {
- if (mapIconObj == null)
- {
- return;
- }
- if (info.iconType == SceneEventNpc.NpcIconType.Default)
- {
- mapIconObj.transform.Find("npc").gameObject.SetActive(true);
- }
- else
- {
- mapIconObj.transform.Find("npc").gameObject.SetActive(false);
- }
- mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBE").gameObject.SetActive(false);
- }
- /// <summary>
- /// 任务领取 主线
- /// </summary>
- /// <param name="mapIconObj"></param>
- public void AddTaskAcceptSignToMiniMap(GameObject mapIconObj)
- {
- mapIconObj.transform.Find("npc").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskMS").gameObject.SetActive(true);
- mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBE").gameObject.SetActive(false);
- }
- /// <summary>
- /// 任务完成 主线
- /// </summary>
- /// <param name="mapIconObj"></param>
- public void AddTaskCompleteSignToMiniMap(GameObject mapIconObj)
- {
- mapIconObj.transform.Find("npc").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskME").gameObject.SetActive(true);
- mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBE").gameObject.SetActive(false);
- }
- /// <summary>
- /// 任务领取 支线
- /// </summary>
- /// <param name="mapIconObj"></param>
- public void AddTaskAcceptSignToMiniMapBranch(GameObject mapIconObj)
- {
- mapIconObj.transform.Find("npc").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBS").gameObject.SetActive(true);
- mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
- }
- /// <summary>
- /// 任务完成 支线
- /// </summary>
- /// <param name="mapIconObj"></param>
- public void AddTaskCompleteSignToMiniMapBranch(GameObject mapIconObj)
- {
- mapIconObj.transform.Find("npc").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskMS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskME").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBS").gameObject.SetActive(false);
- mapIconObj.transform.Find("taskBE").gameObject.SetActive(true);
- }
- }
|