| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using JC.Unity.UI;
- public class NewUserGuiderManager : MonoBehaviour
- {
- [SerializeField] GameObject prefab_NewUserGuider;
- public static NewUserGuiderManager ins;
- void Awake()
- {
- if (ins) {
- Destroy(gameObject);
- return;
- }
- ins = this;
- DontDestroyOnLoad(gameObject);
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- if (onSceneLoaded_added) SceneManager.sceneLoaded -= onSceneLoaded;
- }
- void Start()
- {
- SceneManager.sceneLoaded += onSceneLoaded; onSceneLoaded_added = true;
- if (!IsUserGuideFinished()) {
- ExecuteCurConfig();
- SaveUserGuideFinished(true);
- }
- }
- bool onSceneLoaded_added = false;
- void onSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { //初始话的场景不会触发
- if (scene.name == "Game" && GameMgr.gameType == 1) {
- switch (curConfigKey) {
- case "开始-限时游戏":
- OnClickedDestroyed(curConfigKey);
- break;
- case "限时游戏-选择距离":
- ExecuteCurConfig();
- break;
- }
- }
- }
- public void OnSkip()
- {
- curConfigKey = null;
- SaveUserGuideFinished(true);
- }
- public void OnEnd()
- {
- curConfigKey = null;
- SaveUserGuideFinished(true);
- }
- public void ReviewNewUserGuide()
- {
- int viewCount = PersistenHandler.ins.menuBackCtr.views.Count;
- for (int i = 0; i < viewCount; i++) {
- PersistenHandler.ins.menuBackCtr.OnOnceBack();
- }
- curConfigKey = "模块开机";
- ExecuteCurConfig();
- }
- void SaveUserGuideFinished(bool finished) {
- PlayerPrefs.SetInt("NewUserGuiderFinished", finished ? 1 : 0);
- }
- bool IsUserGuideFinished() {
- return PlayerPrefs.GetInt("NewUserGuiderFinished", 0) == 1 ? true : false;
- }
-
- void InitConfigs()
- {
- if (configsInited) return;
- configsInited = true;
- NewUserGuiderConfig config = new NewUserGuiderConfig();
- config.hitPosType = 1;
- config.hitPos = new Vector2(-86.4f, -70.3f);
- config.pointerRotZ = 120;
- config.pointerPosType = 1;
- config.pointerPos = new Vector2(-155, -31);
- config.frameTipPosType = 1;
- config.frameTipPos = new Vector2(-73.5f, 106);
- config.frameTipText = "长按模块上的<color=#FFA500>“开机”</color>键,当绿灯闪烁时,即模块处于等待连接的状态。";
- config.onStart = (g) => g.transform.Find("IconModule").gameObject.SetActive(true);
- configs.Add("模块开机", config);
- config = new NewUserGuiderConfig();
- config.hitActive = false;
- config.pointerActive = false;
- config.frameTipPivot = "ct";
- config.frameTipPosType = 1;
- config.frameTipPos = Vector2.zero;
- config.frameTipText = "恭喜您完成了本次新手教程,下次如果还\n要" +
- "<color=#FFA500>了解本教程</color>请在<color=#FFA500>游戏教程中选择新手指导</color>。";
- config.onStart = (g) => {
- g.GetMaskClickedEvent().AddListener(() => {
- OnEnd();
- });
- GameMode gameMode = GameMgr.ins.gameMode;
- if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
- gameMode.PauseTimeCounting(g);
- g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
- }
- };
- configs.Add("教程结束", config);
-
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "rb";
- config.frameTipPos = Vector2.zero;
- config.frameTipText = "点击<color=#FFA500>视角归位按钮,按完按键后立刻以标准射箭姿势瞄准\n靶心</color>," +
- "3秒后完成视角的自动归位。";
- config.onPrepare = (g) => {
- if (!GameAssistUI.ins) {
- g.customPreparePass = false;
- return;
- }
- g.customPreparePass = true;
- g.hollowOutMask.isTargetRectCanThrough = false;
- RectTransform btn4 = GameAssistUI.ins.transform.Find("Button4") as RectTransform;
- g.hollowOutMask.SetTarget(btn4);
- RectTransform btn4_img = btn4.Find("Image") as RectTransform;
- g.config.hitPos = btn4_img.position;
- g.config.pointerRotZ = 120;
- g.config.pointerPos = btn4_img.position + RectTransformUtils.CanvasV3ToScreenV3(new Vector3(-60, 60), btn4);
- g.config.frameTipPos = btn4_img.position + RectTransformUtils.CanvasV3ToScreenV3(new Vector3(-120, 120), btn4);
- // g.clickedWillPlayAudioBtn = false;
- // g.GetMaskClickedEvent().AddListener(() => {
- // btn4.GetComponent<Button>().onClick.Invoke();
- // });
- GameMode gameMode = GameMgr.ins.gameMode;
- if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
- gameMode.PauseTimeCounting(g);
- g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
- }
- };
- configs.Add("视角归位-触发", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lc";
- config.frameTipText = "请参考图中小人的姿势,<color=#FFA500>立即瞄准屏幕中\n的靶心</color>,3秒后完成视角的自动归位。";
- config.onPrepare = (g) => {
- float rectSideLen = RectTransformUtils.ScreenV3ToCanvasV3(Vector3.right * Screen.height * 100 / 720f, g.GetComponent<RectTransform>()).x;
- Vector2 rectSize = new Vector2(rectSideLen, rectSideLen);
- RectTransform iconRect = g.transform.Find("IconRect") as RectTransform;
- iconRect.sizeDelta = rectSize;
- iconRect.gameObject.SetActive(true);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.hollowOutMask.SetTarget(iconRect);
- g.config.hitPosType = 1;
- g.config.hitPos = Vector2.zero;
- g.config.pointerPosType = 1;
- g.config.pointerRotZ = 120;
- g.config.pointerPos = new Vector2(-rectSideLen / 2 * 1.2f, rectSideLen / 2 * 1.1f);
- RectTransform iconHumanShoot = g.transform.Find("IconHumanShoot") as RectTransform;
- iconHumanShoot.anchoredPosition = g.config.pointerPos;
- iconHumanShoot.gameObject.SetActive(true);
- g.config.frameTipPosType = 1;
- g.config.frameTipPos = new Vector2(rectSideLen / 2 * 1.3f, 0);
- GameMode gameMode = GameMgr.ins.gameMode;
- if (gameMode.GetType().Equals(typeof(TimeLimitGameMode))) {
- gameMode.PauseTimeCounting(g);
- g.action_OnDestroy += () => gameMode.ResumeTimeCounting(g);
- }
- };
- configs.Add("视角归位-瞄准", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lb";
- config.frameTipText = "点击<color=#FFA500>“连接”</color>等待设备提示连接成功,此时模块处于绿灯常亮的状态。";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("HomeView/HomeViewRenderBow/Btn").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
-
- g.SetIconPointerHitOpacity(0.5f);
- g.config.hitPos = btn.position;
- g.config.pointerPos = btn.position + RectTransformUtils.CanvasV3ToScreenV3(Vector3.up * 80f, btn);
- g.config.frameTipPos = btn.position + RectTransformUtils.CanvasV3ToScreenV3(Vector3.up * 150f, btn);
- };
- configs.Add("连接设备", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lt";
- config.frameTipText = "点击<color=#FFA500>联机游戏</color>进入游戏";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("HomeView/RightPanel/Item (1)").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.5f, 0.6f));
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.9f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero);
- };
- configs.Add("联机游戏", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lt";
- config.frameTipText = "点击<color=#FFA500>开始游戏</color>,开始对局吧!";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("HomeView/RightPanel/Item").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.5f, 0.6f));
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.9f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero);
- g.GetMaskClickedEvent().AddListener(() => {
- GameObject.Instantiate(SceneResMgr.ins.GetPrefab("GameStartView"));
- });
- };
- configs.Add("开始游戏", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lt";
- config.frameTipText = "点击<color=#FFA500>弓箭</color>,查看更多信息。";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("HomeView/HomeViewRenderBow/BtnShowDetail").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.7f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.8f, 0.5f));
- HomeViewRenderBow homeViewRenderBow = FindObjectOfType<HomeViewRenderBow>();
- if (homeViewRenderBow) {
- g.clickedWillPlayAudioBtn = false;
- g.GetMaskClickedEvent().AddListener(homeViewRenderBow.OnClick_ShowDeviceView);
- }
-
- };
- configs.Add("弓箭详情", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "rt";
- config.frameTipText = "点击查看<color=#FFA500>商城</color>";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("TopBarView/TopBar/IconShop").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.SetIconPointerHitOpacity(0.6f);
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = 180;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * -0.1f);
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
- + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
- };
- configs.Add("查看商城", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "rt";
- config.frameTipText = "点击<color=#FFA500>设置</color>了解更多";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("TopBarView/TopBar/IconSetUp").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.SetIconPointerHitOpacity(0.6f);
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = 180;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * -0.1f);
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.zero)
- + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
- };
- configs.Add("查看设置", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lt";
- config.frameTipText = "点击切换<color=#FFA500>好友/排行榜</color>";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("HomeView/FriendBar/FrameBtnTop").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.SetIconPointerHitOpacity(0.6f);
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = -30;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.2f, 0.9f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.2f, 0));
- };
- configs.Add("切换好友/排行榜", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lc";
- config.frameTipText = "展开查看<color=#FFA500>更多详情</color>";
- config.onPrepare = (g) => {
- RectTransform btn = GameObject.Find("HomeView/FriendBar/FrameBtnBottom").GetComponent<RectTransform>();
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.SetIconPointerHitOpacity(0.8f);
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = -30;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1, 0.9f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.5f, 0.5f));
- };
- configs.Add("展开好友/排行榜", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "rt";
- config.frameTipText = "将安装了模块的智能弓箭<color=#FFA500>静置在一个平面</color>";
- config.onPrepare = (g) => {
- if (!DeviceView1.ins) {
- g.customPreparePass = false;
- return;
- }
- g.customPreparePass = true;
- RectTransform btn = DeviceView1.ins.transform.Find("ItemInfo/BowOptions/GyrCalibrate") as RectTransform;
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.SetIconPointerHitOpacity(0.8f);
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = 180;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.3f, 0))
- + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 80f, g.iconPointer);
- };
- configs.Add("设备-陀螺仪校准", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "rt";
- config.frameTipText = "将安装了模块的智能弓箭<color=#FFA500>沿着每一个轴旋转</color>";
- config.onPrepare = (g) => {
- if (!DeviceView1.ins) {
- g.customPreparePass = false;
- return;
- }
- g.customPreparePass = true;
- RectTransform btn = DeviceView1.ins.transform.Find("ItemInfo/BowOptions/MagCalibrate") as RectTransform;
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.SetIconPointerHitOpacity(0.8f);
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = 180;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(-0.1f, 0.2f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.3f, 0))
- + RectTransformUtils.CanvasV3ToScreenV3(Vector3.down * 60f, g.iconPointer);
- DeviceView1 deviceView1 = FindObjectOfType<DeviceView1>();
- if (deviceView1) {
- g.clickedWillPlayAudioBtn = false;
- g.GetMaskClickedEvent().AddListener(deviceView1.OnClick_Back);
- }
- };
- configs.Add("设备-地磁计校准", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lt";
- config.frameTipText = "点击<color=#FFA500>“限时游戏”</color>选择游戏类型";
- config.onPrepare = (g) => {
- if (!GameStartView.ins) {
- g.customPreparePass = false;
- return;
- }
- g.customPreparePass = true;
- RectTransform btn = GameStartView.ins.transform.Find("EntryList/Item (1)") as RectTransform;
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = 180;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.2f, 0.3f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.4f, 0.15f));
- };
- config.onStart = (g) => {
- GameStartView gameStartView = FindObjectOfType<GameStartView>();
- if (gameStartView) {
- string ck = g.config.key;
- g.GetMaskClickedEvent().RemoveAllListeners();
- g.GetMaskClickedEvent().AddListener(() => {
- gameStartView.GoTo("限时");
- //后续在NewUserGuiderManager.onSceneLoaded触发
- });
- }
- };
- configs.Add("开始-限时游戏", config);
- config = new NewUserGuiderConfig();
- config.frameTipPivot = "lc";
- config.frameTipText = "选择距离<color=#FFA500>“10米”</color>开始游戏吧!";
- config.onPrepare = (g) => {
- if (g.hollowOutMask.enabled) g.hollowOutMask.enabled = false;
- if (!TimeLimitGameDistanceSelectView.ins) {
- g.customPreparePass = false;
- return;
- }
- g.customPreparePass = true;
- g.hollowOutMask.enabled = true;
- RectTransform btn = TimeLimitGameDistanceSelectView.ins.transform.Find("Layout/Item") as RectTransform;
- g.hollowOutMask.SetTarget(btn);
- g.hollowOutMask.isTargetRectCanThrough = false;
- g.config.hitPos = RectTransformUtils.GetPositionByPivot(btn, Vector2.one * 0.5f);
- g.config.pointerRotZ = -30;
- g.config.pointerPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(0.85f, 0.5f));
- g.config.frameTipPos = RectTransformUtils.GetPositionByPivot(btn, new Vector2(1.15f, 0.4f));
- g.clickedWillPlayAudioBtn = false;
- g.GetMaskClickedEvent().AddListener(() => {
- btn.GetComponent<Button>().onClick.Invoke();
- });
- };
- configs.Add("限时游戏-选择距离", config);
- }
- #if UNITY_EDITOR
- bool warn_test = false;
- void Update() {
- if (!warn_test) {
- warn_test = true;
- Debug.LogWarning("F3-重置设备校准引导,规则引导");
- Debug.LogWarning("F4-重置新手引导记录");
- }
- if (Input.GetKeyDown(KeyCode.F3)) {
- Debug.Log("重置设备校准引导,规则引导");
- AimHandler.ins.MagCalibrater = new o0._9Axis.MagnetometerAutoCalibrater();
- UserSettings.ins.deviceCalibrateGuideFinish = false;
- UserSettings.ins.gameRuleGuideFinish = new HashSet<int>();
- }
- if (Input.GetKeyDown(KeyCode.F4)) {
- Debug.Log("重置新手引导记录");
- SaveUserGuideFinished(false);
- }
- }
- #endif
- private Dictionary<string, NewUserGuiderConfig> configs = new Dictionary<string, NewUserGuiderConfig>();
- private bool configsInited = false;
- [SerializeField] public string curConfigKey = "模块开机";
- private List<string> configKeyList = new List<string>(new string[]{
- "模块开机",
- "连接设备",
- "弓箭详情",
- "设备-陀螺仪校准",
- "设备-地磁计校准",
- "查看设置",
- "查看商城",
- "切换好友/排行榜",
- "展开好友/排行榜",
- "联机游戏",
- "开始游戏",
- "开始-限时游戏",
- "限时游戏-选择距离",
- "视角归位-触发",
- "视角归位-瞄准",
- "教程结束",
- });
- void ExecuteCurConfig() {
- InitConfigs();
- NewUserGuiderConfig config = configs[curConfigKey];
- config.key = curConfigKey;
- NewUserGuider guider = Instantiate(prefab_NewUserGuider).GetComponent<NewUserGuider>();
- guider.config = config;
- }
- public void OnClickedDestroyed(string configKey) {
- int nextIndex = configKeyList.IndexOf(configKey) + 1;
- if (nextIndex >= configKeyList.Count) return;
- curConfigKey = configKeyList[nextIndex];
- ExecuteCurConfig();
- }
- }
- public class NewUserGuiderConfig
- {
- public string key;
- //0:position,1:anchoredPosition
- public int hitPosType = 0;
- public Vector2 hitPos;
- public bool hitActive = true;
- //icon pointer rotation z
- public float pointerRotZ;
- public int pointerPosType = 0;
- public Vector2 pointerPos;
- public bool pointerActive = true;
- //frameTip-Pivot l:left,r:right,t:top,b:bottom,ct:center
- public string frameTipPivot = "lt";
- public int frameTipPosType = 0;
- public Vector2 frameTipPos;
- //frameTip text
- public string frameTipText;
- public Action<NewUserGuider> onPrepare;
- public Action<NewUserGuider> onStart;
- }
|