NewUserGuiderManager.cs 32 KB

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