PlayerGuideManager.cs 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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 UnityEngine;
  9. using UnityEngine.Events;
  10. using UnityEngine.UI;
  11. using Utility;
  12. using Utility.CTween;
  13. namespace Fort23.Mono
  14. {
  15. public class PlayerGuideManager : Singleton<PlayerGuideManager>
  16. {
  17. public bool isSkip = false;
  18. public bool isUnLockAll = false;
  19. /// <summary>
  20. /// 调试模式.
  21. /// </summary>
  22. public bool isDebugging;
  23. public List<int> debugPhase = new List<int>();
  24. public UnityAction overCallBack;
  25. /// <summary>
  26. /// 是否完成强制引导
  27. /// </summary>
  28. public bool isForceDone = true;
  29. /// <summary>
  30. /// 是否完成非强制引导
  31. /// </summary>
  32. public bool isTriggerDone = true;
  33. /// <summary>
  34. /// 手指
  35. /// </summary>
  36. public Transform finger;
  37. /// <summary>
  38. /// 黑底Obj
  39. /// </summary>
  40. public GameObject blackBaseObj;
  41. /// <summary>
  42. /// 新手引导表
  43. /// </summary>
  44. public PlayerGuideConfig guideConfig;
  45. /// <summary>
  46. /// 光圈(方)
  47. /// </summary>
  48. public Transform fxTrans01;
  49. /// <summary>
  50. /// 光圈(圆)
  51. /// </summary>
  52. public Transform fxTrans02;
  53. /// <summary>
  54. /// 高亮区域
  55. /// </summary>
  56. // public GameObject fxHighLightObj;
  57. public Image highLightSpr;
  58. /// <summary>
  59. /// 保存 被改变父级的引用
  60. /// </summary>
  61. private Transform myMother;
  62. /// <summary>
  63. /// 被改变的目标
  64. /// </summary>
  65. private GameObject target;
  66. /// <summary>
  67. /// 引导目标上一次的坐标
  68. /// </summary>
  69. private Vector3 lastPos;
  70. /// <summary>
  71. /// 当前引导id
  72. /// </summary>
  73. public int curPhase = -1;
  74. /// <summary>
  75. /// 当前步骤
  76. /// </summary>
  77. public int curStep;
  78. // private bool mIsNew = false;
  79. //
  80. // public bool IsNewUser
  81. // {
  82. // get { return mIsNew; }
  83. // set { mIsNew = value; }
  84. // }
  85. public DialogBox dialogBox = new DialogBox();
  86. public IGuideLogic guideLogic;
  87. /// <summary>
  88. /// 简化配置用.
  89. /// </summary>
  90. public bool isReadFingerPos;
  91. public bool isInitGuide = false;
  92. public GameRuntimeConfig GameRuntimeConfig;
  93. public Map<int, int> ALLGuideStepData = new Map<int, int>();
  94. public PlayerGuideManager()
  95. {
  96. InitGuide();
  97. }
  98. /// <summary>
  99. /// 引导重置
  100. /// </summary>
  101. /// <param name="id"></param>
  102. public void GuideReset(int id)
  103. {
  104. if (AccountFileInfo.Instance.playerData.phaseKey.Contains(id))
  105. {
  106. int maxCount = 0;
  107. if (ALLGuideStepData.ContainsKey(id))
  108. {
  109. maxCount = ALLGuideStepData[id];
  110. }
  111. var idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(id);
  112. if (AccountFileInfo.Instance.playerData.phaseValue[idx] < maxCount)
  113. {
  114. AccountFileInfo.Instance.playerData.phaseValue[idx] = -1;
  115. }
  116. }
  117. }
  118. /// <summary>
  119. /// 新手引导是否能做 步数从0开始 需要看对应逻辑所在的索引
  120. /// </summary>
  121. /// <param name="groupID"></param>
  122. /// <returns></returns>
  123. public bool GuideIsCanDo(int groupID, int curstep = 0)
  124. {
  125. // if (!(groupID == 9 || groupID == 910 || groupID == 320))
  126. // {
  127. // return false;
  128. // }
  129. // if (groupID != 330)
  130. // {
  131. // return false;
  132. // }
  133. if (curstep > 1 && guideLogic == null)
  134. {
  135. return false;
  136. }
  137. if (AccountFileInfo.Instance.playerData == null) //todo 容错测试场景没有玩家数据
  138. {
  139. LogTool.Log("AccountFileInfo.Instance.playerSetting = " + AccountFileInfo.Instance.playerData);
  140. return false;
  141. }
  142. if (isSkip)
  143. {
  144. return false;
  145. }
  146. if (isDebugging)
  147. {
  148. if (!debugPhase.Contains(groupID) !)
  149. {
  150. return false;
  151. }
  152. }
  153. if (guideLogic != null)
  154. {
  155. if (guideLogic.guideID != groupID)
  156. {
  157. return false;
  158. }
  159. }
  160. //
  161. // if (!isDebugging) //如果不是指定调试就要判断是否能触发
  162. // {
  163. // if (groupID >= 0)
  164. // {
  165. // int configId = (groupID + 1) * 100 + 1;
  166. // PlayerGuideConfig playerGuideConfig = ConfigComponent.Instance.Get<PlayerGuideConfig>(configId);
  167. //
  168. // if (playerGuideConfig.NeedLevel > PlayerManager.Instance.Level)
  169. // {
  170. // return false;
  171. // }
  172. // }
  173. // }
  174. int maxCount = 0;
  175. if (ALLGuideStepData.ContainsKey(groupID))
  176. {
  177. maxCount = ALLGuideStepData[groupID];
  178. }
  179. int step = GetPhaseStep(groupID);
  180. if (curstep != -1) //判断这个新手引导这一步能否做
  181. {
  182. if (curstep <= step)
  183. {
  184. return false;
  185. }
  186. if (curstep - step > 1) //只能比当前步数多1才可以执行
  187. {
  188. return false;
  189. }
  190. }
  191. if (step >= maxCount)
  192. {
  193. return false;
  194. }
  195. return true;
  196. }
  197. public TimerEntity _timerEntity;
  198. public void ChangeBtnSkip()
  199. {
  200. GuidePanel guidePanel = UIManager.Instance.GetComponent<GuidePanel>();
  201. if (guidePanel != null)
  202. guidePanel.Btn_Skip.gameObject.SetActive(false);
  203. _timerEntity?.Dispose();
  204. _timerEntity = null;
  205. _timerEntity = TimerComponent.Instance.AddTimer(10000, () =>
  206. {
  207. if (UIManager.Instance.GetComponent<GuidePanel>() != null)
  208. UIManager.Instance.GetComponent<GuidePanel>().Btn_Skip.gameObject.SetActive(true);
  209. });
  210. }
  211. /// <summary>
  212. /// 引导初始化
  213. /// </summary>
  214. public void InitGuide()
  215. {
  216. foreach (var playerGuideConfig in ConfigComponent.Instance.GetAll<PlayerGuideConfig>())
  217. {
  218. if (!ALLGuideStepData.ContainsKey(playerGuideConfig.groupID))
  219. {
  220. ALLGuideStepData.Add(playerGuideConfig.groupID, 1);
  221. }
  222. else
  223. {
  224. ALLGuideStepData[playerGuideConfig.groupID] += 1;
  225. }
  226. }
  227. //
  228. // EventManager.Instance.AddEventListener(CustomEventType.NextGuide, RunNextGuide);
  229. GameRuntimeConfig = Resources.Load<GameRuntimeConfig>("GameRuntimeConfig");
  230. LogTool.Log("InitGuide************************");
  231. if (isInitGuide)
  232. {
  233. LogTool.Log("已初始化");
  234. return;
  235. }
  236. isSkip = GameRuntimeConfig.isSkip;
  237. isDebugging = GameRuntimeConfig.isDebug;
  238. isUnLockAll = GameRuntimeConfig.isUnlockAll;
  239. #if UNITY_IPHONE || UNITY_ANDROID&&!UNITY_EDITOR
  240. IsUseServerData = true;
  241. #endif
  242. //
  243. #if !UNITY_EDITOR
  244. isSkip = false;
  245. isDebugging = false;
  246. isUnLockAll = false;
  247. IsUseServerData = true;
  248. #endif
  249. List<int> ids = new List<int>();
  250. if (GameRuntimeConfig.debugPhase.x != 0)
  251. {
  252. ids.Add((int)GameRuntimeConfig.debugPhase.x);
  253. }
  254. if (GameRuntimeConfig.debugPhase.y != 0)
  255. {
  256. ids.Add((int)GameRuntimeConfig.debugPhase.y);
  257. }
  258. if (GameRuntimeConfig.debugPhase.z != 0)
  259. {
  260. ids.Add((int)GameRuntimeConfig.debugPhase.z);
  261. }
  262. if (GameRuntimeConfig.debugPhase.w != 0)
  263. {
  264. ids.Add((int)GameRuntimeConfig.debugPhase.w);
  265. }
  266. debugPhase = ids;
  267. if (isDebugging)
  268. {
  269. for (var i = 0; i < debugPhase.Count; i++)
  270. {
  271. if (AccountFileInfo.Instance.playerData.phaseKey.Contains((int)debugPhase[i]))
  272. {
  273. var idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(debugPhase[i]);
  274. AccountFileInfo.Instance.playerData.phaseValue[idx] = -1;
  275. }
  276. }
  277. }
  278. if (isSkip || isDebugging)
  279. {
  280. isInitGuide = true;
  281. isForceDone = true;
  282. return;
  283. }
  284. isForceDone = AccountFileInfo.Instance.playerData.isForceDone;
  285. curPhase = AccountFileInfo.Instance.playerData.curPhase;
  286. curStep = AccountFileInfo.Instance.playerData.curStep;
  287. //完成强制引导
  288. if (isForceDone)
  289. {
  290. isInitGuide = true;
  291. return;
  292. }
  293. //新用户,从未做过新手引导
  294. if (PlayerManager.Instance.curGuideGroupId == 0 && curPhase <= 0)
  295. {
  296. curPhase = 0;
  297. }
  298. // //没有引导记录,但有游戏记录(不是第一次玩)
  299. // else if (PlayerManager.Instance.currStageId > 1 && curPhase <= 0)
  300. // {
  301. // LogTool.Warning("玩家更换了设备,或者本地引导记录被删除,跳过所有强制引导:" + PlayerManager.Instance.PlayerId);
  302. // isForceDone = true;
  303. // isInitGuide = true;
  304. // AccountFileInfo.Instance.playerSetting.isForceDone = true;
  305. // AccountFileInfo.Instance.Save();
  306. // return;
  307. // }
  308. // else if (PlayerManager.Instance.currStageId > 10)
  309. // {
  310. // LogTool.Warning("超过10关了,强制引导已经完成:" + PlayerManager.Instance.PlayerId);
  311. // isForceDone = true;
  312. // isInitGuide = true;
  313. // AccountFileInfo.Instance.playerSetting.isForceDone = true;
  314. // AccountFileInfo.Instance.Save();
  315. // return;
  316. // }
  317. // else
  318. // {
  319. //
  320. // }
  321. isInitGuide = true;
  322. }
  323. private int GetPhaseStep(int key)
  324. {
  325. if (AccountFileInfo.Instance.playerData.phaseKey.Contains(key))
  326. {
  327. int idx = AccountFileInfo.Instance.playerData.phaseKey.IndexOf(key);
  328. return AccountFileInfo.Instance.playerData.phaseValue[idx];
  329. }
  330. else
  331. {
  332. return -1;
  333. }
  334. }
  335. /// <summary>
  336. /// 将目标加到新手引导的Panel里面.
  337. /// </summary>
  338. /// <param name="target"></param>
  339. public void JoinMe(GameObject target)
  340. {
  341. finger.gameObject.SetActive(false);
  342. if (target == null)
  343. {
  344. LogTool.Log("______" + "找不到目标");
  345. return;
  346. }
  347. Transform transform = UIManager.Instance.GetComponent<GuidePanel>().transform;
  348. if (target.transform.parent.Equals(transform))
  349. {
  350. LogTool.Log("______" + "重复改变目标的父节点,自动忽略,可能是断网重连造成的,请检查");
  351. return;
  352. }
  353. this.lastPos = target.transform.localPosition;
  354. myMother = target.transform.parent;
  355. this.target = target;
  356. target.transform.parent = transform;
  357. target.transform.localScale = Vector3.one;
  358. fxTrans01.gameObject.SetActive(true);
  359. fxTrans01.position = target.transform.position;
  360. }
  361. /// <summary>
  362. /// 还原对象
  363. /// </summary>
  364. public void ReductionTargetObject()
  365. {
  366. target.transform.parent = myMother;
  367. target.transform.localPosition = lastPos;
  368. }
  369. public void JoinMe(GameObject target, Vector3 vector3)
  370. {
  371. if (target == null)
  372. {
  373. LogTool.Log("______" + "找不到目标");
  374. return;
  375. }
  376. Transform transform = UIManager.Instance.GetComponent<GuidePanel>().transform;
  377. if (target.transform.parent.Equals(transform))
  378. {
  379. LogTool.Log("______" + "重复改变目标的父节点,自动忽略,可能是断网重连造成的,请检查");
  380. return;
  381. }
  382. this.lastPos = target.transform.localPosition;
  383. myMother = target.transform.parent;
  384. this.target = target;
  385. target.transform.parent = transform;
  386. target.transform.localScale = Vector3.one;
  387. fxTrans01.gameObject.SetActive(true);
  388. fxTrans01.parent = target.transform;
  389. fxTrans01.localPosition = vector3;
  390. fxTrans01.parent = transform;
  391. finger.gameObject.SetActive(false);
  392. }
  393. public void RestGuide()
  394. {
  395. curPhase = 0;
  396. curStep = 0;
  397. }
  398. /// <summary>
  399. /// 设置新手引导
  400. /// </summary>
  401. /// <param name="phase"></param>
  402. public async CTask SetGuid(int phase)
  403. {
  404. if (isDebugging)
  405. {
  406. if (!debugPhase.Contains(phase))
  407. {
  408. return;
  409. }
  410. }
  411. if (isSkip)
  412. {
  413. return;
  414. }
  415. if (guideLogic != null)
  416. {
  417. return;
  418. }
  419. UIManager.Instance.SetEventSystemEnable(false);
  420. curPhase = phase;
  421. guideLogic = null;
  422. guideLogic = GetIGuideLogic(curPhase);
  423. GuidePanel guildPanel =
  424. await UIManager.Instance.LoadAndOpenPanel<GuidePanel>(null, UILayer.Top, isFocus: false);
  425. dialogBox.Init();
  426. UIManager.Instance.SetEventSystemEnable(true);
  427. finger = guildPanel.GuideHand;
  428. fxTrans01 = guildPanel.FocusFrame01;
  429. fxTrans02 = guildPanel.FocusFrame02;
  430. blackBaseObj = guildPanel.Btn_Bg.gameObject;
  431. guideLogic.SavePhase(curPhase);
  432. guideLogic.ClearList();
  433. guideLogic.Active();
  434. guideLogic.Begin();
  435. NextGuideEx();
  436. }
  437. public IGuideLogic GetIGuideLogic(int groupId)
  438. {
  439. string typeName = " Fort23.Mono.Phases.Phase" + groupId;
  440. IGuideLogic guideLogic = null;
  441. System.Type type = System.Type.GetType(typeName);
  442. if (type == null)
  443. {
  444. LogTool.Error("没有找到Phase" + groupId + "脚本");
  445. return null;
  446. }
  447. object[] constructorArgs = new object[] { this };
  448. guideLogic = (IGuideLogic)Activator.CreateInstance(type, constructorArgs);
  449. // switch (groupId)
  450. // {
  451. // case 1:
  452. // guideLogic = new Phase1(this);
  453. // break;
  454. // case 2:
  455. // guideLogic = new Phase2(this);
  456. // break;
  457. // case 3:
  458. // guideLogic = new Phase3(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 async void NextGuide()
  574. {
  575. if (BreakGuide(guideLogic))
  576. {
  577. return;
  578. }
  579. try
  580. {
  581. //容错:
  582. await 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
  787. .To(() => starPos, x => SetFingerPos(x), endPos, time, finger.gameObject)
  788. .SetEase(CustomTweenEX.CustomAnimationCurve.Line).SetLoop(true);
  789. }
  790. public void SetFingerAnimation(string playerName)
  791. {
  792. // SetFingerAnimation("Loop");
  793. finger.GetComponent<Animator>().Play(playerName);
  794. }
  795. private void SetFingerPos(int[] fPos)
  796. {
  797. SetFingerPos(new Vector3(9999, 9999, 0));
  798. if (fPos != null && fPos.Length >= 2)
  799. {
  800. Vector3 pos = new Vector3(fPos[0], fPos[1], 0);
  801. SetFingerPos(pos);
  802. }
  803. else
  804. {
  805. isReadFingerPos = false;
  806. }
  807. // if (guideConfig.reversalFinger == 1)
  808. // {
  809. // finger.transform.localScale = new Vector3(1, 1, 1);
  810. // }
  811. // else if (guideConfig.reversalFinger == 2)
  812. // {
  813. // finger.transform.localScale = new Vector3(-1, 1, 1);
  814. // }
  815. }
  816. public Vector2 GetProperPos(Vector3 pos, Vector2 size, GameObject gameObject = null)
  817. {
  818. if (gameObject != null)
  819. {
  820. Vector2 pivot = gameObject.GetComponent<RectTransform>().pivot;
  821. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  822. float x = pos.x - size.x * pivot1.x;
  823. float y = pos.y - size.y * pivot1.y;
  824. return new Vector2(x, y);
  825. }
  826. else
  827. {
  828. return pos;
  829. }
  830. }
  831. /// <summary>
  832. /// 设置展示框的大小和位置 如果有锚点同步传入对应gameobject
  833. /// </summary>
  834. /// <param name="pos"></param>
  835. /// <param name="size"></param>
  836. /// <param name="type">0是矩阵 1是圆形</param>
  837. /// <param name="gameObject"></param>
  838. public void SetShowFramePosAndSize(Vector3 pos, Vector2 size, int type = 0, GameObject gameObject = null)
  839. {
  840. switch (type)
  841. {
  842. case 0:
  843. if (gameObject != null)
  844. {
  845. RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
  846. Vector2 pivot = rectTransform.pivot;
  847. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  848. float x = pos.x - size.x * pivot1.x;
  849. float y = pos.y - size.y * pivot1.y;
  850. fxTrans01.transform.localPosition = new Vector3(x, y, 0);
  851. //fxTrans01.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  852. }
  853. else
  854. {
  855. fxTrans01.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  856. fxTrans01.transform.localPosition = pos;
  857. }
  858. fxTrans01.GetComponent<RectTransform>().sizeDelta = size * 2f;
  859. CustomTweenManager.To(() => fxTrans01.GetComponent<RectTransform>().sizeDelta,
  860. x => fxTrans01.GetComponent<RectTransform>().sizeDelta = x,
  861. size, 0.3f, fxTrans01.gameObject).OnComplete(
  862. () => { fxTrans01.GetComponent<RectTransform>().sizeDelta = size; })
  863. .SetEase(CustomTweenEX.CustomAnimationCurve.InExpo);
  864. //fxTrans01.GetComponent<RectTransform>().sizeDelta = size;
  865. break;
  866. case 1:
  867. if (gameObject != null)
  868. {
  869. fxTrans02.GetComponent<RectTransform>().pivot = gameObject.GetComponent<RectTransform>().pivot;
  870. }
  871. else
  872. {
  873. fxTrans02.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
  874. }
  875. fxTrans02.transform.localPosition = pos;
  876. fxTrans02.GetComponent<RectTransform>().sizeDelta = size;
  877. break;
  878. }
  879. }
  880. public Vector3 Setpos(Vector3 pos, Vector2 size, GameObject gameObject )
  881. {
  882. RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
  883. Vector2 pivot = rectTransform.pivot;
  884. Vector2 pivot1 = pivot - Vector2.one * 0.5f;
  885. float x = pos.x - size.x * pivot1.x;
  886. float y = pos.y - size.y * pivot1.y;
  887. return new Vector3(x, y, 0);
  888. }
  889. /// <summary>
  890. /// 设置文本大小
  891. /// </summary>
  892. /// <param name="size"></param>
  893. public void SetDilogBGSize(Vector2 size)
  894. {
  895. dialogBox.MessageBG.GetComponent<RectTransform>().sizeDelta = size;
  896. }
  897. /// <summary>
  898. /// 设置mpc大小
  899. /// </summary>
  900. /// <param name="scale"></param>
  901. public void SetNpcSize(int[] scale)
  902. {
  903. dialogBox.UISpiritLoader.GetComponent<RectTransform>().sizeDelta = new Vector2(scale[0], scale[1]);
  904. dialogBox.UISpiritLoader.SetLoaderSpirit();
  905. }
  906. public Vector3 WorldPosToLocalPos(Vector3 pos)
  907. {
  908. Vector3 localPos = UIManager.Instance.GetComponent<GuidePanel>().transform.InverseTransformPoint(pos);
  909. return localPos;
  910. }
  911. public void SetMaskTarget(GameObject gameObject)
  912. {
  913. // if (guideConfig.ForceOnclick == 0)
  914. // {
  915. // return;
  916. // }
  917. UIManager.Instance.GetComponent<GuidePanel>().SetTarget(gameObject);
  918. }
  919. public void SetOnClickMask(bool value)
  920. {
  921. SetOnClickMaskSize(Vector2.zero);
  922. UIManager.Instance.GetComponent<GuidePanel>().OnClickMask.onClick.RemoveAllListeners();
  923. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMask(value);
  924. }
  925. public void SetOnClickMaskSize(Vector2 size)
  926. {
  927. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMaskSize(size);
  928. }
  929. public void SetOnClickMaskOnClickAction(UnityAction unityAction)
  930. {
  931. UIManager.Instance.GetComponent<GuidePanel>().SetOnClickMaskOnClickAction(unityAction);
  932. }
  933. /// <summary>
  934. /// 阶段初始化
  935. /// </summary>
  936. public void StepInit()
  937. {
  938. _customVectorTween?.Kill();
  939. _customVectorTween = null;
  940. UIManager.Instance.GetComponent<GuidePanel>().transform.SetAsLastSibling();
  941. if (guideConfig.SpeakerStyle == 3)
  942. {
  943. HideDialogBox(false);
  944. }
  945. else
  946. {
  947. HideDialogBox();
  948. }
  949. SetfxTransVisiable(false);
  950. SetMaskTarget(null);
  951. SetFingerVisiable(false);
  952. SetBlackBaseVisiable(true);
  953. }
  954. public void TweenAlpha()
  955. {
  956. }
  957. }
  958. }