PlayerGuideManager.cs 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. using System;
  2. using System.Collections.Generic;
  3. using Core.Language;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.Mono.Phases;
  7. using Fort23.UTool;
  8. using GameLogic.Bag;
  9. using UnityEngine;
  10. using UnityEngine.Events;
  11. using UnityEngine.UI;
  12. using Utility;
  13. using Utility.CTween;
  14. namespace Fort23.Mono
  15. {
  16. public class PlayerGuideManager : Singleton<PlayerGuideManager>
  17. {
  18. public bool isSkip = false;
  19. public bool isUnLockAll = false;
  20. /// <summary>
  21. /// 调试模式.
  22. /// </summary>
  23. public bool isDebugging;
  24. public List<int> debugPhase = new List<int>();
  25. public UnityAction overCallBack;
  26. /// <summary>
  27. /// 是否完成强制引导
  28. /// </summary>
  29. public bool isForceDone = true;
  30. /// <summary>
  31. /// 是否完成非强制引导
  32. /// </summary>
  33. public bool isTriggerDone = true;
  34. /// <summary>
  35. /// 手指
  36. /// </summary>
  37. public Transform finger;
  38. /// <summary>
  39. /// 黑底Obj
  40. /// </summary>
  41. public GameObject blackBaseObj;
  42. /// <summary>
  43. /// 新手引导表
  44. /// </summary>
  45. public PlayerGuideConfig guideConfig;
  46. /// <summary>
  47. /// 光圈(方)
  48. /// </summary>
  49. public Transform fxTrans01;
  50. /// <summary>
  51. /// 光圈(圆)
  52. /// </summary>
  53. public Transform fxTrans02;
  54. /// <summary>
  55. /// 高亮区域
  56. /// </summary>
  57. // public GameObject fxHighLightObj;
  58. public Image highLightSpr;
  59. /// <summary>
  60. /// 保存 被改变父级的引用
  61. /// </summary>
  62. private Transform myMother;
  63. /// <summary>
  64. /// 被改变的目标
  65. /// </summary>
  66. private GameObject target;
  67. /// <summary>
  68. /// 引导目标上一次的坐标
  69. /// </summary>
  70. private Vector3 lastPos;
  71. /// <summary>
  72. /// 当前引导id
  73. /// </summary>
  74. public int curPhase = -1;
  75. /// <summary>
  76. /// 当前步骤
  77. /// </summary>
  78. public int curStep;
  79. // private bool mIsNew = false;
  80. //
  81. // public bool IsNewUser
  82. // {
  83. // get { return mIsNew; }
  84. // set { mIsNew = value; }
  85. // }
  86. public DialogBox dialogBox = new DialogBox();
  87. public IGuideLogic guideLogic;
  88. /// <summary>
  89. /// 简化配置用.
  90. /// </summary>
  91. public bool isReadFingerPos;
  92. public bool isInitGuide = false;
  93. public GameRuntimeConfig GameRuntimeConfig;
  94. public Map<int, int> ALLGuideStepData = new Map<int, int>();
  95. public PlayerGuideManager()
  96. {
  97. InitGuide();
  98. }
  99. /// <summary>
  100. /// 引导重置
  101. /// </summary>
  102. /// <param name="id"></param>
  103. public void GuideReset(int id)
  104. {
  105. if (AccountFileInfo.Instance.playerData.phaseKey.Contains(id))
  106. {
  107. int maxCount = 0;
  108. if (ALLGuideStepData.ContainsKey(id))
  109. {
  110. maxCount = ALLGuideStepData[id];
  111. }
  112. var idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(id);
  113. if (AccountFileInfo.Instance.playerData.phaseValue[idx] < maxCount)
  114. {
  115. AccountFileInfo.Instance.playerData.phaseValue[idx] = -1;
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// 新手引导是否能做 步数从0开始 需要看对应逻辑所在的索引
  121. /// </summary>
  122. /// <param name="groupID"></param>
  123. /// <returns></returns>
  124. public bool GuideIsCanDo(int groupID, int curstep = 0)
  125. {
  126. // if (!(groupID == 9 || groupID == 910 || groupID == 320))
  127. // {
  128. // return false;
  129. // }
  130. // if (groupID != 330)
  131. // {
  132. // return false;
  133. // }
  134. // if (GuideIsCanDo(5))
  135. // {
  136. // return false;
  137. // }
  138. if (curstep > 1 && guideLogic == null)
  139. {
  140. return false;
  141. }
  142. if (AccountFileInfo.Instance.playerData == null) //todo 容错测试场景没有玩家数据
  143. {
  144. LogTool.Log("AccountFileInfo.Instance.playerSetting = " + AccountFileInfo.Instance.playerData);
  145. return false;
  146. }
  147. if (isSkip)
  148. {
  149. return false;
  150. }
  151. if (isDebugging)
  152. {
  153. if (!debugPhase.Contains(groupID) !)
  154. {
  155. return false;
  156. }
  157. }
  158. if (guideLogic != null)
  159. {
  160. if (guideLogic.guideID != groupID)
  161. {
  162. return false;
  163. }
  164. }
  165. //
  166. // if (!isDebugging) //如果不是指定调试就要判断是否能触发
  167. // {
  168. // if (groupID >= 0)
  169. // {
  170. // int configId = (groupID + 1) * 100 + 1;
  171. // PlayerGuideConfig playerGuideConfig = ConfigComponent.Instance.Get<PlayerGuideConfig>(configId);
  172. //
  173. // if (playerGuideConfig.NeedLevel > PlayerManager.Instance.Level)
  174. // {
  175. // return false;
  176. // }
  177. // }
  178. // }
  179. int maxCount = 0;
  180. if (ALLGuideStepData.ContainsKey(groupID))
  181. {
  182. maxCount = ALLGuideStepData[groupID];
  183. }
  184. int step = GetPhaseStep(groupID);
  185. if (curstep != -1) //判断这个新手引导这一步能否做
  186. {
  187. if (curstep <= step)
  188. {
  189. return false;
  190. }
  191. if (curstep - step > 1) //只能比当前步数多1才可以执行
  192. {
  193. return false;
  194. }
  195. }
  196. if (step >= maxCount)
  197. {
  198. return false;
  199. }
  200. return true;
  201. }
  202. public TimerEntity _timerEntity;
  203. public void ChangeBtnSkip()
  204. {
  205. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  206. if (guidePanel != null)
  207. guidePanel.Btn_Skip.gameObject.SetActive(false);
  208. _timerEntity?.Dispose();
  209. _timerEntity = null;
  210. _timerEntity = TimerComponent.Instance.AddTimer(10000, () =>
  211. {
  212. if (UIManager.Instance.GetComponent<GuidePanel>() != null)
  213. UIManager.Instance.GetComponent<GuidePanel>().Btn_Skip.gameObject.SetActive(true);
  214. });
  215. }
  216. /// <summary>
  217. /// 引导初始化
  218. /// </summary>
  219. public void InitGuide()
  220. {
  221. foreach (var playerGuideConfig in ConfigComponent.Instance.GetAll<PlayerGuideConfig>())
  222. {
  223. if (!ALLGuideStepData.ContainsKey(playerGuideConfig.groupID))
  224. {
  225. ALLGuideStepData.Add(playerGuideConfig.groupID, 1);
  226. }
  227. else
  228. {
  229. ALLGuideStepData[playerGuideConfig.groupID] += 1;
  230. }
  231. }
  232. //
  233. // EventManager.Instance.AddEventListener(CustomEventType.NextGuide, RunNextGuide);
  234. GameRuntimeConfig = Resources.Load<GameRuntimeConfig>("GameRuntimeConfig");
  235. LogTool.Log("InitGuide************************");
  236. if (isInitGuide)
  237. {
  238. LogTool.Log("已初始化");
  239. return;
  240. }
  241. isSkip = GameRuntimeConfig.isSkip;
  242. isDebugging = GameRuntimeConfig.isDebug;
  243. isUnLockAll = GameRuntimeConfig.isUnlockAll;
  244. #if UNITY_IPHONE || UNITY_ANDROID&&!UNITY_EDITOR
  245. IsUseServerData = true;
  246. #endif
  247. //
  248. #if !UNITY_EDITOR
  249. isSkip = false;
  250. isDebugging = false;
  251. isUnLockAll = false;
  252. IsUseServerData = true;
  253. #endif
  254. List<int> ids = new List<int>();
  255. if (GameRuntimeConfig.debugPhase.x != 0)
  256. {
  257. ids.Add((int)GameRuntimeConfig.debugPhase.x);
  258. }
  259. if (GameRuntimeConfig.debugPhase.y != 0)
  260. {
  261. ids.Add((int)GameRuntimeConfig.debugPhase.y);
  262. }
  263. if (GameRuntimeConfig.debugPhase.z != 0)
  264. {
  265. ids.Add((int)GameRuntimeConfig.debugPhase.z);
  266. }
  267. if (GameRuntimeConfig.debugPhase.w != 0)
  268. {
  269. ids.Add((int)GameRuntimeConfig.debugPhase.w);
  270. }
  271. debugPhase = ids;
  272. if (isDebugging)
  273. {
  274. for (var i = 0; i < debugPhase.Count; i++)
  275. {
  276. if (AccountFileInfo.Instance.playerData.phaseKey.Contains((int)debugPhase[i]))
  277. {
  278. var idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(debugPhase[i]);
  279. AccountFileInfo.Instance.playerData.phaseValue[idx] = -1;
  280. }
  281. }
  282. }
  283. if (isSkip || isDebugging)
  284. {
  285. isInitGuide = true;
  286. isForceDone = true;
  287. return;
  288. }
  289. isForceDone = AccountFileInfo.Instance.playerData.isForceDone;
  290. curPhase = AccountFileInfo.Instance.playerData.curPhase;
  291. curStep = AccountFileInfo.Instance.playerData.curStep;
  292. //完成强制引导
  293. if (isForceDone)
  294. {
  295. isInitGuide = true;
  296. return;
  297. }
  298. //新用户,从未做过新手引导
  299. if (PlayerManager.Instance.curGuideGroupId == 0 && curPhase <= 0)
  300. {
  301. curPhase = 0;
  302. }
  303. // //没有引导记录,但有游戏记录(不是第一次玩)
  304. // else if (PlayerManager.Instance.currStageId > 1 && curPhase <= 0)
  305. // {
  306. // LogTool.Warning("玩家更换了设备,或者本地引导记录被删除,跳过所有强制引导:" + PlayerManager.Instance.PlayerId);
  307. // isForceDone = true;
  308. // isInitGuide = true;
  309. // AccountFileInfo.Instance.playerSetting.isForceDone = true;
  310. // AccountFileInfo.Instance.Save();
  311. // return;
  312. // }
  313. // else if (PlayerManager.Instance.currStageId > 10)
  314. // {
  315. // LogTool.Warning("超过10关了,强制引导已经完成:" + PlayerManager.Instance.PlayerId);
  316. // isForceDone = true;
  317. // isInitGuide = true;
  318. // AccountFileInfo.Instance.playerSetting.isForceDone = true;
  319. // AccountFileInfo.Instance.Save();
  320. // return;
  321. // }
  322. // else
  323. // {
  324. //
  325. // }
  326. isInitGuide = true;
  327. }
  328. private int GetPhaseStep(int key)
  329. {
  330. if (AccountFileInfo.Instance.playerData.phaseKey.Contains(key))
  331. {
  332. int idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(key);
  333. return AccountFileInfo.Instance.playerData.phaseValue[idx];
  334. }
  335. else
  336. {
  337. return -1;
  338. }
  339. }
  340. /// <summary>
  341. /// 将目标加到新手引导的Panel里面.
  342. /// </summary>
  343. /// <param name="target"></param>
  344. public void JoinMe(GameObject target)
  345. {
  346. finger.gameObject.SetActive(false);
  347. if (target == null)
  348. {
  349. LogTool.Log("______" + "找不到目标");
  350. return;
  351. }
  352. Transform transform = UIManager.Instance.GetComponent<GuidePanel>().transform;
  353. if (target.transform.parent.Equals(transform))
  354. {
  355. LogTool.Log("______" + "重复改变目标的父节点,自动忽略,可能是断网重连造成的,请检查");
  356. return;
  357. }
  358. this.lastPos = target.transform.localPosition;
  359. myMother = target.transform.parent;
  360. this.target = target;
  361. target.transform.parent = transform;
  362. target.transform.localScale = Vector3.one;
  363. fxTrans01.gameObject.SetActive(true);
  364. fxTrans01.position = target.transform.position;
  365. }
  366. /// <summary>
  367. /// 还原对象
  368. /// </summary>
  369. public void ReductionTargetObject()
  370. {
  371. target.transform.parent = myMother;
  372. target.transform.localPosition = lastPos;
  373. }
  374. public void JoinMe(GameObject target, Vector3 vector3)
  375. {
  376. if (target == null)
  377. {
  378. LogTool.Log("______" + "找不到目标");
  379. return;
  380. }
  381. Transform transform = UIManager.Instance.GetComponent<GuidePanel>().transform;
  382. if (target.transform.parent.Equals(transform))
  383. {
  384. LogTool.Log("______" + "重复改变目标的父节点,自动忽略,可能是断网重连造成的,请检查");
  385. return;
  386. }
  387. this.lastPos = target.transform.localPosition;
  388. myMother = target.transform.parent;
  389. this.target = target;
  390. target.transform.parent = transform;
  391. target.transform.localScale = Vector3.one;
  392. fxTrans01.gameObject.SetActive(true);
  393. fxTrans01.parent = target.transform;
  394. fxTrans01.localPosition = vector3;
  395. fxTrans01.parent = transform;
  396. finger.gameObject.SetActive(false);
  397. }
  398. public void RestGuide()
  399. {
  400. curPhase = 0;
  401. curStep = 0;
  402. }
  403. /// <summary>
  404. /// 设置新手引导
  405. /// </summary>
  406. /// <param name="phase"></param>
  407. public async CTask SetGuid(int phase)
  408. {
  409. if (isDebugging)
  410. {
  411. if (!debugPhase.Contains(phase))
  412. {
  413. return;
  414. }
  415. }
  416. if (isSkip)
  417. {
  418. return;
  419. }
  420. if (guideLogic != null)
  421. {
  422. return;
  423. }
  424. UIManager.Instance.SetEventSystemEnable(false);
  425. curPhase = phase;
  426. guideLogic = null;
  427. guideLogic = GetIGuideLogic(curPhase);
  428. GuidePanel guildPanel =
  429. await UIManager.Instance.LoadAndOpenPanel<GuidePanel>(null, UILayer.Top, isFocus: false);
  430. dialogBox.Init();
  431. UIManager.Instance.SetEventSystemEnable(true);
  432. finger = guildPanel.GuideHand;
  433. fxTrans01 = guildPanel.FocusFrame01;
  434. fxTrans02 = guildPanel.FocusFrame02;
  435. blackBaseObj = guildPanel.Btn_Bg.gameObject;
  436. guideLogic.SavePhase(curPhase);
  437. guideLogic.ClearList();
  438. guideLogic.Active();
  439. guideLogic.Begin();
  440. NextGuideEx();
  441. }
  442. public IGuideLogic GetIGuideLogic(int groupId)
  443. {
  444. string typeName = " Fort23.Mono.Phases.Phase" + groupId;
  445. IGuideLogic guideLogic = null;
  446. System.Type type = System.Type.GetType(typeName);
  447. if (type == null)
  448. {
  449. LogTool.Error("没有找到Phase" + groupId + "脚本");
  450. return null;
  451. }
  452. object[] constructorArgs = new object[] { this };
  453. guideLogic = (IGuideLogic)Activator.CreateInstance(type, constructorArgs);
  454. // switch (groupId)
  455. // {
  456. // case 1:
  457. // guideLogic = new Phase1(this);
  458. // break;
  459. // case 2:
  460. // guideLogic = new Phase2(this);
  461. // break;
  462. // case 3:
  463. // guideLogic = new Phase3(this);
  464. // break;
  465. // }
  466. return guideLogic;
  467. }
  468. /// <summary>
  469. /// 关闭引导,重置到初始状态.
  470. /// </summary>
  471. public void ResetPlayerGuide()
  472. {
  473. Transform transform = UIManager.Instance.GetComponent<GuidePanel>().transform;
  474. finger.transform.parent = transform;
  475. finger.transform.localScale = new Vector3(1, 1, 1);
  476. SetFingerVisiable(false);
  477. }
  478. public void SetFingerVisiable(bool b, string playName = "Loop")
  479. {
  480. finger.gameObject.SetActive(b);
  481. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  482. switch (guideConfig.FingerType)
  483. {
  484. case 1:
  485. guidePanel.GuideHandState.ChangeState(0);
  486. break;
  487. case 2:
  488. guidePanel.GuideHandState.ChangeState(1);
  489. break;
  490. case 3:
  491. guidePanel.GuideHandState.ChangeState(2);
  492. break;
  493. case 4:
  494. playName = "changan";
  495. guidePanel.GuideHandState.ChangeState(1);
  496. break;
  497. case -1:
  498. finger.gameObject.SetActive(false);
  499. break;
  500. }
  501. SetFingerAnimation(playName);
  502. }
  503. public void SetFingerSize(Vector3 size)
  504. {
  505. finger.localScale = size;
  506. }
  507. public void SetfxTransVisiable(bool b, int type = 0)
  508. {
  509. switch (type)
  510. {
  511. case 0:
  512. fxTrans01.gameObject.SetActive(b);
  513. break;
  514. case 1:
  515. fxTrans02.gameObject.SetActive(b);
  516. break;
  517. }
  518. }
  519. public void SetfxTransImageVisiable(bool b, int type = 0)
  520. {
  521. switch (type)
  522. {
  523. case 0:
  524. fxTrans01.gameObject.GetComponent<MyImage>().enabled = b;
  525. break;
  526. case 1:
  527. fxTrans02.gameObject.GetComponent<MyImage>().enabled = b;
  528. break;
  529. }
  530. }
  531. public void SetBlackBaseVisiable(bool b)
  532. {
  533. blackBaseObj.gameObject.SetActive(b);
  534. }
  535. public void SetBlackA(byte b)
  536. {
  537. Color c = new Color32(0, 0, 0, b);
  538. blackBaseObj.gameObject.GetComponent<Image>().color = c;
  539. }
  540. public void FinishATriggerGuide()
  541. {
  542. SetBlackBaseVisiable(false);
  543. if (guideLogic != null)
  544. {
  545. guideLogic = null;
  546. }
  547. }
  548. public bool IsStepSkip = false;
  549. public async CTask ConfigLogic(int configID, System.Action action, int diTyp = 1, string str = null)
  550. {
  551. IsStepSkip = false;
  552. guideConfig = ConfigComponent.Instance.Get<PlayerGuideConfig>(configID);
  553. if (guideConfig.AwardItem != null)
  554. {
  555. for (var i = 0; i < guideConfig.AwardItem.Length; i++)
  556. {
  557. PlayerManager.Instance.BagController.AddItem(new ItemInfo(guideConfig.AwardItem[i],
  558. guideConfig.AwardItemNum[i]));
  559. }
  560. }
  561. HideDialogBox(false);
  562. // if (guideConfig.SpeakerStyle == 3)
  563. // {
  564. // HideDialogBox(false);
  565. // }
  566. // else
  567. // {
  568. // HideDialogBox();
  569. // }
  570. // if (IsUseServerData)
  571. // {
  572. // PlayerManager.Instance.PlayerGuideDataComponent.UpdateData(configID);
  573. // await HttpSendManager.Instance.SendSaveGuideDataRequest(configID, SaveGuideDataCallBack); //记录服务器
  574. // }
  575. if (guideConfig.IsSkip == 1)
  576. {
  577. IsStepSkip = true;
  578. NextGuide();
  579. return;
  580. }
  581. if (guideConfig.Highlighting == 0)
  582. {
  583. SetfxTransImageVisiable(false);
  584. }
  585. int[] fPos = guideConfig.fingerPos;
  586. int[] dPos = guideConfig.dialogPos;
  587. isReadFingerPos = true;
  588. SetFingerVisiable(false);
  589. SetFingerPos(fPos);
  590. SetDialogPos(dPos);
  591. SetBlackBaseVisiable(true);
  592. SetBlackAlpha(guideConfig.blackAlpha);
  593. ShowDialogBox(action, str);
  594. await dialogBox.SetDiTex(guideConfig, guideConfig.SpeakerImage);
  595. UIManager.Instance.SetEventSystemEnable(true);
  596. }
  597. /// <summary>
  598. /// 下一步引导
  599. /// </summary>
  600. public async void NextGuide()
  601. {
  602. if (BreakGuide(guideLogic))
  603. {
  604. return;
  605. }
  606. try
  607. {
  608. //容错:
  609. await guideLogic.Guide();
  610. }
  611. catch (System.Exception e)
  612. {
  613. LogTool.Error("打印异常信息:" + e);
  614. ResetPlayerGuide();
  615. CloseForceGuide();
  616. LogTool.Error("引导出错,出错步骤,Phase=" + curPhase + "-" + curStep);
  617. }
  618. EventManager.Instance.Dispatch(CustomEventType.NextGuide, null);
  619. }
  620. public CTask CanDoNextCTask;
  621. public async void RunNextGuide(IEventData eventData)
  622. {
  623. if (CanDoNextCTask != null)
  624. {
  625. await CanDoNextCTask;
  626. NextGuideEx();
  627. }
  628. else
  629. {
  630. NextGuideEx();
  631. }
  632. CanDoNextCTask = null;
  633. }
  634. public void NextGuideEx()
  635. {
  636. if (BreakGuide(guideLogic))
  637. {
  638. return;
  639. }
  640. try
  641. {
  642. //容错:
  643. guideLogic.Guide();
  644. }
  645. catch (System.Exception e)
  646. {
  647. LogTool.Error("打印异常信息:" + e);
  648. ResetPlayerGuide();
  649. CloseForceGuide();
  650. LogTool.Error("引导出错,出错步骤,Phase=" + curPhase + "-" + curStep);
  651. }
  652. ChangeBtnSkip();
  653. }
  654. private bool BreakGuide(IGuideLogic guideLogic)
  655. {
  656. //#if UNITY_EDITOR
  657. if (isSkip)
  658. {
  659. this.guideLogic = null;
  660. return true;
  661. }
  662. //#endif
  663. if (guideLogic == null)
  664. {
  665. return true;
  666. }
  667. if (guideLogic.isSkipGuide)
  668. {
  669. LogTool.Log("引导开启条件不符合,不再执行");
  670. this.guideLogic = null;
  671. return true;
  672. }
  673. //强制和非强制引导都完成
  674. if (isForceDone && isTriggerDone)
  675. {
  676. LogTool.Log("引导完成");
  677. this.guideLogic = null;
  678. return true;
  679. }
  680. return false;
  681. }
  682. public void SkipGuide()
  683. {
  684. }
  685. /// <summary>
  686. /// 关闭强制引导
  687. /// </summary>
  688. public void CloseForceGuide()
  689. {
  690. HideDialogBox();
  691. isForceDone = true;
  692. SetBlackBaseVisiable(false);
  693. if (guideLogic != null)
  694. {
  695. guideLogic = null;
  696. }
  697. overCallBack?.Invoke();
  698. overCallBack = null;
  699. UIManager.Instance.HideUIUIPanel<GuidePanel>(UIDestroyType.ImmediatelyDestroy);
  700. }
  701. public void SetBlackAlpha(float f)
  702. {
  703. if (f == 0)
  704. {
  705. f = 0.05f;
  706. }
  707. Color color = blackBaseObj.GetComponent<Image>().color;
  708. color.a = f;
  709. blackBaseObj.GetComponent<Image>().color = color;
  710. }
  711. public BetterList<string> dialogList = new BetterList<string>();
  712. public void HideDialogBox(bool isHide = true)
  713. {
  714. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  715. if (guidePanel != null)
  716. {
  717. guidePanel.DialogBoxState.gameObject.SetActive(!isHide);
  718. // if (isHide)
  719. // {
  720. // guidePanel.DialogBoxState.gameObject.SetActive(false);
  721. // }
  722. }
  723. }
  724. /// <summary>
  725. /// 显示对话框
  726. /// </summary>
  727. public void ShowDialogBox(System.Action action = null, string key = null)
  728. {
  729. if (guideConfig.desc == -1)
  730. {
  731. action?.Invoke();
  732. action = null;
  733. return;
  734. }
  735. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  736. switch (guideConfig.SpeakerStyle)
  737. {
  738. case 1:
  739. guidePanel.DialogBoxState.ChangeState(0);
  740. break;
  741. case 2:
  742. guidePanel.DialogBoxState.ChangeState(1);
  743. break;
  744. case 3:
  745. guidePanel.DialogBoxState.ChangeState(2);
  746. break;
  747. case 4:
  748. guidePanel.DialogBoxState.ChangeState(3);
  749. break;
  750. }
  751. dialogBox.ChangeState(guideConfig.SpeakerStyle);
  752. if (guideConfig.SpeakerStyle != 3)
  753. {
  754. SetDialogPos(guideConfig.dialogPos);
  755. }
  756. string str = null;
  757. if (key == null)
  758. {
  759. str = LanguageManager.Instance.Text(guideConfig.desc);
  760. }
  761. else
  762. {
  763. str = string.Format(LanguageManager.Instance.Text(guideConfig.desc), key);
  764. }
  765. string[] textArr = str.Split(';');
  766. dialogList.Clear();
  767. foreach (string tex in textArr)
  768. {
  769. dialogList.Add(tex);
  770. }
  771. dialogBox.Open(dialogList, action);
  772. }
  773. private void SetDialogPos(int[] dPos)
  774. {
  775. if (dPos != null)
  776. {
  777. Vector3 pos = new Vector3(dPos[0], dPos[1], 0);
  778. float ratio = Screen.width / 750f;
  779. pos.x *= ratio;
  780. dialogBox.MessageBG.localPosition = pos;
  781. }
  782. else
  783. {
  784. dialogBox.MessageBG.localPosition = new Vector3(-125, -100, 0);
  785. }
  786. }
  787. private void SetNpcPos(int[] nPos)
  788. {
  789. if (nPos != null)
  790. {
  791. Vector3 pos = new Vector3(nPos[0], nPos[1], 0);
  792. // dialogBox.UISpiritLoader.transform.localPosition = pos;
  793. }
  794. else
  795. {
  796. // dialogBox.UISpiritLoader.transform.localPosition = new Vector3(422, -100, 0);
  797. }
  798. }
  799. public void SetFingerPos(Vector3 pos, GameObject gameObject = null)
  800. {
  801. if (gameObject != null)
  802. {
  803. finger.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  804. }
  805. else
  806. {
  807. finger.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  808. }
  809. finger.transform.localPosition = pos;
  810. }
  811. private CustomVectorTween _customVectorTween;
  812. public void SetFingerTweenMove(Vector3 starPos, Vector3 endPos, float time)
  813. {
  814. // SetFingerAnimation("Loop");
  815. _customVectorTween?.Kill();
  816. _customVectorTween = null;
  817. _customVectorTween = CustomTweenManager
  818. .To(() => starPos, x => SetFingerPos(x), endPos, time, finger.gameObject)
  819. .SetEase(CustomTweenEX.CustomAnimationCurve.Line).SetLoop(true);
  820. }
  821. public void SetFingerAnimation(string playerName)
  822. {
  823. // SetFingerAnimation("Loop");
  824. finger.GetComponent<Animator>().Play(playerName);
  825. }
  826. private void SetFingerPos(int[] fPos)
  827. {
  828. SetFingerPos(new Vector3(9999, 9999, 0));
  829. if (fPos != null && fPos.Length >= 2)
  830. {
  831. Vector3 pos = new Vector3(fPos[0], fPos[1], 0);
  832. SetFingerPos(pos);
  833. }
  834. else
  835. {
  836. isReadFingerPos = false;
  837. }
  838. // if (guideConfig.reversalFinger == 1)
  839. // {
  840. // finger.transform.localScale = new Vector3(1, 1, 1);
  841. // }
  842. // else if (guideConfig.reversalFinger == 2)
  843. // {
  844. // finger.transform.localScale = new Vector3(-1, 1, 1);
  845. // }
  846. }
  847. public Vector2 GetProperPos(Vector3 pos, Vector2 size, GameObject gameObject = null)
  848. {
  849. if (gameObject != null)
  850. {
  851. Vector2 pivot = gameObject.GetComponent<RectTransform>().pivot;
  852. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  853. float x = pos.x - size.x * pivot1.x;
  854. float y = pos.y - size.y * pivot1.y;
  855. return new Vector2(x, y);
  856. }
  857. else
  858. {
  859. return pos;
  860. }
  861. }
  862. /// <summary>
  863. /// 设置展示框的大小和位置 如果有锚点同步传入对应gameobject
  864. /// </summary>
  865. /// <param name="pos"></param>
  866. /// <param name="size"></param>
  867. /// <param name="type">0是矩阵 1是圆形</param>
  868. /// <param name="gameObject"></param>
  869. public void SetShowFramePosAndSize(Vector3 pos, Vector2 size, int type = 0, GameObject gameObject = null)
  870. {
  871. switch (type)
  872. {
  873. case 0:
  874. if (gameObject != null)
  875. {
  876. RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
  877. Vector2 pivot = rectTransform.pivot;
  878. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  879. float x = pos.x - size.x * pivot1.x;
  880. float y = pos.y - size.y * pivot1.y;
  881. fxTrans01.transform.localPosition = new Vector3(x, y, 0);
  882. //fxTrans01.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  883. }
  884. else
  885. {
  886. fxTrans01.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  887. fxTrans01.transform.localPosition = pos;
  888. }
  889. fxTrans01.GetComponent<RectTransform>().sizeDelta = size * 2f;
  890. CustomTweenManager.To(() => fxTrans01.GetComponent<RectTransform>().sizeDelta,
  891. x => fxTrans01.GetComponent<RectTransform>().sizeDelta = x,
  892. size, 0.3f, fxTrans01.gameObject).OnComplete(
  893. () => { fxTrans01.GetComponent<RectTransform>().sizeDelta = size; })
  894. .SetEase(CustomTweenEX.CustomAnimationCurve.InExpo);
  895. //fxTrans01.GetComponent<RectTransform>().sizeDelta = size;
  896. break;
  897. case 1:
  898. if (gameObject != null)
  899. {
  900. fxTrans02.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  901. }
  902. else
  903. {
  904. fxTrans02.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  905. }
  906. fxTrans02.transform.localPosition = pos;
  907. fxTrans02.GetComponent<RectTransform>().sizeDelta = size;
  908. break;
  909. }
  910. }
  911. public Vector3 Setpos(Vector3 pos, Vector2 size, GameObject gameObject)
  912. {
  913. RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
  914. Vector2 pivot = rectTransform.pivot;
  915. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  916. float x = pos.x - size.x * pivot1.x;
  917. float y = pos.y - size.y * pivot1.y;
  918. return new Vector3(x, y, 0);
  919. }
  920. /// <summary>
  921. /// 设置文本大小
  922. /// </summary>
  923. /// <param name="size"></param>
  924. public void SetDilogBGSize(Vector2 size)
  925. {
  926. dialogBox.MessageBG.GetComponent<RectTransform>().sizeDelta = size;
  927. }
  928. /// <summary>
  929. /// 设置mpc大小
  930. /// </summary>
  931. /// <param name="scale"></param>
  932. public void SetNpcSize(int[] scale)
  933. {
  934. dialogBox.UISpiritLoader.GetComponent<RectTransform>().sizeDelta = new Vector2(scale[0], scale[1]);
  935. dialogBox.UISpiritLoader.SetLoaderSpirit();
  936. }
  937. public Vector3 WorldPosToLocalPos(Vector3 pos)
  938. {
  939. Vector3 localPos = UIManager.Instance.GetComponent<GuidePanel>().transform.InverseTransformPoint(pos);
  940. return localPos;
  941. }
  942. public void SetMaskTarget(GameObject gameObject)
  943. {
  944. // if (guideConfig.ForceOnclick == 0)
  945. // {
  946. // return;
  947. // }
  948. UIManager.Instance.GetComponent<GuidePanel>().SetTarget(gameObject);
  949. }
  950. public void SetOnClickMask(bool value)
  951. {
  952. SetOnClickMaskSize(Vector2.zero);
  953. UIManager.Instance.GetComponent<GuidePanel>().OnClickMask.onClick.RemoveAllListeners();
  954. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMask(value);
  955. }
  956. public void SetOnClickMaskSize(Vector2 size)
  957. {
  958. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMaskSize(size);
  959. }
  960. public void SetOnClickMaskOnClickAction(UnityAction unityAction)
  961. {
  962. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMaskOnClickAction(unityAction);
  963. }
  964. /// <summary>
  965. /// 阶段初始化
  966. /// </summary>
  967. public void StepInit()
  968. {
  969. UIManager.Instance.SetEventSystemEnable(false);
  970. _customVectorTween?.Kill();
  971. _customVectorTween = null;
  972. UIManager.Instance.GetComponent<GuidePanel>().transform.SetAsLastSibling();
  973. // if (guideConfig.SpeakerStyle == 3)
  974. // {
  975. // HideDialogBox(false);
  976. // }
  977. // else
  978. // {
  979. // HideDialogBox();
  980. // }
  981. HideDialogBox();
  982. SetfxTransVisiable(false);
  983. SetMaskTarget(null);
  984. SetFingerVisiable(false);
  985. SetBlackBaseVisiable(false);
  986. }
  987. public void TweenAlpha()
  988. {
  989. }
  990. }
  991. }