NewUserGuiderManager.cs 38 KB

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