NewUserGuiderManager.cs 32 KB

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