PlayerGuideManager.cs 33 KB

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