1. 程式人生 > >Unity3D 大型遊戲 MOBA類手機遊戲 狀態機在遊戲中的應用(18)

Unity3D 大型遊戲 MOBA類手機遊戲 狀態機在遊戲中的應用(18)

using UnityEngine;
using System.Collections;

namespace BlGame.GameState
{
    public interface IGameState
    {
        GameStateType GetStateType();
        void SetStateTo(GameStateType gsType);
        void Enter();
        GameStateType Update(float fDeltaTime);
        void FixedUpdate(float fixedDeltaTime);
        void
Exit(); } }
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace BlGame.GameState
{
    public enum GameStateType
    {
        GS_Continue,
        GS_Login,
        GS_User,
        GS_Lobby,
        GS_Room,
        GS_Hero,
        GS_Loading,
        GS_Play,
        GS_Over,
    }

    public
class GameStateManager : Singleton<GameStateManager> { Dictionary<GameStateType, IGameState> gameStates; IGameState currentState; public GameStateManager() { gameStates = new Dictionary<GameStateType, IGameState>(); IGameState gameState; gameState = new
LoginState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new UserState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new LobbyState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new RoomState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new HeroState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new LoadingState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new PlayState(); gameStates.Add(gameState.GetStateType(), gameState); gameState = new OverState(); gameStates.Add(gameState.GetStateType(), gameState); } public IGameState GetCurState() { return currentState; } public void ChangeGameStateTo(GameStateType stateType) { if (currentState != null && currentState.GetStateType() != GameStateType.GS_Loading && currentState.GetStateType() == stateType) return; if (gameStates.ContainsKey(stateType)) { if (currentState != null) { currentState.Exit(); } currentState = gameStates[stateType]; currentState.Enter(); } } public void EnterDefaultState() { ChangeGameStateTo(GameStateType.GS_Login); } public void FixedUpdate(float fixedDeltaTime) { if (currentState != null) { currentState.FixedUpdate(fixedDeltaTime); } } public void Update(float fDeltaTime) { GameStateType nextStateType = GameStateType.GS_Continue; if (currentState != null) { nextStateType = currentState.Update(fDeltaTime); } if (nextStateType > GameStateType.GS_Continue) { ChangeGameStateTo(nextStateType); } } public IGameState getState(GameStateType type) { if (!gameStates.ContainsKey(type)) { return null; } return gameStates[type]; } } }
using UnityEngine;
using System.Collections;
using GameDefine;
using BlGame.GameData;
using BlGame.Resource;
using BlGame.Ctrl;
using BlGame.View;

namespace BlGame.GameState
{
    class HeroState : IGameState
    {
        GameStateType stateTo;

        GameObject mScenesRoot;

        GameObject mUIRoot;

        public HeroState()
        {
        }

        public GameStateType GetStateType()
        {
            return GameStateType.GS_Hero;
        }

        public void SetStateTo(GameStateType gs)
        {
            stateTo = gs;
        }

        public void Enter()
        {
            SetStateTo(GameStateType.GS_Continue);


            HeroCtrl.Instance.Enter();

            ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(AudioDefine.PATH_UIBGSOUND, ResourceType.ASSET);

            AudioClip clip = clipUnit.Asset as AudioClip;
            AudioManager.Instance.PlayBgAudio(clip);

            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);
            EventCenter.AddListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);
            EventCenter.AddListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff); 
        }

        public void Exit()
        {
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);
            EventCenter.RemoveListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);
            EventCenter.RemoveListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff); 

            HeroCtrl.Instance.Exit();
        }

        public void OnConnectServerFail()
        {
            EventCenter.Broadcast<EMessageType>(EGameEvent.eGameEvent_ShowMessage, EMessageType.EMT_Reconnect);
        }

        public void FixedUpdate(float fixedDeltaTime)
        {

        }

        public GameStateType Update(float fDeltaTime)
        {
            return stateTo;
        }

        public void OnEvent(CEvent evt)
        {
            switch (evt.GetEventId())
            {
                case EGameEvent.eGameEvent_Loading:
                    {
                        GameStateType stateType = (GameStateType)evt.GetParam("NextState");
                        LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                        lState.SetNextState(stateType);
                        lState.SetFrontScenes(View.EScenesType.EST_Login);
                        SetStateTo(GameStateType.GS_Loading);
                    }

                    break;
            }
        }

        private void SdkLogOff()
        {
            GameMethod.LogOutToLogin();
            SetStateTo(GameStateType.GS_Login);
        }
    }
}


