PlayerGuideManager.cs 34 KB

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