NewUserGuiderManager.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. using JC.Unity.UI;
  8. public class NewUserGuiderManager : MonoBehaviour
  9. {
  10. [SerializeField] GameObject prefab_NewUserGuider;
  11. public static NewUserGuiderManager ins;
  12. void Awake()
  13. {
  14. if (ins) {
  15. Destroy(gameObject);
  16. return;
  17. }
  18. ins = this;
  19. DontDestroyOnLoad(gameObject);
  20. }
  21. void OnDestroy()
  22. {
  23. if (ins == this) ins = null;
  24. if (onSceneLoaded_added) SceneManager.sceneLoaded -= onSceneLoaded;
  25. }
  26. void Start()
  27. {
  28. SceneManager.sceneLoaded += onSceneLoaded; onSceneLoaded_added = true;
  29. }
  30. bool _initChecked = false;
  31. public void InitCheck()
  32. {
  33. if (_initChecked) return;
  34. _initChecked = true;
  35. if (!IsUserGuideFinished()) {
  36. ExecuteCurConfig();
  37. SaveUserGuideFinished(true);
  38. }
  39. }
  40. bool onSceneLoaded_added = false;
  41. void onSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { //初始话的场景不会触发
  42. if (scene.name == "Game" && GameMgr.gameType == 1) {
  43. switch (curConfigKey) {
  44. case "开始-限时游戏":
  45. OnClickedDestroyed(curConfigKey);
  46. break;
  47. case "限时游戏-选择距离":
  48. ExecuteCurConfig();
  49. break;
  50. }
  51. }
  52. }
  53. public void OnSkip()
  54. {
  55. curConfigKey = null;
  56. SaveUserGuideFinished(true);
  57. }
  58. public void OnEnd()
  59. {
  60. curConfigKey = null;
  61. SaveUserGuideFinished(true);
  62. }
  63. public void ReviewNewUserGuide()
  64. {
  65. int viewCount = PersistenHandler.ins.menuBackCtr.views.Count;
  66. for (int i = 0; i < viewCount; i++) {
  67. PersistenHandler.ins.menuBackCtr.OnOnceBack();
  68. }
  69. curConfigKey = "模块开机";
  70. ExecuteCurConfig();
  71. }
  72. void SaveUserGuideFinished(bool finished) {
  73. PlayerPrefs.SetInt("NewUserGuiderFinished", finished ? 1 : 0);
  74. }
  75. bool IsUserGuideFinished() {
  76. return PlayerPrefs.GetInt("NewUserGuiderFinished", 0) == 1 ? true : false;
  77. }
  78. void InitConfigs()
  79. {
  80. if (configsInited) return;
  81. configsInited = true;
  82. NewUserGuiderConfig config = new NewUserGuiderConfig();
  83. config.key = "模块开机";
  84. config.hitPosType = 1;
  85. config.hitPos = new Vector2(-138.9f, -56.1f);
  86. config.pointerRotZ = 120;
  87. config.pointerPosType = 1;
  88. config.pointerPos = new Vector2(-205, 4);
  89. config.frameTipPivot = "lc";
  90. config.frameTipPosType = 1;
  91. config.frameTipPos = new Vector2(0, 0);
  92. config.onStart = (g) => {
  93. RectTransform iconModule = g.transform.Find("IconModule") as RectTransform;
  94. iconModule.anchoredPosition = new Vector2(-146, -39);
  95. iconModule.gameObject.SetActive(true);
  96. g.SetIconPointerHitOpacity(0.2f);
  97. };
  98. configs.Add(config.key, config);
  99. config = new NewUserGuiderConfig();
  100. config.key = "连接设备";
  101. config.frameTipPivot = "lb";
  102. config.onPrepare = (g) => {
  103. RectTransform btn = GameObject.Find("HomeView/HomeViewRenderBow/Btn").GetComponent<RectTransform>();
  104. g.hollowOutMask.SetTarget(btn);
  105. // g.hollowOutMask.isTargetRectCanThrough = false;
  106. g.SetIconPointerHitOpacity(0.5f);
  107. g.config.hitPos = btn.position;
  108. g.config.pointerPos = btn.position + RectTransformUtils.CanvasV3ToScreenV3(Vector3.up * 80f, btn);
  109. g.config.frameTipPos = btn.position + RectTransformUtils.CanvasV3ToScreenV3(Vector3.up * 150f, btn);
  110. g.hollowOutMask.autoUpdate = true;
  111. };
  112. config.onStart = (g) => {
  113. g.GetMaskClickedEvent().RemoveAllListeners();
  114. g.GetMaskClickedEvent().AddListener(() => {
  115. if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess) {
  116. g.OnClick_ToNext();
  117. }
  118. });
  119. Func<bool> action_DoConnectInterceptor = () => {
  120. bool isConnected = BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
  121. if (isConnected) {
  122. g.OnClick_ToNext();
  123. }
  124. return isConnected;
  125. };
  126. BluetoothAim.ins.action_DoConnectInterceptor += action_DoConnectInterceptor;
  127. g.action_OnDestroy += () => BluetoothAim.ins.action_DoConnectInterceptor -= action_DoConnectInterceptor;
  128. };
  129. configs.Add(config.key, config);
  130. config = new NewUserGuiderConfig();
  131. config.key = "弓箭详情";
  132. config.frameTipPivot = "lt";
  133. config.onPrepare = (g) => {
  134. RectTransform btn = GameObject.Find("HomeView/HomeViewRenderBow/BtnShowDetail").GetComponent<RectTransform>();
  135. g.hollowOutMask.SetTarget(btn);
  136. g.hollowOutMask.isTargetRectCanThrough = false;
  137. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  138. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.7f));
  139. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.5f));
  140. };
  141. config.onStart = (g) => {
  142. g.GetMaskClickedEvent().RemoveAllListeners();
  143. g.GetNewUserGuiderButton().onClick += () => {
  144. HomeViewRenderBow homeViewRenderBow = FindObjectOfType<HomeViewRenderBow>();
  145. if (homeViewRenderBow) {
  146. homeViewRenderBow.OnClick_ShowDeviceView();
  147. g.clickedWillPlayAudioBtn = false;
  148. g.OnClick_ToNext();
  149. }
  150. };
  151. };
  152. configs.Add(config.key, config);
  153. config = new NewUserGuiderConfig();
  154. config.key = "设备-陀螺仪校准";
  155. config.frameTipPivot = "rt";
  156. config.onPrepare = (g) => {
  157. if (!DeviceView1.ins) {
  158. g.customPreparePass = false;
  159. return;
  160. }
  161. g.customPreparePass = true;
  162. RectTransform btn = DeviceView1.ins.transform.Find("ItemInfo/BowOptions/GyrCalibrate") as RectTransform;
  163. g.hollowOutMask.SetTarget(btn);
  164. // g.hollowOutMask.isTargetRectCanThrough = false;
  165. g.SetIconPointerHitOpacity(0.8f);
  166. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  167. g.config.pointerRotZ = 180;
  168. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
  169. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.3f, 0))
  170. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
  171. };
  172. config.onStart = (g) => {
  173. g.GetMaskClickedEvent().RemoveAllListeners();
  174. Action onclickTarget = () => {
  175. g.clickedWillPlayAudioBtn = false;
  176. g.OnClick_ToNext();
  177. };
  178. DeviceView1.ins.action_OnClickGyr += onclickTarget;
  179. g.action_OnDestroy += () => DeviceView1.ins.action_OnClickGyr -= onclickTarget;
  180. };
  181. configs.Add(config.key, config);
  182. config = new NewUserGuiderConfig();
  183. config.key = "陀螺仪校准-开始";
  184. config.frameTipPivot = "rt";
  185. config.frameTipText = "";
  186. config.delayExecute = false;
  187. config.onPrepare = (g) => {
  188. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  189. RectTransform btn = DeviceCalibrateView.ins.transform.Find("Gyr/Button") as RectTransform;
  190. g.hollowOutMask.SetTarget(btn);
  191. g.SetIconPointerHitOpacity(0.8f);
  192. g.SetMaskOpacity(0.33f);
  193. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  194. g.config.pointerRotZ = 180;
  195. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
  196. g.frameTip.gameObject.SetActive(false);
  197. };
  198. config.onStart = (g) => {
  199. g.GetMaskClickedEvent().RemoveAllListeners();
  200. g.action_Update += () => {
  201. bool doing = DeviceCalibrateView.ins.gyrCalibrating;
  202. g.iconPointer.gameObject.SetActive(!doing);
  203. g.iconPointerHit.gameObject.SetActive(!doing);
  204. };
  205. Func<bool> interceptor = () => {
  206. return DeviceCalibrateView.ins.gyrCalibrating;
  207. };
  208. Action operateFinished = () => {
  209. g.hollowOutMask.isTargetRectCanThrough = false;
  210. g.OnClick_ToNext();
  211. };
  212. DeviceCalibrateView.ins.action_OnClickGyrCalibrateInterceptor += interceptor;
  213. DeviceCalibrateView.ins.action_GyrCalibarateOperateAndFinish += operateFinished;
  214. g.action_OnDestroy += () => {
  215. DeviceCalibrateView.ins.action_OnClickGyrCalibrateInterceptor -= interceptor;
  216. DeviceCalibrateView.ins.action_GyrCalibarateOperateAndFinish -= operateFinished;
  217. };
  218. };
  219. configs.Add(config.key, config);
  220. config = new NewUserGuiderConfig();
  221. config.key = "陀螺仪校准-完成";
  222. config.frameTipPivot = "rt";
  223. config.frameTipText = "";
  224. config.onPrepare = (g) => {
  225. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  226. RectTransform btn = DeviceCalibrateView.ins.transform.Find("BtnFinish") as RectTransform;
  227. g.hollowOutMask.SetTarget(btn);
  228. g.SetIconPointerHitOpacity(0.8f);
  229. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  230. g.config.pointerRotZ = 120;
  231. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.2f, 1.2f));
  232. g.frameTip.gameObject.SetActive(false);
  233. };
  234. config.onStart = (g) => {
  235. g.GetMaskClickedEvent().RemoveAllListeners();
  236. Action operateFinished = () => {
  237. g.clickedWillPlayAudioBtn = false;
  238. g.OnClick_ToNext();
  239. };
  240. DeviceCalibrateView.ins.action_OnDestroy += operateFinished;
  241. };
  242. configs.Add(config.key, config);
  243. config = new NewUserGuiderConfig();
  244. config.key = "设备-地磁计校准";
  245. config.frameTipPivot = "rt";
  246. config.onPrepare = (g) => {
  247. if (!DeviceView1.ins) {
  248. g.customPreparePass = false;
  249. return;
  250. }
  251. g.customPreparePass = true;
  252. RectTransform btn = DeviceView1.ins.transform.Find("ItemInfo/BowOptions/MagCalibrate") as RectTransform;
  253. g.hollowOutMask.SetTarget(btn);
  254. // g.hollowOutMask.isTargetRectCanThrough = false;
  255. g.SetIconPointerHitOpacity(0.8f);
  256. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  257. g.config.pointerRotZ = 180;
  258. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
  259. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.3f, 0))
  260. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 60f, g.iconPointer);
  261. };
  262. config.onStart = (g) => {
  263. g.GetMaskClickedEvent().RemoveAllListeners();
  264. Action onclickTarget = () => {
  265. g.clickedWillPlayAudioBtn = false;
  266. g.OnClick_ToNext();
  267. };
  268. DeviceView1.ins.action_OnClickMag += onclickTarget;
  269. g.action_OnDestroy += () => DeviceView1.ins.action_OnClickMag -= onclickTarget;
  270. };
  271. configs.Add(config.key, config);
  272. config = new NewUserGuiderConfig();
  273. config.key = "地磁计校准-开始";
  274. config.frameTipPivot = "rt";
  275. config.frameTipText = "";
  276. config.delayExecute = false;
  277. config.onPrepare = (g) => {
  278. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  279. RectTransform btn = DeviceCalibrateView.ins.transform.Find("Mag/MagReset") as RectTransform;
  280. g.hollowOutMask.SetTarget(btn);
  281. g.SetIconPointerHitOpacity(0.8f);
  282. g.SetMaskOpacity(0.33f);
  283. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  284. g.config.pointerRotZ = 180;
  285. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
  286. g.frameTip.gameObject.SetActive(false);
  287. };
  288. config.onStart = (g) => {
  289. g.GetMaskClickedEvent().RemoveAllListeners();
  290. g.action_Update += () => {
  291. bool doing = DeviceCalibrateView.ins.calibrateMagDoing;
  292. g.iconPointer.gameObject.SetActive(!doing);
  293. g.iconPointerHit.gameObject.SetActive(!doing);
  294. };
  295. Func<bool> interceptor = () => {
  296. return DeviceCalibrateView.ins.calibrateMagDoing;
  297. };
  298. Action operateFinished = () => {
  299. g.hollowOutMask.isTargetRectCanThrough = false;
  300. g.OnClick_ToNext();
  301. };
  302. DeviceCalibrateView.ins.action_OnClickMagCalibrateInterceptor += interceptor;
  303. DeviceCalibrateView.ins.action_MagCalibarateOperateAndFinish += operateFinished;
  304. g.action_OnDestroy += () => {
  305. DeviceCalibrateView.ins.action_OnClickMagCalibrateInterceptor -= interceptor;
  306. DeviceCalibrateView.ins.action_MagCalibarateOperateAndFinish -= operateFinished;
  307. };
  308. };
  309. configs.Add(config.key, config);
  310. config = new NewUserGuiderConfig();
  311. config.key = "地磁计校准-完成";
  312. config.frameTipPivot = "rt";
  313. config.frameTipText = "";
  314. config.onPrepare = (g) => {
  315. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  316. RectTransform btn = DeviceCalibrateView.ins.transform.Find("BtnFinish") as RectTransform;
  317. g.hollowOutMask.SetTarget(btn);
  318. g.SetIconPointerHitOpacity(0.8f);
  319. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  320. g.config.pointerRotZ = 120;
  321. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.2f, 1.2f));
  322. g.frameTip.gameObject.SetActive(false);
  323. };
  324. config.onStart = (g) => {
  325. g.GetMaskClickedEvent().RemoveAllListeners();
  326. Action operateFinished = () => {
  327. FindObjectOfType<DeviceView1>()?.OnClick_Back();
  328. g.clickedWillPlayAudioBtn = false;
  329. g.OnClick_ToNext();
  330. };
  331. DeviceCalibrateView.ins.action_OnDestroy += operateFinished;
  332. };
  333. configs.Add(config.key, config);
  334. config = new NewUserGuiderConfig();
  335. config.key = "查看设置";
  336. config.frameTipPivot = "rt";
  337. config.onPrepare = (g) => {
  338. RectTransform btn = GameObject.Find("TopBarView/TopBar/IconSetUp").GetComponent<RectTransform>();
  339. g.hollowOutMask.SetTarget(btn);
  340. g.hollowOutMask.isTargetRectCanThrough = false;
  341. g.SetIconPointerHitOpacity(0.6f);
  342. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  343. g.config.pointerRotZ = 180;
  344. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * -0.1f);
  345. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  346. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
  347. };
  348. configs.Add(config.key, config);
  349. config = new NewUserGuiderConfig();
  350. config.key = "查看商城";
  351. config.frameTipPivot = "rt";
  352. config.onPrepare = (g) => {
  353. RectTransform btn = GameObject.Find("TopBarView/TopBar/IconShop").GetComponent<RectTransform>();
  354. g.hollowOutMask.SetTarget(btn);
  355. g.hollowOutMask.isTargetRectCanThrough = false;
  356. g.SetIconPointerHitOpacity(0.6f);
  357. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  358. g.config.pointerRotZ = 180;
  359. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * -0.1f);
  360. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  361. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
  362. };
  363. configs.Add(config.key, config);
  364. config = new NewUserGuiderConfig();
  365. config.key = "切换好友/排行榜";
  366. config.frameTipPivot = "lt";
  367. config.onPrepare = (g) => {
  368. RectTransform btn = GameObject.Find("HomeView/FriendBar/FrameBtnTop").GetComponent<RectTransform>();
  369. g.hollowOutMask.SetTarget(btn);
  370. g.hollowOutMask.isTargetRectCanThrough = false;
  371. g.SetIconPointerHitOpacity(0.6f);
  372. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  373. g.config.pointerRotZ = -30;
  374. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.2f, 0.9f));
  375. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.2f, 0));
  376. };
  377. configs.Add(config.key, config);
  378. config = new NewUserGuiderConfig();
  379. config.key = "展开好友/排行榜";
  380. config.frameTipPivot = "lc";
  381. config.onPrepare = (g) => {
  382. RectTransform btn = GameObject.Find("HomeView/FriendBar/FrameBtnBottom").GetComponent<RectTransform>();
  383. g.hollowOutMask.SetTarget(btn);
  384. g.hollowOutMask.isTargetRectCanThrough = false;
  385. g.SetIconPointerHitOpacity(0.8f);
  386. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  387. g.config.pointerRotZ = -30;
  388. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1, 0.9f));
  389. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.5f, 0.5f));
  390. };
  391. configs.Add(config.key, config);
  392. config = new NewUserGuiderConfig();
  393. config.key = "联机游戏";
  394. config.frameTipPivot = "lt";
  395. config.onPrepare = (g) => {
  396. RectTransform btn = GameObject.Find("HomeView/RightPanel/Item (1)").GetComponent<RectTransform>();
  397. g.hollowOutMask.SetTarget(btn);
  398. g.hollowOutMask.isTargetRectCanThrough = false;
  399. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.5f, 0.6f));
  400. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.9f));
  401. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  402. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.left * 150f, g.iconPointer);
  403. };
  404. configs.Add(config.key, config);
  405. config = new NewUserGuiderConfig();
  406. config.key = "开始游戏";
  407. config.frameTipPivot = "lt";
  408. config.onPrepare = (g) => {
  409. RectTransform btn = GameObject.Find("HomeView/RightPanel/Item").GetComponent<RectTransform>();
  410. g.hollowOutMask.SetTarget(btn);
  411. // g.hollowOutMask.isTargetRectCanThrough = false;
  412. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.5f, 0.6f));
  413. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.9f));
  414. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  415. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.left * 150f, g.iconPointer);
  416. };
  417. config.onStart = (g) => {
  418. g.GetMaskClickedEvent().RemoveAllListeners();
  419. Action onClickTarget = () => {
  420. g.clickedWillPlayAudioBtn = false;
  421. g.OnClick_ToNext();
  422. };
  423. HomeView.ins.action_OnClickStartGame += onClickTarget;
  424. g.action_OnDestroy += () => HomeView.ins.action_OnClickStartGame -= onClickTarget;
  425. };
  426. configs.Add(config.key, config);
  427. config = new NewUserGuiderConfig();
  428. config.key = "开始-限时游戏";
  429. config.frameTipPivot = "lt";
  430. config.onPrepare = (g) => {
  431. if (!GameStartView.ins) {
  432. g.customPreparePass = false;
  433. return;
  434. }
  435. g.customPreparePass = true;
  436. RectTransform btn = GameStartView.ins.transform.Find("EntryList/Item (1)") as RectTransform;
  437. g.hollowOutMask.SetTarget(btn);
  438. // g.hollowOutMask.isTargetRectCanThrough = false;
  439. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  440. g.config.pointerRotZ = 180;
  441. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.2f, 0.3f));
  442. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.4f, 0.15f))
  443. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.left * 150f, g.iconPointer);
  444. };
  445. config.onStart = (g) => {
  446. g.GetMaskClickedEvent().RemoveAllListeners();
  447. };
  448. configs.Add(config.key, config);
  449. config = new NewUserGuiderConfig();
  450. config.key = "限时游戏-选择距离";
  451. config.frameTipPivot = "lc";
  452. config.onPrepare = (g) => {
  453. if (g.hollowOutMask.enabled) g.hollowOutMask.enabled = false;
  454. g.ActiveBtnSkip(false);
  455. if (!TimeLimitGameDistanceSelectView.ins) {
  456. g.customPreparePass = false;
  457. return;
  458. }
  459. //马上重构布局,否则引导初始化获取到的目标坐标不对
  460. LayoutRebuilder.ForceRebuildLayoutImmediate(TimeLimitGameDistanceSelectView.ins.transform.Find("Layout") as RectTransform);
  461. g.customPreparePass = true;
  462. g.hollowOutMask.enabled = true;
  463. g.ActiveBtnSkip(true);
  464. RectTransform btn = TimeLimitGameDistanceSelectView.ins.transform.Find("Layout/Item") as RectTransform;
  465. g.hollowOutMask.SetTarget(btn);
  466. // g.hollowOutMask.isTargetRectCanThrough = false;
  467. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  468. g.config.pointerRotZ = -30;
  469. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.85f, 0.5f));
  470. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.15f, 0.4f));
  471. };
  472. config.onStart = (g) => {
  473. g.GetMaskClickedEvent().RemoveAllListeners();
  474. Action onClickTarget = () => {
  475. g.clickedWillPlayAudioBtn = false;
  476. g.OnClick_ToNext();
  477. };
  478. TimeLimitGameDistanceSelectView.ins.action_OnClickSelectDistance += onClickTarget;
  479. g.action_OnDestroy += () => {
  480. if (!TimeLimitGameDistanceSelectView.ins) return;
  481. TimeLimitGameDistanceSelectView.ins.action_OnClickSelectDistance -= onClickTarget;
  482. };
  483. };
  484. configs.Add(config.key, config);
  485. config = new NewUserGuiderConfig();
  486. config.key = "视角归位-触发";
  487. config.frameTipPivot = "rb";
  488. config.frameTipPos = Vector2.zero;
  489. config.onPrepare = (g) => {
  490. RectTransform btn4 = GameAssistUI.ins.transform.Find("Button4") as RectTransform;
  491. g.hollowOutMask.SetTarget(btn4);
  492. RectTransform btn4_img = btn4.Find("Image") as RectTransform;
  493. g.config.hitPos = btn4_img.position;
  494. g.config.pointerRotZ = 120;
  495. g.config.pointerPos = btn4_img.position + RectTransformUtils.CanvasV3ToScreenV3(new Vector3(-60, 60), btn4);
  496. g.config.frameTipPos = btn4_img.position + RectTransformUtils.CanvasV3ToScreenV3(new Vector3(-120, 120), btn4);
  497. RectTransform iconHumanShoot = g.transform.Find("IconHumanShoot") as RectTransform;
  498. iconHumanShoot.pivot = Vector2.one * 0.5f;
  499. iconHumanShoot.anchoredPosition = new Vector2(-350, -85);
  500. iconHumanShoot.gameObject.SetActive(true);
  501. GameMode gameMode = GameMgr.ins.gameMode;
  502. if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  503. gameMode.PauseTimeCounting(g);
  504. g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  505. }
  506. };
  507. config.onStart = (g) => {
  508. g.GetMaskClickedEvent().RemoveAllListeners();
  509. Action onClickTarget = () => {
  510. g.gameObject.SetActive(false);
  511. AutoResetView.ins.action_OnDestroy += () => {
  512. if (!g) return;
  513. g.clickedWillPlayAudioBtn = false;
  514. g.OnClick_ToNext();
  515. };
  516. };
  517. GameAssistUI.ins.action_OnClickBtnIdentity += onClickTarget;
  518. g.action_OnDestroy += () => GameAssistUI.ins.action_OnClickBtnIdentity -= onClickTarget;
  519. };
  520. configs.Add(config.key, config);
  521. // config = new NewUserGuiderConfig();
  522. // config.key = "视角归位-瞄准";
  523. // config.frameTipPivot = "lc";
  524. // config.onPrepare = (g) => {
  525. // float rectSideLen = RectTransformUtils.ScreenV3ToCanvasV3(Vector3.right * Screen.height * 100 / 720f, g.GetComponent<RectTransform>()).x;
  526. // Vector2 rectSize = new Vector2(rectSideLen, rectSideLen);
  527. // RectTransform iconRect = g.transform.Find("IconRect") as RectTransform;
  528. // iconRect.sizeDelta = rectSize;
  529. // iconRect.gameObject.SetActive(true);
  530. // g.hollowOutMask.isTargetRectCanThrough = false;
  531. // g.hollowOutMask.SetTarget(iconRect);
  532. // g.config.hitPosType = 1;
  533. // g.config.hitPos = Vector2.zero;
  534. // g.config.pointerPosType = 1;
  535. // g.config.pointerRotZ = 120;
  536. // g.config.pointerPos = new Vector2(-rectSideLen / 2 * 1.2f, rectSideLen / 2 * 1.1f);
  537. // RectTransform iconHumanShoot = g.transform.Find("IconHumanShoot") as RectTransform;
  538. // iconHumanShoot.anchoredPosition = g.config.pointerPos;
  539. // iconHumanShoot.gameObject.SetActive(true);
  540. // g.config.frameTipPosType = 1;
  541. // g.config.frameTipPos = new Vector2(rectSideLen / 2 * 1.3f, 0);
  542. // GameMode gameMode = GameMgr.ins.gameMode;
  543. // if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  544. // gameMode.PauseTimeCounting(g);
  545. // g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  546. // }
  547. // };
  548. // configs.Add(config.key, config);
  549. config = new NewUserGuiderConfig();
  550. config.key = "准心高亮";
  551. config.hitPosType = 1;
  552. config.hitPos = Vector2.zero;
  553. config.pointerActive = false;
  554. config.frameTipText = "";
  555. config.onStart = (g) => {
  556. g.GetMaskClickedEvent().RemoveAllListeners();
  557. GameMode gameMode = GameMgr.ins.gameMode;
  558. if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  559. gameMode.PauseTimeCounting(g);
  560. g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  561. }
  562. RectTransform iconRect = g.transform.Find("IconRect") as RectTransform;
  563. iconRect.gameObject.SetActive(true);
  564. g.hollowOutMask.isTargetRectCanThrough = false;
  565. g.hollowOutMask.SetTarget(iconRect);
  566. Transform centerPoint = TargetBody.ins.transform.Find("CenterPoint");
  567. Transform sidePoint = TargetBody.ins.transform.Find("SidePoint");
  568. float countDown = 5;
  569. g.action_Update += () => {
  570. Vector3 centerPos = RectTransformUtility.WorldToScreenPoint(Camera.main, centerPoint.position);
  571. Vector3 sidePos = RectTransformUtility.WorldToScreenPoint(Camera.main, sidePoint.position);
  572. float sizeLen = Mathf.Abs(centerPos.x - sidePos.x) * 2;
  573. iconRect.position = centerPos;
  574. iconRect.sizeDelta = JC.Unity.UI.RectTransformUtils.ScreenV3ToCanvasV3(Vector3.one * sizeLen, iconRect);
  575. g.hollowOutMask.RefreshViewImmediate();
  576. countDown -= Time.deltaTime;
  577. if (countDown <= 0) {
  578. g.clickedWillPlayAudioBtn = false;
  579. g.OnClick_ToNext();
  580. }
  581. g.iconPointerHit.transform.position = CrossHair.ins.transform.position;
  582. };
  583. };
  584. configs.Add(config.key, config);
  585. config = new NewUserGuiderConfig();
  586. config.key = "教程结束";
  587. config.hitActive = false;
  588. config.pointerActive = false;
  589. config.frameTipPivot = "ct";
  590. config.frameTipPosType = 1;
  591. config.frameTipPos = Vector2.zero;
  592. config.onStart = (g) => {
  593. g.GetMaskClickedEvent().AddListener(() => {
  594. OnEnd();
  595. });
  596. GameMode gameMode = GameMgr.ins.gameMode;
  597. if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  598. gameMode.PauseTimeCounting(g);
  599. g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  600. }
  601. };
  602. configs.Add(config.key, config);
  603. }
  604. #if UNITY_EDITOR
  605. bool warn_test = false;
  606. void Update() {
  607. if (!warn_test) {
  608. warn_test = true;
  609. Debug.LogWarning("F3-重置设备校准引导,规则引导");
  610. Debug.LogWarning("F4-重置新手引导记录");
  611. Debug.LogWarning("F5-新手引导强行下一步");
  612. }
  613. if (Input.GetKeyDown(KeyCode.F3)) {
  614. Debug.Log("重置设备校准引导,规则引导");
  615. AimHandler.ins.MagCalibrater = new o0._9Axis.MagnetometerAutoCalibrater();
  616. UserSettings.ins.deviceCalibrateGuideFinish = false;
  617. UserSettings.ins.gameRuleGuideFinish = new HashSet<int>();
  618. }
  619. if (Input.GetKeyDown(KeyCode.F4)) {
  620. Debug.Log("重置新手引导记录");
  621. SaveUserGuideFinished(false);
  622. }
  623. if (Input.GetKeyDown(KeyCode.F5)) {
  624. Debug.Log("新手引导强行下一步");
  625. FindObjectOfType<NewUserGuider>()?.OnClick_ToNext();
  626. }
  627. }
  628. #endif
  629. private Dictionary<string, NewUserGuiderConfig> configs = new Dictionary<string, NewUserGuiderConfig>();
  630. private bool configsInited = false;
  631. [SerializeField] public string curConfigKey = "模块开机";
  632. private List<string> configKeyList = new List<string>(new string[]{
  633. "模块开机",
  634. "连接设备",
  635. "弓箭详情",
  636. "设备-陀螺仪校准",
  637. "陀螺仪校准-开始",
  638. "陀螺仪校准-完成",
  639. "设备-地磁计校准",
  640. "地磁计校准-开始",
  641. "地磁计校准-完成",
  642. "查看设置",
  643. "查看商城",
  644. "切换好友/排行榜",
  645. "展开好友/排行榜",
  646. "联机游戏",
  647. "开始游戏",
  648. "开始-限时游戏",
  649. "限时游戏-选择距离",
  650. "视角归位-触发",
  651. // "视角归位-瞄准",
  652. "准心高亮",
  653. "教程结束",
  654. });
  655. [ContextMenu("执行当前配置")]
  656. void ExecuteCurConfig() {
  657. InitConfigs();
  658. NewUserGuiderConfig config = configs[curConfigKey];
  659. NewUserGuider guider = Instantiate(prefab_NewUserGuider).GetComponent<NewUserGuider>();
  660. guider.config = config;
  661. }
  662. public void OnClickedDestroyed(string configKey) {
  663. int nextIndex = configKeyList.IndexOf(configKey) + 1;
  664. if (nextIndex >= configKeyList.Count) return;
  665. curConfigKey = configKeyList[nextIndex];
  666. ExecuteCurConfig();
  667. }
  668. }
  669. public class NewUserGuiderConfig
  670. {
  671. public string key;
  672. //0:position,1:anchoredPosition
  673. public int hitPosType = 0;
  674. public Vector2 hitPos;
  675. public bool hitActive = true;
  676. //icon pointer rotation z
  677. public float pointerRotZ;
  678. public int pointerPosType = 0;
  679. public Vector2 pointerPos;
  680. public bool pointerActive = true;
  681. //frameTip-Pivot l:left,r:right,t:top,b:bottom,ct:center
  682. public string frameTipPivot = "lt";
  683. public int frameTipPosType = 0;
  684. public Vector2 frameTipPos;
  685. //frameTip text
  686. public string frameTipText = null;
  687. public string frameTipTextKey = null;
  688. public Action<NewUserGuider> onPrepare;
  689. public Action<NewUserGuider> onStart;
  690. public bool delayExecute = true;
  691. }