using UnityEngine;
using System.Collections;
using GameDefine;
using BlGame.GameData;
using System.Threading;
using BlGame.Resource;
using BlGame.View;
using BlGame.Ctrl;
using BlGame.Model;

namespace BlGame.GameState
{
    class LoadingState : IGameState
    {
        GameStateType stateTo;

        GameObject mScenesRoot;

        GameObject mUIRoot;

        public GameStateType mNextState;

        public EScenesType mFrontScenes;

        public LoadingState()
        {
            mNextState = GameStateType.GS_Continue;
        }

        public GameStateType GetStateType()
        {
            return GameStateType.GS_Loading;
        }

        public void SetNextState(GameStateType next)
        {
            mNextState = next;
        }

        public void SetFrontScenes(EScenesType front)
        {
            mFrontScenes = front;
        }

        public void SetStateTo(GameStateType gs)
        {
            stateTo = gs;
        }

        private string GetLoadMapName()
        {
            MapInfo map = MapLoadConfig.Instance.GetMapInfo(GameUserModel.Instance.GameMapID);

            if (map == null)
            {
                Debug.LogError("GetLoadMapName map find fail !!!");
                return "";
            }

            return map.mLoadScene;
        }

        private void LoadFinish(GameStateType state)
        {
            //Timer t = new Timer(this.CallBack, state, 5000, 0);
            SetStateTo(state);
        }

//         public void CallBack(object obj)
//         {
//             GameStateType state = (GameStateType)obj;
//             SetStateTo(state);
//         }

        public void Enter()
        {
            if (mNextState == GameStateType.GS_Continue)
                return;

            SetStateTo(GameStateType.GS_Continue);

            //載入UI
            mUIRoot = GameMethod.LoadProgress();
            LoadScene.Instance.GState = mNextState;
            LoadScene.Instance.OnLoadFinish += LoadFinish;


            //載入場景之前需要進行清除操作
            BlGame.Effect.EffectManager.Instance.DestroyAllEffect();
            //清除GameObjectPool資料
            GameObjectPool.Instance.Clear();

            //載入場景
            if (mNextState == BlGame.GameState.GameStateType.GS_Play)
            {
                LoadScene.Instance.isCloseBySelf = false;
                string name = GetLoadMapName();
                LoadScene.Instance.LoadAsignedSene("Scenes/"+name);

                WindowManager.Instance.ChangeScenseToPlay(mFrontScenes);
            }
            else
            {
                //返回Pvp_Login選人介面需要清除預載入資訊                
                ReadPreLoadConfig.Instance.Clear();

                LoadScene.Instance.isCloseBySelf = true;
                LoadScene.Instance.LoadAsignedSene("Scenes/Pvp_Login");

                WindowManager.Instance.ChangeScenseToLogin(mFrontScenes);

            }
            //AudioClip clip = Resources.Load(AudioDefine.PATH_UIBGSOUND) as AudioClip;
            //AudioManager.Instance.PlayBgAudio(clip);

            ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(AudioDefine.PATH_UIBGSOUND, ResourceType.ASSET);
            AudioClip clip = clipUnit.Asset as AudioClip;
            AudioManager.Instance.PlayBgAudio(clip);

            EventCenter.AddListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);
            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_IntoRoom, OnEvent);
        }

        public void Exit()
        {
            EventCenter.RemoveListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_IntoRoom, OnEvent);
        }

        public void FixedUpdate(float fixedDeltaTime)
        {

        }

        public GameStateType Update(float fDeltaTime)
        {
            return stateTo;
        }

        public void OnConnectServerFail()
        {
            EventCenter.Broadcast<EMessageType>(EGameEvent.eGameEvent_ShowMessage, EMessageType.EMT_Reconnect);
        }

        public void OnEvent(CEvent evt)
        {
            switch (evt.GetEventId())
            {
                case EGameEvent.eGameEvent_IntoRoom:
                    {
                        LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                        lState.SetNextState(GameStateType.GS_Room);
                        lState.SetFrontScenes(View.EScenesType.EST_Play);
                        SetStateTo(GameStateType.GS_Loading);
                    }
                    break;
            }
        }
    }
}


using UnityEngine;
using System.Collections;
using GameDefine;
using BlGame.Resource;
using BlGame.Ctrl;
using System;
using BlGame.View;

namespace BlGame.GameState
{
    class LobbyState : IGameState
    {
        GameStateType stateTo;

