NewUserGuiderManager.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. g.action_Update += () => {
  194. bool doing = DeviceCalibrateView.ins.calibrateMagDoing;
  195. g.iconPointer.gameObject.SetActive(!doing);
  196. g.iconPointerHit.gameObject.SetActive(!doing);
  197. };
  198. Func<bool> interceptor = () => {
  199. return DeviceCalibrateView.ins.gyrCalibrating;
  200. };
  201. Action operateFinished = () => {
  202. g.hollowOutMask.isTargetRectCanThrough = false;
  203. g.OnClick_ToNext();
  204. };
  205. DeviceCalibrateView.ins.action_OnClickGyrCalibrateInterceptor += interceptor;
  206. DeviceCalibrateView.ins.action_GyrCalibarateOperateAndFinish += operateFinished;
  207. g.action_OnDestroy += () => {
  208. DeviceCalibrateView.ins.action_OnClickGyrCalibrateInterceptor -= interceptor;
  209. DeviceCalibrateView.ins.action_GyrCalibarateOperateAndFinish -= operateFinished;
  210. };
  211. };
  212. configs.Add(config.key, config);
  213. config = new NewUserGuiderConfig();
  214. config.key = "陀螺仪校准-完成";
  215. config.frameTipPivot = "rt";
  216. config.frameTipText = "";
  217. config.onPrepare = (g) => {
  218. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  219. RectTransform btn = DeviceCalibrateView.ins.transform.Find("BtnFinish") as RectTransform;
  220. g.hollowOutMask.SetTarget(btn);
  221. g.SetIconPointerHitOpacity(0.8f);
  222. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  223. g.config.pointerRotZ = 120;
  224. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.2f, 1.2f));
  225. g.frameTip.gameObject.SetActive(false);
  226. };
  227. config.onStart = (g) => {
  228. g.GetMaskClickedEvent().RemoveAllListeners();
  229. Action operateFinished = () => {
  230. g.clickedWillPlayAudioBtn = false;
  231. g.OnClick_ToNext();
  232. };
  233. DeviceCalibrateView.ins.action_OnDestroy += operateFinished;
  234. };
  235. configs.Add(config.key, config);
  236. config = new NewUserGuiderConfig();
  237. config.key = "设备-地磁计校准";
  238. config.frameTipPivot = "rt";
  239. config.onPrepare = (g) => {
  240. if (!DeviceView1.ins) {
  241. g.customPreparePass = false;
  242. return;
  243. }
  244. g.customPreparePass = true;
  245. RectTransform btn = DeviceView1.ins.transform.Find("ItemInfo/BowOptions/MagCalibrate") as RectTransform;
  246. g.hollowOutMask.SetTarget(btn);
  247. // g.hollowOutMask.isTargetRectCanThrough = false;
  248. g.SetIconPointerHitOpacity(0.8f);
  249. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  250. g.config.pointerRotZ = 180;
  251. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
  252. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.3f, 0))
  253. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 60f, g.iconPointer);
  254. };
  255. config.onStart = (g) => {
  256. g.GetMaskClickedEvent().RemoveAllListeners();
  257. Action onclickTarget = () => {
  258. g.clickedWillPlayAudioBtn = false;
  259. g.OnClick_ToNext();
  260. };
  261. DeviceView1.ins.action_OnClickMag += onclickTarget;
  262. g.action_OnDestroy += () => DeviceView1.ins.action_OnClickMag -= onclickTarget;
  263. };
  264. configs.Add(config.key, config);
  265. config = new NewUserGuiderConfig();
  266. config.key = "地磁计校准-开始";
  267. config.frameTipPivot = "rt";
  268. config.frameTipText = "";
  269. config.onPrepare = (g) => {
  270. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  271. RectTransform btn = DeviceCalibrateView.ins.transform.Find("Mag/MagReset") as RectTransform;
  272. g.hollowOutMask.SetTarget(btn);
  273. g.SetIconPointerHitOpacity(0.8f);
  274. g.SetMaskOpacity(0.33f);
  275. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  276. g.config.pointerRotZ = 180;
  277. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
  278. g.frameTip.gameObject.SetActive(false);
  279. };
  280. config.onStart = (g) => {
  281. g.GetMaskClickedEvent().RemoveAllListeners();
  282. g.action_Update += () => {
  283. bool doing = DeviceCalibrateView.ins.calibrateMagDoing;
  284. g.iconPointer.gameObject.SetActive(!doing);
  285. g.iconPointerHit.gameObject.SetActive(!doing);
  286. };
  287. Func<bool> interceptor = () => {
  288. return DeviceCalibrateView.ins.calibrateMagDoing;
  289. };
  290. Action operateFinished = () => {
  291. g.hollowOutMask.isTargetRectCanThrough = false;
  292. g.OnClick_ToNext();
  293. };
  294. DeviceCalibrateView.ins.action_OnClickMagCalibrateInterceptor += interceptor;
  295. DeviceCalibrateView.ins.action_MagCalibarateOperateAndFinish += operateFinished;
  296. g.action_OnDestroy += () => {
  297. DeviceCalibrateView.ins.action_OnClickMagCalibrateInterceptor -= interceptor;
  298. DeviceCalibrateView.ins.action_MagCalibarateOperateAndFinish -= operateFinished;
  299. };
  300. };
  301. configs.Add(config.key, config);
  302. config = new NewUserGuiderConfig();
  303. config.key = "地磁计校准-完成";
  304. config.frameTipPivot = "rt";
  305. config.frameTipText = "";
  306. config.onPrepare = (g) => {
  307. g.SetCanvasSortOrder(DeviceCalibrateView.ins.GetComponent<Canvas>().sortingOrder + 1);
  308. RectTransform btn = DeviceCalibrateView.ins.transform.Find("BtnFinish") as RectTransform;
  309. g.hollowOutMask.SetTarget(btn);
  310. g.SetIconPointerHitOpacity(0.8f);
  311. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  312. g.config.pointerRotZ = 120;
  313. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.2f, 1.2f));
  314. g.frameTip.gameObject.SetActive(false);
  315. };
  316. config.onStart = (g) => {
  317. g.GetMaskClickedEvent().RemoveAllListeners();
  318. Action operateFinished = () => {
  319. FindObjectOfType<DeviceView1>()?.OnClick_Back();
  320. g.clickedWillPlayAudioBtn = false;
  321. g.OnClick_ToNext();
  322. };
  323. DeviceCalibrateView.ins.action_OnDestroy += operateFinished;
  324. };
  325. configs.Add(config.key, config);
  326. config = new NewUserGuiderConfig();
  327. config.key = "查看设置";
  328. config.frameTipPivot = "rt";
  329. config.onPrepare = (g) => {
  330. RectTransform btn = GameObject.Find("TopBarView/TopBar/IconSetUp").GetComponent<RectTransform>();
  331. g.hollowOutMask.SetTarget(btn);
  332. g.hollowOutMask.isTargetRectCanThrough = false;
  333. g.SetIconPointerHitOpacity(0.6f);
  334. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  335. g.config.pointerRotZ = 180;
  336. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * -0.1f);
  337. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  338. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
  339. };
  340. configs.Add(config.key, config);
  341. config = new NewUserGuiderConfig();
  342. config.key = "查看商城";
  343. config.frameTipPivot = "rt";
  344. config.onPrepare = (g) => {
  345. RectTransform btn = GameObject.Find("TopBarView/TopBar/IconShop").GetComponent<RectTransform>();
  346. g.hollowOutMask.SetTarget(btn);
  347. g.hollowOutMask.isTargetRectCanThrough = false;
  348. g.SetIconPointerHitOpacity(0.6f);
  349. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  350. g.config.pointerRotZ = 180;
  351. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * -0.1f);
  352. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  353. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
  354. };
  355. configs.Add(config.key, config);
  356. config = new NewUserGuiderConfig();
  357. config.key = "切换好友/排行榜";
  358. config.frameTipPivot = "lt";
  359. config.onPrepare = (g) => {
  360. RectTransform btn = GameObject.Find("HomeView/FriendBar/FrameBtnTop").GetComponent<RectTransform>();
  361. g.hollowOutMask.SetTarget(btn);
  362. g.hollowOutMask.isTargetRectCanThrough = false;
  363. g.SetIconPointerHitOpacity(0.6f);
  364. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  365. g.config.pointerRotZ = -30;
  366. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.2f, 0.9f));
  367. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.2f, 0));
  368. };
  369. configs.Add(config.key, config);
  370. config = new NewUserGuiderConfig();
  371. config.key = "展开好友/排行榜";
  372. config.frameTipPivot = "lc";
  373. config.onPrepare = (g) => {
  374. RectTransform btn = GameObject.Find("HomeView/FriendBar/FrameBtnBottom").GetComponent<RectTransform>();
  375. g.hollowOutMask.SetTarget(btn);
  376. g.hollowOutMask.isTargetRectCanThrough = false;
  377. g.SetIconPointerHitOpacity(0.8f);
  378. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  379. g.config.pointerRotZ = -30;
  380. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1, 0.9f));
  381. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.5f, 0.5f));
  382. };
  383. configs.Add(config.key, config);
  384. config = new NewUserGuiderConfig();
  385. config.key = "联机游戏";
  386. config.frameTipPivot = "lt";
  387. config.onPrepare = (g) => {
  388. RectTransform btn = GameObject.Find("HomeView/RightPanel/Item (1)").GetComponent<RectTransform>();
  389. g.hollowOutMask.SetTarget(btn);
  390. g.hollowOutMask.isTargetRectCanThrough = false;
  391. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.5f, 0.6f));
  392. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.9f));
  393. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  394. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.left * 150f, g.iconPointer);
  395. };
  396. configs.Add(config.key, config);
  397. config = new NewUserGuiderConfig();
  398. config.key = "开始游戏";
  399. config.frameTipPivot = "lt";
  400. config.onPrepare = (g) => {
  401. RectTransform btn = GameObject.Find("HomeView/RightPanel/Item").GetComponent<RectTransform>();
  402. g.hollowOutMask.SetTarget(btn);
  403. // g.hollowOutMask.isTargetRectCanThrough = false;
  404. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.5f, 0.6f));
  405. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.9f));
  406. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
  407. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.left * 150f, g.iconPointer);
  408. };
  409. config.onStart = (g) => {
  410. g.GetMaskClickedEvent().RemoveAllListeners();
  411. Action onClickTarget = () => {
  412. g.clickedWillPlayAudioBtn = false;
  413. g.OnClick_ToNext();
  414. };
  415. HomeView.ins.action_OnClickStartGame += onClickTarget;
  416. g.action_OnDestroy += () => HomeView.ins.action_OnClickStartGame -= onClickTarget;
  417. };
  418. configs.Add(config.key, config);
  419. config = new NewUserGuiderConfig();
  420. config.key = "开始-限时游戏";
  421. config.frameTipPivot = "lt";
  422. config.onPrepare = (g) => {
  423. if (!GameStartView.ins) {
  424. g.customPreparePass = false;
  425. return;
  426. }
  427. g.customPreparePass = true;
  428. RectTransform btn = GameStartView.ins.transform.Find("EntryList/Item (1)") as RectTransform;
  429. g.hollowOutMask.SetTarget(btn);
  430. // g.hollowOutMask.isTargetRectCanThrough = false;
  431. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  432. g.config.pointerRotZ = 180;
  433. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.2f, 0.3f));
  434. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.4f, 0.15f))
  435. + RectTransformUtils.CanvasV3ToScreenV3(Vector3.left * 150f, g.iconPointer);
  436. };
  437. config.onStart = (g) => {
  438. g.GetMaskClickedEvent().RemoveAllListeners();
  439. };
  440. configs.Add(config.key, config);
  441. config = new NewUserGuiderConfig();
  442. config.key = "限时游戏-选择距离";
  443. config.frameTipPivot = "lc";
  444. config.onPrepare = (g) => {
  445. if (g.hollowOutMask.enabled) g.hollowOutMask.enabled = false;
  446. g.ActiveBtnSkip(false);
  447. if (!TimeLimitGameDistanceSelectView.ins) {
  448. g.customPreparePass = false;
  449. return;
  450. }
  451. g.customPreparePass = true;
  452. g.hollowOutMask.enabled = true;
  453. g.ActiveBtnSkip(true);
  454. RectTransform btn = TimeLimitGameDistanceSelectView.ins.transform.Find("Layout/Item") as RectTransform;
  455. g.hollowOutMask.SetTarget(btn);
  456. // g.hollowOutMask.isTargetRectCanThrough = false;
  457. g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
  458. g.config.pointerRotZ = -30;
  459. g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.85f, 0.5f));
  460. g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.15f, 0.4f));
  461. };
  462. config.onStart = (g) => {
  463. g.GetMaskClickedEvent().RemoveAllListeners();
  464. Action onClickTarget = () => {
  465. g.clickedWillPlayAudioBtn = false;
  466. g.OnClick_ToNext();
  467. };
  468. TimeLimitGameDistanceSelectView.ins.action_OnClickSelectDistance += onClickTarget;
  469. g.action_OnDestroy += () => {
  470. if (!TimeLimitGameDistanceSelectView.ins) return;
  471. TimeLimitGameDistanceSelectView.ins.action_OnClickSelectDistance -= onClickTarget;
  472. };
  473. };
  474. configs.Add(config.key, config);
  475. config = new NewUserGuiderConfig();
  476. config.key = "视角归位-触发";
  477. config.frameTipPivot = "rb";
  478. config.frameTipPos = Vector2.zero;
  479. config.onPrepare = (g) => {
  480. RectTransform btn4 = GameAssistUI.ins.transform.Find("Button4") as RectTransform;
  481. g.hollowOutMask.SetTarget(btn4);
  482. RectTransform btn4_img = btn4.Find("Image") as RectTransform;
  483. g.config.hitPos = btn4_img.position;
  484. g.config.pointerRotZ = 120;
  485. g.config.pointerPos = btn4_img.position + RectTransformUtils.CanvasV3ToScreenV3(new Vector3(-60, 60), btn4);
  486. g.config.frameTipPos = btn4_img.position + RectTransformUtils.CanvasV3ToScreenV3(new Vector3(-120, 120), btn4);
  487. RectTransform iconHumanShoot = g.transform.Find("IconHumanShoot") as RectTransform;
  488. iconHumanShoot.pivot = Vector2.one * 0.5f;
  489. iconHumanShoot.anchoredPosition = new Vector2(-350, -85);
  490. iconHumanShoot.gameObject.SetActive(true);
  491. GameMode gameMode = GameMgr.ins.gameMode;
  492. if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  493. gameMode.PauseTimeCounting(g);
  494. g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  495. }
  496. };
  497. config.onStart = (g) => {
  498. g.GetMaskClickedEvent().RemoveAllListeners();
  499. Action onClickTarget = () => {
  500. g.gameObject.SetActive(false);
  501. AutoResetView.ins.action_OnDestroy += () => {
  502. if (!g) return;
  503. g.clickedWillPlayAudioBtn = false;
  504. g.OnClick_ToNext();
  505. };
  506. };
  507. GameAssistUI.ins.action_OnClickBtnIdentity += onClickTarget;
  508. g.action_OnDestroy += () => GameAssistUI.ins.action_OnClickBtnIdentity -= onClickTarget;
  509. };
  510. configs.Add(config.key, config);
  511. // config = new NewUserGuiderConfig();
  512. // config.key = "视角归位-瞄准";
  513. // config.frameTipPivot = "lc";
  514. // config.onPrepare = (g) => {
  515. // float rectSideLen = RectTransformUtils.ScreenV3ToCanvasV3(Vector3.right * Screen.height * 100 / 720f, g.GetComponent<RectTransform>()).x;
  516. // Vector2 rectSize = new Vector2(rectSideLen, rectSideLen);
  517. // RectTransform iconRect = g.transform.Find("IconRect") as RectTransform;
  518. // iconRect.sizeDelta = rectSize;
  519. // iconRect.gameObject.SetActive(true);
  520. // g.hollowOutMask.isTargetRectCanThrough = false;
  521. // g.hollowOutMask.SetTarget(iconRect);
  522. // g.config.hitPosType = 1;
  523. // g.config.hitPos = Vector2.zero;
  524. // g.config.pointerPosType = 1;
  525. // g.config.pointerRotZ = 120;
  526. // g.config.pointerPos = new Vector2(-rectSideLen / 2 * 1.2f, rectSideLen / 2 * 1.1f);
  527. // RectTransform iconHumanShoot = g.transform.Find("IconHumanShoot") as RectTransform;
  528. // iconHumanShoot.anchoredPosition = g.config.pointerPos;
  529. // iconHumanShoot.gameObject.SetActive(true);
  530. // g.config.frameTipPosType = 1;
  531. // g.config.frameTipPos = new Vector2(rectSideLen / 2 * 1.3f, 0);
  532. // GameMode gameMode = GameMgr.ins.gameMode;
  533. // if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  534. // gameMode.PauseTimeCounting(g);
  535. // g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  536. // }
  537. // };
  538. // configs.Add(config.key, config);
  539. config = new NewUserGuiderConfig();
  540. config.key = "准心高亮";
  541. config.hitPosType = 1;
  542. config.hitPos = Vector2.zero;
  543. config.pointerActive = false;
  544. config.frameTipText = "";
  545. config.onStart = (g) => {
  546. g.GetMaskClickedEvent().RemoveAllListeners();
  547. GameMode gameMode = GameMgr.ins.gameMode;
  548. if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  549. gameMode.PauseTimeCounting(g);
  550. g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  551. }
  552. g.AnimateIconPointerHit();
  553. RectTransform iconRect = g.transform.Find("IconRect") as RectTransform;
  554. iconRect.gameObject.SetActive(true);
  555. g.hollowOutMask.isTargetRectCanThrough = false;
  556. g.hollowOutMask.SetTarget(iconRect);
  557. Transform centerPoint = TargetBody.ins.transform.Find("CenterPoint");
  558. Transform sidePoint = TargetBody.ins.transform.Find("SidePoint");
  559. float countDown = 5;
  560. g.action_Update += () => {
  561. Vector3 centerPos = RectTransformUtility.WorldToScreenPoint(Camera.main, centerPoint.position);
  562. Vector3 sidePos = RectTransformUtility.WorldToScreenPoint(Camera.main, sidePoint.position);
  563. float sizeLen = Mathf.Abs(centerPos.x - sidePos.x) * 2;
  564. iconRect.position = centerPos;
  565. iconRect.sizeDelta = JC.Unity.UI.RectTransformUtils.ScreenV3ToCanvasV3(Vector3.one * sizeLen, iconRect);
  566. g.hollowOutMask.RefreshViewImmediate();
  567. countDown -= Time.deltaTime;
  568. if (countDown <= 0) {
  569. g.clickedWillPlayAudioBtn = false;
  570. g.OnClick_ToNext();
  571. }
  572. };
  573. };
  574. configs.Add(config.key, config);
  575. config = new NewUserGuiderConfig();
  576. config.key = "教程结束";
  577. config.hitActive = false;
  578. config.pointerActive = false;
  579. config.frameTipPivot = "ct";
  580. config.frameTipPosType = 1;
  581. config.frameTipPos = Vector2.zero;
  582. config.onStart = (g) => {
  583. g.GetMaskClickedEvent().AddListener(() => {
  584. OnEnd();
  585. });
  586. GameMode gameMode = GameMgr.ins.gameMode;
  587. if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
  588. gameMode.PauseTimeCounting(g);
  589. g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
  590. }
  591. };
  592. configs.Add(config.key, config);
  593. }
  594. #if UNITY_EDITOR
  595. bool warn_test = false;
  596. void Update() {
  597. if (!warn_test) {
  598. warn_test = true;
  599. Debug.LogWarning("F3-重置设备校准引导,规则引导");
  600. Debug.LogWarning("F4-重置新手引导记录");
  601. Debug.LogWarning("F5-新手引导强行下一步");
  602. }
  603. if (Input.GetKeyDown(KeyCode.F3)) {
  604. Debug.Log("重置设备校准引导,规则引导");
  605. AimHandler.ins.MagCalibrater = new o0._9Axis.MagnetometerAutoCalibrater();
  606. UserSettings.ins.deviceCalibrateGuideFinish = false;
  607. UserSettings.ins.gameRuleGuideFinish = new HashSet<int>();
  608. }
  609. if (Input.GetKeyDown(KeyCode.F4)) {
  610. Debug.Log("重置新手引导记录");
  611. SaveUserGuideFinished(false);
  612. }
  613. if (Input.GetKeyDown(KeyCode.F5)) {
  614. Debug.Log("新手引导强行下一步");
  615. FindObjectOfType<NewUserGuider>()?.OnClick_ToNext();
  616. }
  617. }
  618. #endif
  619. private Dictionary<string, NewUserGuiderConfig> configs = new Dictionary<string, NewUserGuiderConfig>();
  620. private bool configsInited = false;
  621. [SerializeField] public string curConfigKey = "模块开机";
  622. private List<string> configKeyList = new List<string>(new string[]{
  623. "模块开机",
  624. "连接设备",
  625. "弓箭详情",
  626. "设备-陀螺仪校准",
  627. "陀螺仪校准-开始",
  628. "陀螺仪校准-完成",
  629. "设备-地磁计校准",
  630. "地磁计校准-开始",
  631. "地磁计校准-完成",
  632. "查看设置",
  633. "查看商城",
  634. "切换好友/排行榜",
  635. "展开好友/排行榜",
  636. "联机游戏",
  637. "开始游戏",
  638. "开始-限时游戏",
  639. "限时游戏-选择距离",
  640. "视角归位-触发",
  641. // "视角归位-瞄准",
  642. "准心高亮",
  643. "教程结束",
  644. });
  645. [ContextMenu("执行当前配置")]
  646. void ExecuteCurConfig() {
  647. InitConfigs();
  648. NewUserGuiderConfig config = configs[curConfigKey];
  649. NewUserGuider guider = Instantiate(prefab_NewUserGuider).GetComponent<NewUserGuider>();
  650. guider.config = config;
  651. }
  652. public void OnClickedDestroyed(string configKey) {
  653. int nextIndex = configKeyList.IndexOf(configKey) + 1;
  654. if (nextIndex >= configKeyList.Count) return;
  655. curConfigKey = configKeyList[nextIndex];
  656. ExecuteCurConfig();
  657. }
  658. }
  659. public class NewUserGuiderConfig
  660. {
  661. public string key;
  662. //0:position,1:anchoredPosition
  663. public int hitPosType = 0;
  664. public Vector2 hitPos;
  665. public bool hitActive = true;
  666. //icon pointer rotation z
  667. public float pointerRotZ;
  668. public int pointerPosType = 0;
  669. public Vector2 pointerPos;
  670. public bool pointerActive = true;
  671. //frameTip-Pivot l:left,r:right,t:top,b:bottom,ct:center
  672. public string frameTipPivot = "lt";
  673. public int frameTipPosType = 0;
  674. public Vector2 frameTipPos;
  675. //frameTip text
  676. public string frameTipText = null;
  677. public string frameTipTextKey = null;
  678. public Action<NewUserGuider> onPrepare;
  679. public Action<NewUserGuider> onStart;
  680. }