PlayerGuideManager.cs 33 KB

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