        GameObject mScenesRoot;

        GameObject mUIRoot;

        public LobbyState()
        {
        }

        public GameStateType GetStateType()
        {
            return GameStateType.GS_Lobby;
        }

        public void SetStateTo(GameStateType gs)
        {
            stateTo = gs;
        }

        public void Enter()
        {
            SetStateTo(GameStateType.GS_Continue);

            LobbyCtrl.Instance.Enter();

            //AudioClip clip = Resources.Load(AudioDefine.PATH_UIBGSOUND) as AudioClip;
            //AudioManager.Instance.PlayBgAudio(clip);

            ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(AudioDefine.PATH_UIBGSOUND, ResourceType.ASSET);
            AudioClip clip = clipUnit.Asset as AudioClip;

            AudioManager.Instance.PlayBgAudio(clip);

            if (!AudioManager.Instance.LoopAudioSource.isPlaying)
            {
                AudioManager.Instance.LoopAudioSource.Play();
            }

             EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_IntoRoom, OnEvent);
             EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);
             EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_IntoHero, OnEvent);
             EventCenter.AddListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff); 
             EventCenter.AddListener<UInt64,string>(EGameEvent.eGameEvent_InviteCreate, InviteAddFriend);
             EventCenter.AddListener<string>(EGameEvent.eGameEvent_InviteAddRoom, InviteAddRoom);
             EventCenter.AddListener(EGameEvent.eGameEvent_ReconnectToBatttle, ReconnectToBatttle);    

        }

        private void SdkLogOff()
        {
            GameMethod.LogOutToLogin();
            SetStateTo(GameStateType.GS_Login);
        }

        private void InviteAddRoom(string arg1)
        {
            InviteRoomCtrl.Instance.Enter();
        }

        private void InviteAddFriend(UInt64 sGUID ,string temp)
        {
            if (InviteCtrl.Instance.AddDic(sGUID, temp) && InviteCtrl.Instance.InvatiDic.Count > 1)
            {
                InviteCtrl.Instance.ChangeInvite(sGUID, temp);
            }else
                InviteCtrl.Instance.Enter(sGUID,temp);
        }

        public void Exit()
        {
            LobbyCtrl.Instance.Exit();

            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_IntoRoom, OnEvent);
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_IntoHero, OnEvent);
            EventCenter.RemoveListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);            
            EventCenter.RemoveListener<UInt64,string>(EGameEvent.eGameEvent_InviteCreate, InviteAddFriend);
            EventCenter.RemoveListener<string>(EGameEvent.eGameEvent_InviteAddRoom, InviteAddRoom);
            EventCenter.RemoveListener(EGameEvent.eGameEvent_ReconnectToBatttle, ReconnectToBatttle);    

        }

        public void FixedUpdate(float fixedDeltaTime)
        {   
        }

        public GameStateType Update(float fDeltaTime)
        {
            return stateTo;
        }

        public void OnEvent(CEvent evt)
        {
            switch (evt.GetEventId())
            {
                case EGameEvent.eGameEvent_IntoRoom:
                    SetStateTo(GameStateType.GS_Room);
                    break;
                case EGameEvent.eGameEvent_IntoHero:
                    GameStateManager.Instance.ChangeGameStateTo(GameStateType.GS_Hero);
                    break;
                case EGameEvent.eGameEvent_Loading:
                    GameStateType stateType = (GameStateType)evt.GetParam("NextState");
                    LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                    lState.SetNextState(stateType);
                    lState.SetFrontScenes(View.EScenesType.EST_Login);
                    SetStateTo(GameStateType.GS_Loading);
                    break;              
            }

        }

        public void ReconnectToBatttle()
        {
            EventCenter.Broadcast<EMessageType>(EGameEvent.eGameEvent_ShowMessage, EMessageType.EMT_ReEnter);
        }
    }
}


using UnityEngine;
using System.Collections;
using GameDefine;
using BlGame.Resource;
using BlGame.Ctrl;

namespace BlGame.GameState
{
    class LoginState : IGameState
    {
        GameStateType stateTo;

        GameObject mScenesRoot;

       // GameObject mUIRoot;

        public LoginState()
        {
        }

        public GameStateType GetStateType()
        {
            return GameStateType.GS_Login;
        }

        public void SetStateTo(GameStateType gs)
        {
            stateTo = gs;
        }

