PlayerGuideManager.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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 SetBlackBaseVisiable(bool b)
  520. {
  521. blackBaseObj.gameObject.SetActive(b);
  522. }
  523. public void SetBlackA(byte b)
  524. {
  525. Color c = new Color32(0, 0, 0, b);
  526. blackBaseObj.gameObject.GetComponent<Image>().color = c;
  527. }
  528. public void FinishATriggerGuide()
  529. {
  530. SetBlackBaseVisiable(false);
  531. if (guideLogic != null)
  532. {
  533. guideLogic = null;
  534. }
  535. }
  536. public bool IsStepSkip = false;
  537. public async CTask ConfigLogic(int configID, System.Action action, int diTyp = 1, string str = null)
  538. {
  539. IsStepSkip = false;
  540. guideConfig = ConfigComponent.Instance.Get<PlayerGuideConfig>(configID);
  541. if (guideConfig.AwardItem != null)
  542. {
  543. for (var i = 0; i < guideConfig.AwardItem.Length; i++)
  544. {
  545. PlayerManager.Instance.BagController.AddItem(new ItemInfo(guideConfig.AwardItem[i],
  546. guideConfig.AwardItemNum[i]));
  547. }
  548. }
  549. HideDialogBox(false);
  550. // if (guideConfig.SpeakerStyle == 3)
  551. // {
  552. // HideDialogBox(false);
  553. // }
  554. // else
  555. // {
  556. // HideDialogBox();
  557. // }
  558. // if (IsUseServerData)
  559. // {
  560. // PlayerManager.Instance.PlayerGuideDataComponent.UpdateData(configID);
  561. // await HttpSendManager.Instance.SendSaveGuideDataRequest(configID, SaveGuideDataCallBack); //记录服务器
  562. // }
  563. if (guideConfig.IsSkip == 1)
  564. {
  565. IsStepSkip = true;
  566. NextGuide();
  567. return;
  568. }
  569. if (guideConfig.Highlighting == 0)
  570. {
  571. SetfxTransVisiable(false);
  572. }
  573. int[] fPos = guideConfig.fingerPos;
  574. int[] dPos = guideConfig.dialogPos;
  575. isReadFingerPos = true;
  576. SetFingerVisiable(false);
  577. SetFingerPos(fPos);
  578. SetDialogPos(dPos);
  579. SetBlackBaseVisiable(true);
  580. SetBlackAlpha(guideConfig.blackAlpha);
  581. ShowDialogBox(action, str);
  582. await dialogBox.SetDiTex(guideConfig, guideConfig.SpeakerImage);
  583. UIManager.Instance.SetEventSystemEnable(true);
  584. }
  585. /// <summary>
  586. /// 下一步引导
  587. /// </summary>
  588. public async void NextGuide()
  589. {
  590. if (BreakGuide(guideLogic))
  591. {
  592. return;
  593. }
  594. try
  595. {
  596. //容错:
  597. await guideLogic.Guide();
  598. }
  599. catch (System.Exception e)
  600. {
  601. LogTool.Error("打印异常信息:" + e);
  602. ResetPlayerGuide();
  603. CloseForceGuide();
  604. LogTool.Error("引导出错,出错步骤,Phase=" + curPhase + "-" + curStep);
  605. }
  606. EventManager.Instance.Dispatch(CustomEventType.NextGuide, null);
  607. }
  608. public CTask CanDoNextCTask;
  609. public async void RunNextGuide(IEventData eventData)
  610. {
  611. if (CanDoNextCTask != null)
  612. {
  613. await CanDoNextCTask;
  614. NextGuideEx();
  615. }
  616. else
  617. {
  618. NextGuideEx();
  619. }
  620. CanDoNextCTask = null;
  621. }
  622. public void NextGuideEx()
  623. {
  624. if (BreakGuide(guideLogic))
  625. {
  626. return;
  627. }
  628. try
  629. {
  630. //容错:
  631. guideLogic.Guide();
  632. }
  633. catch (System.Exception e)
  634. {
  635. LogTool.Error("打印异常信息:" + e);
  636. ResetPlayerGuide();
  637. CloseForceGuide();
  638. LogTool.Error("引导出错,出错步骤,Phase=" + curPhase + "-" + curStep);
  639. }
  640. ChangeBtnSkip();
  641. }
  642. private bool BreakGuide(IGuideLogic guideLogic)
  643. {
  644. //#if UNITY_EDITOR
  645. if (isSkip)
  646. {
  647. this.guideLogic = null;
  648. return true;
  649. }
  650. //#endif
  651. if (guideLogic == null)
  652. {
  653. return true;
  654. }
  655. if (guideLogic.isSkipGuide)
  656. {
  657. LogTool.Log("引导开启条件不符合,不再执行");
  658. this.guideLogic = null;
  659. return true;
  660. }
  661. //强制和非强制引导都完成
  662. if (isForceDone && isTriggerDone)
  663. {
  664. LogTool.Log("引导完成");
  665. this.guideLogic = null;
  666. return true;
  667. }
  668. return false;
  669. }
  670. public void SkipGuide()
  671. {
  672. }
  673. /// <summary>
  674. /// 关闭强制引导
  675. /// </summary>
  676. public void CloseForceGuide()
  677. {
  678. HideDialogBox();
  679. isForceDone = true;
  680. SetBlackBaseVisiable(false);
  681. if (guideLogic != null)
  682. {
  683. guideLogic = null;
  684. }
  685. overCallBack?.Invoke();
  686. overCallBack = null;
  687. UIManager.Instance.HideUIUIPanel<GuidePanel>(UIDestroyType.ImmediatelyDestroy);
  688. }
  689. public void SetBlackAlpha(float f)
  690. {
  691. if (f == 0)
  692. {
  693. f = 0.05f;
  694. }
  695. Color color = blackBaseObj.GetComponent<Image>().color;
  696. color.a = f;
  697. blackBaseObj.GetComponent<Image>().color = color;
  698. }
  699. public BetterList<string> dialogList = new BetterList<string>();
  700. public void HideDialogBox(bool isHide = true)
  701. {
  702. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  703. if (guidePanel != null)
  704. {
  705. guidePanel.DialogBoxState.gameObject.SetActive(!isHide);
  706. // if (isHide)
  707. // {
  708. // guidePanel.DialogBoxState.gameObject.SetActive(false);
  709. // }
  710. }
  711. }
  712. /// <summary>
  713. /// 显示对话框
  714. /// </summary>
  715. public void ShowDialogBox(System.Action action = null, string key = null)
  716. {
  717. if (guideConfig.desc == -1)
  718. {
  719. action?.Invoke();
  720. action = null;
  721. return;
  722. }
  723. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  724. switch (guideConfig.SpeakerStyle)
  725. {
  726. case 1:
  727. guidePanel.DialogBoxState.ChangeState(0);
  728. break;
  729. case 2:
  730. guidePanel.DialogBoxState.ChangeState(1);
  731. break;
  732. case 3:
  733. guidePanel.DialogBoxState.ChangeState(2);
  734. break;
  735. case 4:
  736. guidePanel.DialogBoxState.ChangeState(3);
  737. break;
  738. }
  739. dialogBox.ChangeState(guideConfig.SpeakerStyle);
  740. if (guideConfig.SpeakerStyle != 3)
  741. {
  742. SetDialogPos(guideConfig.dialogPos);
  743. }
  744. string str = null;
  745. if (key == null)
  746. {
  747. str = LanguageManager.Instance.Text(guideConfig.desc);
  748. }
  749. else
  750. {
  751. str = string.Format(LanguageManager.Instance.Text(guideConfig.desc), key);
  752. }
  753. string[] textArr = str.Split(';');
  754. dialogList.Clear();
  755. foreach (string tex in textArr)
  756. {
  757. dialogList.Add(tex);
  758. }
  759. dialogBox.Open(dialogList, action);
  760. }
  761. private void SetDialogPos(int[] dPos)
  762. {
  763. if (dPos != null)
  764. {
  765. Vector3 pos = new Vector3(dPos[0], dPos[1], 0);
  766. float ratio = Screen.width / 750f;
  767. pos.x *= ratio;
  768. dialogBox.MessageBG.localPosition = pos;
  769. }
  770. else
  771. {
  772. dialogBox.MessageBG.localPosition = new Vector3(-125, -100, 0);
  773. }
  774. }
  775. private void SetNpcPos(int[] nPos)
  776. {
  777. if (nPos != null)
  778. {
  779. Vector3 pos = new Vector3(nPos[0], nPos[1], 0);
  780. // dialogBox.UISpiritLoader.transform.localPosition = pos;
  781. }
  782. else
  783. {
  784. // dialogBox.UISpiritLoader.transform.localPosition = new Vector3(422, -100, 0);
  785. }
  786. }
  787. public void SetFingerPos(Vector3 pos, GameObject gameObject = null)
  788. {
  789. if (gameObject != null)
  790. {
  791. finger.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  792. }
  793. else
  794. {
  795. finger.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  796. }
  797. finger.transform.localPosition = pos;
  798. }
  799. private CustomVectorTween _customVectorTween;
  800. public void SetFingerTweenMove(Vector3 starPos, Vector3 endPos, float time)
  801. {
  802. // SetFingerAnimation("Loop");
  803. _customVectorTween?.Kill();
  804. _customVectorTween = null;
  805. _customVectorTween = CustomTweenManager
  806. .To(() => starPos, x => SetFingerPos(x), endPos, time, finger.gameObject)
  807. .SetEase(CustomTweenEX.CustomAnimationCurve.Line).SetLoop(true);
  808. }
  809. public void SetFingerAnimation(string playerName)
  810. {
  811. // SetFingerAnimation("Loop");
  812. finger.GetComponent<Animator>().Play(playerName);
  813. }
  814. private void SetFingerPos(int[] fPos)
  815. {
  816. SetFingerPos(new Vector3(9999, 9999, 0));
  817. if (fPos != null && fPos.Length >= 2)
  818. {
  819. Vector3 pos = new Vector3(fPos[0], fPos[1], 0);
  820. SetFingerPos(pos);
  821. }
  822. else
  823. {
  824. isReadFingerPos = false;
  825. }
  826. // if (guideConfig.reversalFinger == 1)
  827. // {
  828. // finger.transform.localScale = new Vector3(1, 1, 1);
  829. // }
  830. // else if (guideConfig.reversalFinger == 2)
  831. // {
  832. // finger.transform.localScale = new Vector3(-1, 1, 1);
  833. // }
  834. }
  835. public Vector2 GetProperPos(Vector3 pos, Vector2 size, GameObject gameObject = null)
  836. {
  837. if (gameObject != null)
  838. {
  839. Vector2 pivot = gameObject.GetComponent<RectTransform>().pivot;
  840. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  841. float x = pos.x - size.x * pivot1.x;
  842. float y = pos.y - size.y * pivot1.y;
  843. return new Vector2(x, y);
  844. }
  845. else
  846. {
  847. return pos;
  848. }
  849. }
  850. /// <summary>
  851. /// 设置展示框的大小和位置 如果有锚点同步传入对应gameobject
  852. /// </summary>
  853. /// <param name="pos"></param>
  854. /// <param name="size"></param>
  855. /// <param name="type">0是矩阵 1是圆形</param>
  856. /// <param name="gameObject"></param>
  857. public void SetShowFramePosAndSize(Vector3 pos, Vector2 size, int type = 0, GameObject gameObject = null)
  858. {
  859. switch (type)
  860. {
  861. case 0:
  862. if (gameObject != null)
  863. {
  864. RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
  865. Vector2 pivot = rectTransform.pivot;
  866. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  867. float x = pos.x - size.x * pivot1.x;
  868. float y = pos.y - size.y * pivot1.y;
  869. fxTrans01.transform.localPosition = new Vector3(x, y, 0);
  870. //fxTrans01.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  871. }
  872. else
  873. {
  874. fxTrans01.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  875. fxTrans01.transform.localPosition = pos;
  876. }
  877. fxTrans01.GetComponent<RectTransform>().sizeDelta = size * 2f;
  878. CustomTweenManager.To(() => fxTrans01.GetComponent<RectTransform>().sizeDelta,
  879. x => fxTrans01.GetComponent<RectTransform>().sizeDelta = x,
  880. size, 0.3f, fxTrans01.gameObject).OnComplete(
  881. () => { fxTrans01.GetComponent<RectTransform>().sizeDelta = size; })
  882. .SetEase(CustomTweenEX.CustomAnimationCurve.InExpo);
  883. //fxTrans01.GetComponent<RectTransform>().sizeDelta = size;
  884. break;
  885. case 1:
  886. if (gameObject != null)
  887. {
  888. fxTrans02.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  889. }
  890. else
  891. {
  892. fxTrans02.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  893. }
  894. fxTrans02.transform.localPosition = pos;
  895. fxTrans02.GetComponent<RectTransform>().sizeDelta = size;
  896. break;
  897. }
  898. }
  899. public Vector3 Setpos(Vector3 pos, Vector2 size, GameObject gameObject)
  900. {
  901. RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
  902. Vector2 pivot = rectTransform.pivot;
  903. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  904. float x = pos.x - size.x * pivot1.x;
  905. float y = pos.y - size.y * pivot1.y;
  906. return new Vector3(x, y, 0);
  907. }
  908. /// <summary>
  909. /// 设置文本大小
  910. /// </summary>
  911. /// <param name="size"></param>
  912. public void SetDilogBGSize(Vector2 size)
  913. {
  914. dialogBox.MessageBG.GetComponent<RectTransform>().sizeDelta = size;
  915. }
  916. /// <summary>
  917. /// 设置mpc大小
  918. /// </summary>
  919. /// <param name="scale"></param>
  920. public void SetNpcSize(int[] scale)
  921. {
  922. dialogBox.UISpiritLoader.GetComponent<RectTransform>().sizeDelta = new Vector2(scale[0], scale[1]);
  923. dialogBox.UISpiritLoader.SetLoaderSpirit();
  924. }
  925. public Vector3 WorldPosToLocalPos(Vector3 pos)
  926. {
  927. Vector3 localPos = UIManager.Instance.GetComponent<GuidePanel>().transform.InverseTransformPoint(pos);
  928. return localPos;
  929. }
  930. public void SetMaskTarget(GameObject gameObject)
  931. {
  932. // if (guideConfig.ForceOnclick == 0)
  933. // {
  934. // return;
  935. // }
  936. UIManager.Instance.GetComponent<GuidePanel>().SetTarget(gameObject);
  937. }
  938. public void SetOnClickMask(bool value)
  939. {
  940. SetOnClickMaskSize(Vector2.zero);
  941. UIManager.Instance.GetComponent<GuidePanel>().OnClickMask.onClick.RemoveAllListeners();
  942. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMask(value);
  943. }
  944. public void SetOnClickMaskSize(Vector2 size)
  945. {
  946. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMaskSize(size);
  947. }
  948. public void SetOnClickMaskOnClickAction(UnityAction unityAction)
  949. {
  950. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMaskOnClickAction(unityAction);
  951. }
  952. /// <summary>
  953. /// 阶段初始化
  954. /// </summary>
  955. public void StepInit()
  956. {
  957. UIManager.Instance.SetEventSystemEnable(false);
  958. _customVectorTween?.Kill();
  959. _customVectorTween = null;
  960. UIManager.Instance.GetComponent<GuidePanel>().transform.SetAsLastSibling();
  961. // if (guideConfig.SpeakerStyle == 3)
  962. // {
  963. // HideDialogBox(false);
  964. // }
  965. // else
  966. // {
  967. // HideDialogBox();
  968. // }
  969. HideDialogBox();
  970. SetfxTransVisiable(false);
  971. SetMaskTarget(null);
  972. SetFingerVisiable(false);
  973. SetBlackBaseVisiable(false);
  974. }
  975. public void TweenAlpha()
  976. {
  977. }
  978. }
  979. }