NewUserGuiderManager.cs 39 KB

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