        public void Enter()
        {
            SetStateTo(GameStateType.GS_Continue);

            //yaz修改            
            //mScenesRoot = GameObject.Instantiate(Resources.Load(GameConstDefine.GameLogin)) as GameObject;
            //mUIRoot = LoadUiResource.LoadRes(GameMethod.GetUiCamera.transform, GameConstDefine.LoadGameLoginUI);
            //AudioClip clip = Resources.Load(AudioDefine.PATH_UIBGSOUND) as AudioClip;

            ResourceUnit sceneRootUnit = ResourcesManager.Instance.loadImmediate(GameConstDefine.GameLogin, ResourceType.PREFAB);
            mScenesRoot = GameObject.Instantiate(sceneRootUnit.Asset) as GameObject;

            //mUIRoot = LoadUiResource.LoadRes(GameMethod.GetUiCamera.transform, GameConstDefine.LoadGameLoginUI);

            LoginCtrl.Instance.Enter();

            ResourceUnit audioClipUnit = ResourcesManager.Instance.loadImmediate(AudioDefine.PATH_UIBGSOUND, ResourceType.ASSET);
            AudioClip clip = audioClipUnit.Asset as AudioClip;       


            AudioManager.Instance.PlayBgAudio(clip);

            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_InputUserData, OnEvent);
            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_IntoLobby, OnEvent);
            EventCenter.AddListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);            
        }

        private void SdkLogOff()
        {
            GameMethod.LogOutToLogin();
            SetStateTo(GameStateType.GS_Login);
        }

        public void Exit()
        {
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_InputUserData, OnEvent);
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_IntoLobby, OnEvent);
            EventCenter.RemoveListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);       

            //LoadUiResource.DestroyLoad(mUIRoot);
            LoginCtrl.Instance.Exit();
            GameObject.DestroyImmediate(mScenesRoot);            
        }

        public void FixedUpdate(float fixedDeltaTime)
        {

        }

        public GameStateType Update(float fDeltaTime)
        {
            return stateTo;
        }

        public void OnEvent(CEvent evt)
        {
            UIPlayMovie.PlayMovie("cg.mp4", Color.black, 2/* FullScreenMovieControlMode.Hidden*/, 3/*FullScreenMovieScalingMode.Fill*/);
            switch (evt.GetEventId())
            {
                case EGameEvent.eGameEvent_InputUserData:
                    SetStateTo(GameStateType.GS_User);
                    break;
                case EGameEvent.eGameEvent_IntoLobby:
                    GameStateManager.Instance.ChangeGameStateTo(GameStateType.GS_Lobby);
                    break;
            }
        }
    }
}


using UnityEngine;
using System.Collections;
using GameDefine;
using BlGame.Effect;
using BlGame.Resource;
using BlGame.Ctrl;
using BlGame.View;
using BlGame.GameEntity;
using BlGame.Model;

namespace BlGame.GameState
{
    class OverState : IGameState
    {
        GameStateType stateTo;

        GameObject mScenesRoot;

        GameObject mUIRoot;

        float mTime;
        bool mNeedUpdate;
        bool mNeedScore;

        public OverState()
        {
        }

        public GameStateType GetStateType()
        {
            return GameStateType.GS_Over;
        }

        public void SetStateTo(GameStateType gs)
        {
            stateTo = gs;
        }

