Unity开发 MMORPG类游戏引导系统

38 篇文章 2 订阅

下面展示一些 MMORPG类游戏引导系统逻辑代码

using LitJson;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 class GuideController : MonoBehaviour
    {
        public static GuideController instance;

        public List<GameObject> tapTipList;
        public List<GameObject> Guides;//引导窗口
        public List<GameObject> tapTips;//点击提示窗口
        public List<GameObject> playSkillTips;//技巧提示
        [HideInInspector]
        public GameObject swapTip;

        //判断Unity端引导过程是否结束
        [HideInInspector]
        public bool inGuide;
        
        [HideInInspector]
        public int nextStep;

        /// <summary>
        /// 玩家当前引导步数
        /// </summary>
        [HideInInspector]
        public int StepSign = 0;

        [HideInInspector]
        //引导是否没有
        public bool fromBegin;

        [HideInInspector]
        /// <summary>
        /// 用于判断是否第一次触发了吃饼干,只用一次
        /// </summary>
        public bool afterFood;

        [HideInInspector]
        /// <summary>
        /// 用于判断是否第一次触发了zombi死亡,只用一次
        /// </summary>
        public bool zombi;

        [HideInInspector]
        /// <summary>
        /// 用于判断是否第一次触发了mummy死亡
        /// </summary>
        public bool mummy;
        MainView mainView;
        [HideInInspector]
        /// <summary>
        /// 用于存储引导键值对
        /// </summary>
        public Dictionary<string, string> guideDic = new Dictionary<string, string>();

        public IEnumerator stopGuide2;

        void Awake()
        {
            instance = this;
            mainView = MainView.instance;
            stopGuide2 = null;
            foreach (GameObject temp in Guides)
            {
                temp.SetActive(false);
            }
        }

        //temp Before blackDragon enter.
        public void ShowBlackDragonGuide()
        {
            KnapsackView kView = KnapsackView.instance;
            MainView mView = MainView.instance;
            //先让蒙版遮住所有,获取物品的面板消失
            kView.settleMentPop.SetActive(false);
            mView.guideMask.SetActive(true);
            mView.guideMask.transform.SetAsLastSibling();
            mView.blackDragonTip.transform.SetAsLastSibling();

            kView.closeButton.interactable = false;
            if (kView.inventoryPopup.closeButton)
                kView.inventoryPopup.closeButton.interactable = false;

            foreach (GameObject item in tapTipList)
            {
                item.SetActive(false);
            }
            mView.blackDragonTip.SetActive(true);
            //游戏暂停
            //Time.timeScale = 0;
        }

        public IEnumerator ShowRedDragonGuide()
        {
            KnapsackView kView = KnapsackView.instance;
            MainView mView = MainView.instance;
            yield return new WaitForSeconds(2);
            //先让蒙版遮住所有,获取物品的面板消失
            kView.settleMentPop.SetActive(false);
            mView.guideMask.SetActive(true);
            mView.guideMask.transform.SetAsLastSibling();
            mView.redDragonTip.transform.SetAsLastSibling();

            kView.closeButton.interactable = false;
            if (kView.inventoryPopup.closeButton)
                kView.inventoryPopup.closeButton.interactable = false;

            foreach (GameObject item in tapTipList)
            {
                item.SetActive(false);
            }
            mView.redDragonTip.SetActive(true);
            //游戏暂停
            //Time.timeScale = 0;
        }


        /// <summary>
        /// 常规引导流程,常规引导操作
        /// </summary>
        void GuidePrepare()
        {
            KnapsackView kView = KnapsackView.instance;
            MainView mView = MainView.instance;
            //先让蒙版遮住所有,获取物品的面板消失
            kView.settleMentPop.SetActive(false);
            mView.guideMask.SetActive(true);
            mView.guideMask.transform.SetAsLastSibling();

            kView.closeButton.interactable = false;
            if (kView.inventoryPopup.closeButton)
                kView.inventoryPopup.closeButton.interactable = false;

            foreach (GameObject item in tapTipList)
            {
                item.SetActive(false);

            }
            //tapTipList[nextStep - 1].SetActive(true);

            //Operations.GuideStepUpdate(PlayerController.instance.PlayerMe.UserId, nextStep + 1);

            //游戏暂停
            //Time.timeScale = 0;

        }

        //public void UpdateStepRequest()
        //{
        //    Operations.GuideStepUpdate(PlayerController.instance.PlayerMe.UserId, nextStep + 1);
        //}

        //喂食引导,挂在按钮上调用
        public void ObjectGuideOn()
        {
            MainView mView = MainView.instance;
            //KnapsackView kView = KnapsackView.instance;
            mView.objectPanel.SetActive(true);
            //激活华夫饼跳动
            //kView.objectItUI.GetComponentInChildren<ObjectButton>().objectImgAnim.enabled = true;
            GuidePrepare();
            mView.objectPanel.transform.SetParent(mView.knapsackCanvas.transform);
            mView.objectPanel.transform.SetAsLastSibling();

            //出小手
            ShowGuideSolo(6);
        }

        public void ObjectGuideOff()
        {
            MainView mainView = MainView.instance;
            mainView.objectPanel.transform.SetParent(mainView.bottomButtonGroup.transform);
            mainView.objectPanel.transform.SetSiblingIndex(1);
            AfterGuide();
        }

        public void DelayPet1GuideOn(float time, int step)
        {
           
            //if (delayPet1Guide_cor == null)
            //{
            delayPet1Guide_cor = DelayPet1GuideOnCor(time, step);
            //}
            StartCoroutine(delayPet1Guide_cor);

        }

        public void DelayPet1GuideOff()
        {
            if (delayPet1Guide_cor != null)
                StopCoroutine(delayPet1Guide_cor);
        }

        IEnumerator delayPet1Guide_cor;

        //等两秒,跳过物品展示框后,出现召唤怪物引导
        IEnumerator DelayPet1GuideOnCor(float time, int step)
        {
            yield return new WaitForSeconds(time);

            KnapsackView kView = KnapsackView.instance;

            //如果按钮上有东西或者是需要切换宠物,才能触发引导
            if (kView.pet1ItUI.inventoryItem != null || step == 8)
            {
                //Debug.LogError(222);
                Pet1GuideOn(step);
            }

        }
        public void Pet1GuideOn(int step)
        {
            MainView mView = MainView.instance;

            GuidePrepare();
            mView.pet1Panel.transform.SetParent(mView.knapsackCanvas.transform);
            mView.pet1Panel.transform.SetAsLastSibling();
            //出小手
            ShowGuideSolo(step);

        }

        public void Pet1GuideOff()
        {
            MainView mainView = MainView.instance;
            mainView.pet1Panel.transform.SetParent(mainView.bottomButtonGroup.transform);
            mainView.pet1Panel.transform.SetSiblingIndex(1);
            AfterGuide();

        }

        public void SkillGuideOn()
        {
            MainView mView = MainView.instance;
            mView.clickSkillPanel.SetActive(true);

            //GuidePrepare();
            //mView.clickSkillPanel.transform.SetParent(mView.mainCanvas.transform);
            //mView.clickSkillPanel.transform.SetAsLastSibling();

            //引导中才可以跳动
            //if (inGuide)
            //{
            //    mView.clickSkillPanel.GetComponentInChildren<SkillButton>().skillImageAnim.enabled = true;
            //}
        }

        public void SkillGuideOff()
        {
            //MainView mainView = MainView.instance;
            //mainView.clickSkillPanel.transform.SetParent(mainView.bottomButtonGroup.transform);
            //mainView.clickSkillPanel.transform.SetSiblingIndex(1);
            //AfterGuide();
        }

        /// <summary>
        /// 辅助的单独的引导,往往是再次提醒和引导,只需出现三次,不会暂停游戏
        /// </summary>
        void ShowGuideSolo(int step)
        {
            //Debug.LogError(111);
            tapTipList[step - 1].SetActive(true);
        }

        public void ShowGuide(int step)
        {
            tapTipList[step - 1].SetActive(true);

        }
        /// <summary>
        /// 引导步骤大于7的话,就结束Unity端的引导喽
        /// </summary>
        /// <param name="newStep"></param>
        /// <param name="onGet"> 是get到的step还是更新的step</param>
        public void GuideStepChange(int newStep, bool onGet)
        {
            nextStep = newStep;
            Debug.LogError("nextStep:  " + nextStep);

            //3D端引导完,nextStep值为7
            if (nextStep > 1)
            {
                inGuide = false;

                BattleController.instance.CountDown();

                //不能在这里将InGuide设为0,因为这个时候不一定打完引导中的怪
            }
            else
            {
                inGuide = true;

            }

            //if (onGet)
            //{
            //    //如果大招引导没执行,还是要先召唤宠物
            //    if (nextStep == 4)
            //    {
            //        DelayGuide4();
            //    }
            //    //回退一步
            //    else if (nextStep == 5)
            //    {
            //        nextStep = 4;
            //        DelayGuide4();
            //    }
            //    return;
            //}
            避免背包过早打开,误触发引导
            //if (nextStep == 1)
            //{
            //    MainView.instance.backPack.SetActive(false);
            //}
            提示选择宠物蛋
            //else if (nextStep == 2)
            //{
            //    ShowGuide(2);
            //}
            //else if (nextStep == 3)
            //{
            //    ShowGuide(3);
            //}
            //else if (nextStep == 4)
            //{
            //    DisableGuide();
            //}
            //else if (nextStep == 5)
            //{
            //    DisableGuide();
            //}
            //else if (nextStep == 6)
            //{
            //    DisableGuide();
            //}
            //else if (nextStep == 7)
            //{
            //    DisableGuide();
            //}

        }
        public void AfterGuide()
        {
            MainView mView = MainView.instance;
            KnapsackView kView = KnapsackView.instance;
            Time.timeScale = 1;

            mView.guideMask.SetActive(false);

            kView.closeButton.interactable = true;
            if (kView.inventoryPopup.closeButton)
                kView.inventoryPopup.closeButton.interactable = true;

            foreach (GameObject item in tapTipList)
                item.SetActive(false);
        }

        /// <summary>
        /// 打开引导弹窗
        /// </summary>
        /// <param name="step"> 步骤</param>
        public void StepControl(int step,float time) {
            PlayerController playerCon = PlayerController.instance;
            Debug.Log("StepSign:" + StepSign + "    参数step :" + step);
            if (step > StepSign)
            {
                StepSign++;
                if (step >= 4) {
                    StepSign = step;
                }
                foreach (GameObject temp in Guides)
                {
                    if (temp != null)
                        temp.SetActive(false);
                }
                step -= 1;//数组里是从0开始的

                //if (StepSign == 3)
                //{
                //    mainView.Guides[2].SetActive(true);
                //    stopGuide2 = StopGuide(5);
                //    StartCoroutine(stopGuide2);
                //}

                
                if (StepSign != 6 && Guides[step] != null) {
                    Guides[step].SetActive(true);
                }
                // StepSign == 6 则引导结束
                if (playerCon.PlayerMe != null) {
                    string val = "";
                    if (guideDic.TryGetValue("BattleStep", out val))
                    {
                        guideDic["BattleStep"] = StepSign.ToString();
                    }
                    else
                    {
                        //不存在,则添加
                        guideDic.Add("BattleStep", StepSign.ToString());
                    }
                    Operations.GuideStepUpdate(playerCon.PlayerMe.UserId, JsonMapper.ToJson(guideDic));

                }
                if (time > 0) {
                    StartCoroutine(StopGuide(time));
                }
            }
            Debug.LogError("StepSign : " + StepSign);

        }
        public void CloseGuide() {
            foreach (GameObject temp in Guides)
            {
                if (temp != null)
                    temp.SetActive(false);
            }
            foreach (GameObject temp in tapTips)
            {
                if (temp != null)
                    temp.SetActive(false);
            }
        }
        IEnumerator StopGuide(float time) {
            yield return new WaitForSeconds(time);
            foreach (GameObject temp in Guides)
            {
                if (temp != null)
                    temp.SetActive(false);
            }
            foreach (GameObject temp in tapTips)
            {
                if (temp != null)
                    temp.SetActive(false);
            }
        }

        public void OpenTipsPanel(int index, float time) {
            for(int i = 0;i< tapTips.Count;i++)
            {
                if (tapTips[i] != null) {
                    if(i == index)
                        tapTips[i].SetActive(true);
                    else
                        tapTips[i].SetActive(false);
                }
            }
            if (time > 0)
            {
                StartCoroutine(StopGuide(time));
            }
        }
        public void OpenTipsPanel(int index, float time,string texts)
        {
            foreach (GameObject temp in tapTips)
            {
                if (temp != null)
                    temp.SetActive(false);
            }

            if (tapTips[index] != null) {
                if (texts != null)
                {
                    tapTips[index].transform.Find("Text").GetComponent<Text>().text = texts;
                }
                tapTips[index].SetActive(true);
            }
            if (time > 0)
            {
                StartCoroutine(StopGuide(time));
            }
        }

        public void GetPlayerGuide() {
            UnityPhotonClient unityPhotonClient = UnityPhotonClient.Instance;
            //Debug.Log("player.UserId :" + unityPhotonClient.player.UserId);

            //如果是注册,第一次登录
            if (unityPhotonClient.player.Registered)
            {
                Debug.Log("第一次注册,发送引导请求");
                //Operations.GuideStepUpdate(player.UserId, 1);//------------------------------cl
                Operations.GetGuideStep(unityPhotonClient.player.UserId);//------------------------------cl
            }
            //以后登录
            else
            {
                //获取玩家引导步数,方便判断是否需要引导
                Operations.GetGuideStep(unityPhotonClient.player.UserId);//------------------------------cl
                Debug.Log("战斗前先获取引导Guide :" + StepSign);
                //if (guideCon.StepSign == 0) {
                //}
            }
        }


    }

