首页 > 代码库 > 笔记0819

笔记0819

首先要有个静态类 用来控制整个游戏的状态

//**********************************////    Maggic @ ////**********************************//using UnityEngine;using System.Collections;/// <summary>/// 游戏状态   无,手指事件,按钮/// </summary>public enum GameState { NULL, FINGER, BUTTONS,LOADING }/// <summary>/// 声音状态   等待下载,下载,取消下载,下载完成,播放,暂停/// </summary>public enum AudioState { WAITDOWNLOAD, DOWNLOAD, DOWNLOADSTOP, DOWNLOADCOMPLETE, PLAY, PAUSE }/// <summary>/// 游戏总控台/// </summary>public class GameScene{    private static GameState m_gameState = GameState.LOADING;    public static GameState GetGameState    {        get { return m_gameState; }        set { m_gameState = value; }    }    public static Player GetPlayer { get; set; }    public static View GetView { get; set; }    public static void RefreshGameState(GameState state)    {        switch (state)        {            case GameState.LOADING:                break;            case GameState.NULL:                //侦测录音                //Sprite随机播放发呆动画                GetPlayer.m_animatorControl.m_idles.StartDetection();                GetView.m_isCanClickButton = true;                //开启触摸                GetView.m_eventListen.IsCanColliderOperation = true;                break;            case GameState.FINGER:                //关闭录音功能                GameScene.GetPlayer.m_audioControl.m_androidRecord.Stop();                //Sprite播放对应动画                GetPlayer.m_animatorControl.DestroyIdleMessage();                //关闭触摸                GetView.m_eventListen.IsCanColliderOperation = true;                break;            case GameState.BUTTONS:                //关闭录音功能                GameScene.GetPlayer.m_audioControl.m_androidRecord.Stop();                //Sprite播放对应动画                GetPlayer.m_animatorControl.DestroyAllMessage();                //关闭触摸                GetView.m_eventListen.IsCanColliderOperation = false;                break;        }        GameScene.GetGameState = state;    }}

用枚举来定义状态 public enum GameState { NULL, FINGER, BUTTONS,LOADING }

---------------------------------------

定义静态类 并封装

private static GameState m_gameState = GameState.LOADING;
public static GameState GetGameState
{
  get { return m_gameState; }
  set { m_gameState = value; }
}

-----------------------------------------

public static Player GetPlayer { get; set; }

代表,属性xxx 可以 是获取或设置。
如果是 仅是 set 则只能设置,反之亦然。
不写的话是变量,写的话就是程序属性了,如果用到反射去操作就明白了。(什么是反射?)

这里的GetPlayer 继承了Player的类 说明GetPlayerz中的属性可以获取活设置
而且还是静态的 所以在别的代码里只要写上 GameScene.GetPlayer.m_SpriteControl.gameObject.SetActive(false);
就可以设置
using UnityEngine;using System.Collections;using System.Collections.Generic;public class Player : MonoBehaviour{    public List<Event> m_LoadingEvent = new List<Event>();    public SpriteControl m_SpriteControl;    public AnimatorControl m_animatorControl;    public AudioControl m_audioControl;    public Loading m_loading;    void Awake()    {        GameScene.GetPlayer = this;    }}public class MyDebug{    public static void Log(object message)    {        //Debug.Log(message);    }}