        public void Enter()
        {
            SetStateTo(GameStateType.GS_Continue);

            mTime = 0;

            mNeedUpdate = true;
            mNeedScore = true;

            //AudioClip clip = Resources.Load(AudioDefine.PATH_UIBGSOUND) as AudioClip;
            //AudioManager.Instance.PlayBgAudio(clip);

            ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(AudioDefine.GetMapBgAudio((MAPTYPE)GameUserModel.Instance.GameMapID), ResourceType.ASSET);
            AudioClip clip = clipUnit.Asset as AudioClip;

            AudioManager.Instance.PlayBgAudio(clip);

            AdvancedGuideCtrl.Instance.Exit();


            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);
            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_IntoRoom, OnEvent);
            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_IntoLobby, OnEvent);
            EventCenter.AddListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);
        }

        public void Exit()
        {
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_IntoRoom, OnEvent);
            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_IntoLobby, OnEvent);
            EventCenter.RemoveListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);

            //GameMethod.DisableAllUI();

            GameMethod.RemoveUI("superwan(Clone)");
            PlayerManager.Instance.LocalPlayer.CleanWhenGameOver();
            JxBlGame.Instance.OpenConnectUI();
            GameObjectPool.Instance.Clear();
        }

        public void FixedUpdate(float fixedDeltaTime)
        {
        }

        public GameStateType Update(float fDeltaTime)
        {
            if (!mNeedUpdate)
                return stateTo;

            mTime += fDeltaTime;
            if (UIGuideModel.Instance.GuideType == GCToCS.AskCSCreateGuideBattle.guidetype.first)
            {
                if (mTime > 6)
                {
                    CGLCtrl_GameLogic.Instance.EmsgToss_AskReEnterRoom();
                    mNeedUpdate = false;
                    UIGuideCtrl.Instance.GuideBattleType(GCToCS.AskCSCreateGuideBattle.guidetype.other);
                }
            }
            else
            {
                if (mTime > 18)
                {
                    ScoreCtrl.Instance.Exit();
                    CGLCtrl_GameLogic.Instance.EmsgToss_AskReEnterRoom();
                    mNeedUpdate = false;
                }
                else if (mNeedScore && mTime > 6)
                {
                    ScoreCtrl.Instance.Enter();
                    mNeedScore = false;
                }
            }
            return stateTo;
        }

        public void OnEvent(CEvent evt)
        {
            switch (evt.GetEventId())
            {
                case EGameEvent.eGameEvent_Loading:
                    {
                        GameStateType stateType = (GameStateType)evt.GetParam("NextState");
                        LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                        lState.SetNextState(stateType);
                        lState.SetFrontScenes(View.EScenesType.EST_Play);
                        SetStateTo(GameStateType.GS_Loading);
                    }
                    break;
                case EGameEvent.eGameEvent_IntoRoom:
                    {
                        LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                        lState.SetNextState(GameStateType.GS_Room);
                        lState.SetFrontScenes(View.EScenesType.EST_Play);
                        SetStateTo(GameStateType.GS_Loading);
                    }
                    break;
                case EGameEvent.eGameEvent_IntoLobby:
                    {
                        LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                        lState.SetNextState(GameStateType.GS_Lobby);
                        lState.SetFrontScenes(View.EScenesType.EST_Play);
                        SetStateTo(GameStateType.GS_Loading);
                    }
                    break;
            }
        }

        private void OnConnectServerFail()
        {
            EventCenter.Broadcast<EMessageType>(EGameEvent.eGameEvent_ShowMessage, EMessageType.EMT_Disconnect);
        }
    }
}


using UnityEngine;
using System.Collections;
using GameDefine;
using BlGame.GameData;
using BlGame.GameEntity;
using BlGame.GuideDate;
using BlGame.Resource;
using BlGame.Model;
using BlGame.Ctrl;
using BlGame.View;
using System;
using System.Linq;

namespace BlGame.GameState
{
    class PlayState : IGameState
    {
        GameStateType stateTo;

        GameObject mScenesRoot;
        GameObject mUIRoot;

        //地圖相機型別
        public int mCameraType = 1;
        public int ShopID = 0;

        public PlayState()
        {
        }

        public GameStateType GetStateType()
        {
            return GameStateType.GS_Play;
        }

        public void SetStateTo(GameStateType gs)
        {
            stateTo = gs;
        }

        public void Enter()
        {
            SetStateTo(GameStateType.GS_Continue);

            IGuideMidMatchTip.Instance.RegisterListerner();

            switch (PlayerManager.Instance.LocalAccount.ObType)
            {
                case ObPlayerOrPlayer.PlayerType:
                    GamePlayCtrl.Instance.Enter();
                    break;
                case ObPlayerOrPlayer.PlayerObType:
                    mUIRoot = LoadUiResource.LoadRes(GameMethod.GetUiCamera.transform, GameConstDefine.LoadGameViewer);
                    break;
            }

            JxBlGame.Instance.PlayStart();

            CGLCtrl_GameLogic.Instance.AskLoadComplete();

            ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(AudioDefine.GetMapBgAudio((MAPTYPE)GameUserModel.Instance.GameMapID), ResourceType.ASSET);
            AudioClip clip = clipUnit.Asset as AudioClip;

            AudioManager.Instance.PlayBgAudio(clip);

            //正常流程
            EventCenter.AddListener<UInt64>(EGameEvent.eGameEvent_GameOver, OnGameOver);

            //新手引導流程
            EventCenter.AddListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);

            EventCenter.AddListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);