在这里插入图片描述

效果如下图:
在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Unity KBEngine开发MMORPG网络游戏demo是一款基于KBEngine游戏引擎和Unity3D引擎开发的大型多人在线角色扮演游戏。玩家可以通过选择职业、制定策略、组队作战等方来体验这个游戏。 这个demo可以让玩家参与到一个大型的游戏世界,探索各种地形,战斗怪物获得经验、金币等奖励,提升自己的等级和装备,以及进行多种型的任务,和其他玩家进行社交互动,例如加入公会、结交好友等。 这个游戏开发使用了Unity3D引擎实现了游戏场景的渲染和交互,以及KBEngine游戏引擎实现了网络通信、角色管理、动态创造游戏玩法等功能。这里提一下KBEngine的优点,它是一种快速而灵活的游戏引擎,可以快速搭建游戏服务端,支持多线程、多进程等机制,并提供了许多可定制的接口和扩展功能,满足了网络游戏开发不同的需求。 整个游戏采用了逻辑与客户端分离的方,实现服务端的多进程负载均衡,提高游戏的性能和稳定性;在客户端方面,通过使用Unity3D引擎可以使游戏画面更加精美、流畅、真实,同时使用了各种技术手段来保障游戏的安全性和稳定性。 总之,Unity KBEngine开发MMORPG网络游戏demo不仅在视觉效果上给玩家带来了非凡的游戏体验,而且在开发技术上也具有较高的实用、创新和开放性,为游戏开发领域的不断推进带来了非常宝贵的实践经验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小程小程,永不消沉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值