NewUserGuiderManager.cs 39 KB

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