            EventCenter.AddListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);

            EventCenter.AddListener(EGameEvent.eGameEvent_ReconnectToBatttle, OnReconnectToBatttle);     

            //獲取地圖資訊
            GetMapType();
        }

        public void GetMapType()
        {
            if (UIGuideModel.Instance.GuideType == GCToCS.AskCSCreateGuideBattle.guidetype.first)
            {
                UIGuideCtrl.Instance.Enter();
                GamePlayGuideModel.Instance.NowTaskId = 90004;
                EventCenter.Broadcast(EGameEvent.eGameEvent_PlayTaskModelFinish);
            }
            else if (UIGuideModel.Instance.GuideType == GCToCS.AskCSCreateGuideBattle.guidetype.second)
            {
                AdvancedGuideCtrl.Instance.Enter();
                UIGuideCtrl.Instance.GuideBattleType(GCToCS.AskCSCreateGuideBattle.guidetype.other);
            }
            //獲取當前遊戲地圖資料
            string levelName = Application.loadedLevelName;
            MapInfo mapInfo = MapLoadConfig.Instance.GetMapInfo(levelName);
            if (mapInfo == null)
                Debug.LogError("can not find levelName in MapLoadCfg.xml!");

            mCameraType = mapInfo.mCameraType;
            GamePlayCtrl.Instance.SetShopID(mapInfo.mShopID);
        }

        public void Exit()
        {
            EventCenter.RemoveListener<UInt64>(EGameEvent.eGameEvent_GameOver, OnGameOver);

            EventCenter.RemoveListener<CEvent>(EGameEvent.eGameEvent_Loading, OnEvent);

            EventCenter.RemoveListener(EGameEvent.eGameEvent_ConnectServerFail, OnConnectServerFail);

            EventCenter.RemoveListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);

            EventCenter.RemoveListener(EGameEvent.eGameEvent_ReconnectToBatttle, OnReconnectToBatttle);     

            LoadUiResource.DestroyLoad(mUIRoot);

            GamePlayCtrl.Instance.Exit();
        }

        public void FixedUpdate(float fixedDeltaTime)
        {

        }

        public GameStateType Update(float fDeltaTime)
        {
            return stateTo;
        }

        private void OnGameOver(UInt64 BaseGuid)
        {
            PlayFinishVedio(BaseGuid);

            GameStateManager.Instance.ChangeGameStateTo(GameStateType.GS_Over);
        }

        public void OnEvent(CEvent evt)
        {
            switch (evt.GetEventId())
            {
                case EGameEvent.eGameEvent_Loading:
                    {
                        GameStateType stateType = (GameStateType)evt.GetParam("NextState");
                        LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
                        lState.SetNextState(stateType);
                        lState.SetFrontScenes(View.EScenesType.EST_Play);
                        SetStateTo(GameStateType.GS_Loading);
                    }
                    break;

            }
        }

        private void OnConnectServerFail()
        {
            EventCenter.Broadcast<EMessageType>(EGameEvent.eGameEvent_ShowMessage, EMessageType.EMT_Reconnect);
        }

        private void SdkLogOff()
        {
            GameMethod.LogOutToLogin();

            LoadingState lState = GameStateManager.Instance.getState(GameStateType.GS_Loading) as LoadingState;
            lState.SetNextState(GameStateType.GS_Login);
            lState.SetFrontScenes(View.EScenesType.EST_Play);
            SetStateTo(GameStateType.GS_Loading);
        }

        private void OnReconnectToBatttle()
        {
            CGLCtrl_GameLogic.Instance.EmsgToss_AskEnterBattle(GameUserModel.Instance.GameBattleID);
        }

        //播放特效
        void PlayFinishVedio(UInt64 ObjID)
        {
            BlGame.AudioManager.Instance.StopHeroAudio();
            GameTimeData.Instance.EndCountTime();
            ProgressBarInterface.hideProgressBar();
            //UIPlay.OpenUIPlay(false);
            //if (UIDeathInterface.Instance != null)
            //{
            //    GameObject.DestroyImmediate(UIDeathInterface.Instance.gameObject);
            //}
            DeathCtrl.Instance.Exit();
            Iselfplayer player = PlayerManager.Instance.LocalPlayer;
            if (player != null)
            {
                player.RemoveRuinWarning();
            }

            GameMethod.CreateWindow(GameConstDefine.GameOverBoxPath, Vector3.zero, GameMethod.GetUiCamera.transform);
            if (Camera.main != null && Camera.main.gameObject != null)
            {
                Camera.main.gameObject.AddComponent<BaseDaBomb>();
            }
            GameMethod.GetMainCamera.target = null;
            GameMethod.GetMainCamera.enabled = false;

            //ToReview wincamp沒用上
            UInt64 sGUID;
            sGUID = ObjID;
            Ientity entity = EntityManager.Instance.GetEntity(sGUID);

            for (int i = EntityManager.AllEntitys.Count - 1; i >= 0; i--)
            {
                var item = EntityManager.AllEntitys.ElementAt(i);
                if (item.Value.RealEntity != null)
                {
                    item.Value.RealEntity.PlayerFreeAnimation();
                    item.Value.RealEntity.SyncEntity = null;
                    item.Value.RealEntity.enabled = false;
                }
                if (item.Value.entityType == EntityType.Player || item.Value.entityType == EntityType.Building)
                    continue;
                EntityManager.AllEntitys.Remove(item.Key);
            }

            if (entity != null)
            {
                BaseDaBomb.Instance.SetBaseBomb(true, entity, GameUserModel.Instance.GameMapID);    //ToReview int->uint
            }

            AltarData
            
           

相關推薦

Unity3D 大型遊戲 MOBA手機遊戲 狀態遊戲應用(18)

using UnityEngine; using System.Collections; namespace BlGame.GameState { public interface IGameState { GameStat

RTL基本知識:使用枚舉型表示狀態進入死循環

sys 解決方法 其中 代碼 遞增 tro 跳轉 集合 enter 在定義狀態機中的狀態時,除了可以使用宏(define)或者參數(parameter)聲明定義外,還可以使用枚舉類型,但是如果對於枚舉類型使用不正確的話,極易出現編譯仿真均沒有報錯,但是仿真時狀態機跳轉異常的

狀態理解及應用

nsh 處理 .html 應用場景 logs color tps details pan 今天看nginx講解,看到在處理http請求行的時候用的是狀態機,一直淺顯的一位就是if else 或者switch,雖然實現是這種方式,但是內含的意義可不止這麽簡單,就再貼點別人的理

可配置語法分析器開發紀事(五)——構造一個真正能用的狀態

上一篇部落格寫到了如何給一個非終結符的文法規則構造出一個壓縮過的下推狀態機,那麼今天說的就是如何把所有的文法都連線起來。其實主要的idea在(三)和他的勘誤(三點五)裡面已經說得差不多了。但是今天我們要處理的是帶資訊的transition,所以還有一些地方要注意一下。 所以在這裡我們先把幾條文法

談一款MOBA遊戲《碼神聯盟》的服務端架構設計與實現(更新優化思路)

一、前言   《碼神聯盟》是一款為技術人做的開源情懷遊戲,每一種程式語言都是一位英雄。客戶端和服務端均使用C#開發,客戶端使用Unity3D引擎,資料庫使用MySQL。這個MOBA類遊戲是筆者在學習時期和客戶端美術策劃的小夥伴一起做的遊戲,筆者主要負責遊戲服務端開發,客戶

談一款MOBA遊戲的服務端架構設計

一、前言   《碼神聯盟》是一款為技術人做的開源情懷遊戲,每一種程式語言都是一位英雄。客戶端和服務端均使用C#開發,客戶端使用Unity3D引擎,資料庫使用MySQL。這個MOBA類遊戲是筆者在學習時期和客戶端美術策劃的小夥伴一起做的遊戲,筆者主要負責遊戲服務端

如何使用python控制手機(以微信遊戲跳一跳為例)

更多 狀態 ace word margin mil vpd 會有 選項 需要一個安卓手機(請原諒我買不起蘋果)需要一根數據線(智能充電的電線我估計不行)需要一臺電腦(筆記本,臺式機都可以,此次試驗以win7系統為例)聲明下:本人初學python 一個星期,做此博文的目的就是

10月第4周業務風控關注|多部門聯合調查教育App:重點排查遊戲、打賞等內容

易盾業務風控週報每週呈報值得關注的安全技術和事件,包括但不限於內容安全、移動安全、業務安全和網路安全,幫助企業提高警惕,規避這些似小實大、影響業務健康發展的安全風險。 1、多部門聯合調查教育類App:重點排查遊戲、打賞等內容 近期,深圳、北京、重慶多位家長向記者反

關於tcgames電腦玩手機遊戲助手新版本玩刺激戰場遊戲按鍵設定方法

用tcgames在電腦上玩刺激戰場和全軍出擊一段時間了,個人感覺這個比模擬器好用,模擬器匹配的是模擬器不能匹配手機玩家就算了,主要原因還是大部分模擬器比較佔用電腦記憶體配置,像我這種電腦比較垃圾的是帶不動模擬器的,動不動就閃退。當然,各位電腦配置高的就不說了......主要是

王洪業 手機網遊是遊戲未來發展趨勢

自網際網路發展以來,網路遊戲藉助燎原之勢,迅速發展,在短短十幾年內遍地開花,形成了網際網路相當重要的產業之一。隨著網路遊戲的發展,很多相關的遊戲門戶、平臺也隨之發展壯大,今天筆者專訪了任遊網CEO--WONE(王洪業),與大家分享一下筆者與王先生的清茶小談。   在對未來網遊發展看法上WON

手機端APP與遊戲測試過程

安裝測試: 1)  安裝過程中對於預設安裝目錄及任意指定的安裝目錄,是否都能正確安裝; 2)  若是選擇安裝,檢視能否實現其相應的功能; 3)  在所有能中途退出安裝的位置退出安裝程式後,驗證此程式並未安裝成功(沒有程式組及程式項產生); 4)  軟體安裝後,對其它已經安裝的軟體是否有影響; 5)  裸機安裝

