首页 > 代码库 > 笔记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); }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。