NewUserGuiderManager.cs 37 KB

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