遊戲設計模式】之三 狀態模式、有限狀態 & Unity版本實現

毛星雲,網路ID「淺墨」,90後,熱愛遊戲開發、遊戲引擎、計算機圖形、實時渲染等技術,就職於騰訊互娛。 微軟最有價值專家 著作《Windows遊戲程式設計之從零開始》、《OpenCV3程式設計入門》 碩士就讀於南京航空航天大學航天學院(2013級碩士研究生),已於2016年三月畢業。本科

FSM:網路遊戲開發的有限狀態(實踐篇)

上一篇文章《FSM:網路遊戲開發中的有限狀態機(理論篇)》中,講解了FSM的基礎知識。這裡,我結合圖形及具體例子,講解下FSM在實際開發中的運用。首先,圖解下上篇文章中提到的各種action。1.InputAction:某狀態下收到某事件,輸出相應動作。這裡不發生狀態變更,只

手機怎麽錄遊戲視頻 手機屏幕錄制的方法

image 高清 選擇 size ffffff ext 51cto http 錄制 如今在遊戲市場中,根據2017年調研報告,手遊市場的用戶規模達到了7.76億。手遊市場份額不斷的增長,但是手機怎麽錄遊戲視頻呢?這裏筆者以刺激戰場為例,為大家分享手機屏幕錄制的方法。使用工具

RPG遊戲狀態實現例項

local Hero = class("Hero", function ( ) return display.newNode() end) function Hero:ctor( ) self:initHero() self:addStateMachine()-

Unity3D有限狀態(FSM)學習筆記【3】FSState

本系列筆記轉載自遊戲蠻牛專欄作家Jackel的論壇文章,詳細介紹了FSM的建立與使用,特與眾分享。連結:http://www.manew.com/thread-37136-1-1.html 該類主要是狀態的基本操作及事件的新增與觸發。程式碼如下: using System;

Unity3D 從入門到放棄(五)----射箭遊戲

Unity3D 從入門到放棄(五) —-射箭遊戲 填坑啊填坑,每週都補上週作業,啥時候才能到頭啊= = 作業需求 遊戲規則: 設計一個射箭小遊戲,點選滑鼠射箭:  靶物件為 5 環,按環計分;  箭物件,射

Unity3D學習筆記(4)-牧師與魔鬼遊戲改進

這次實現的還是牧師與魔鬼遊戲,不過在此基礎上添加了一個動作管理器 把動作管理和遊戲場景分離出來,上一個版本的連結在這裡http://blog.csdn.net/x2_yt/article/details/61912680,有興趣的朋友可以 去看看。 以下是

java遊戲開發雜談 - 有限狀態

出現 範圍 pri nta widget 定義 ESS rpg遊戲 log 在不同的階段,遊戲所運行的邏輯、所顯示的界面,都是不同的。 以五子棋舉例,遊戲開始、遊戲中、勝負已分,對應的界面和邏輯都不同。 在遊戲中,又分為:自己下棋、對方下棋、遊戲暫停、悔棋等多個狀態。

用 Java 做個“你畫手機猜”的小遊戲

> 本文適合有 Java 基礎的人群 ![](https://img2020.cnblogs.com/blog/759200/202009/759200-20200923184426141-1352914100.gif) 作者:**DJL-Lanking** HelloGitHub 推出的[《講