Skip to content

EventCenter

muxigame edited this page Nov 24, 2021 · 1 revision

事件系统 Event System

$\textcolor{RedOrange}{GalForUnity.System.Event.EventCenter}$

GalForUnity.System.Event.EventCenter 事件中心

功能

GalForUnity.System.Event.EventCenter: 事件中心是GalForUnity里最重要的类之一,管理着所有的事件,均已委托的形式保存

字段

public UnityAction<int,string,int> RoleChangeEvent;//当某个角色的数值被改变是触发

public UnityAction<RoleModel> RoleStateChangeEvent;//当某个角色的状态发生改变时触发

public UnityAction<SceneModel> SceneStateChangeEvent;//当系统场景的状态发生改变时触发

public Func<PlotModel, RoleModel, bool> PlotExecuteEvent;//当剧情开始执行时触发

public Func<PlotModel, RoleModel,PlotItem, bool> PlotItemExecuteEvent;// 当剧情流中的某一项开始执行时触发

public UnityAction<PlotModel, RoleModel> PlotExecuteOverEvent;// 当剧情流执行完毕时触发

public UnityAction<PlotModel, RoleModel> PlotRequireCheckOkEvent;// 当剧情流通过检查器的检查时触发

public UnityAction<GameTime> DayOverEvent;// 当一天结束时触发

方法

EventCenter GetInstance()://获得事件中心的实例

源代码

//======================================================================
//
//       CopyRight 2019-2020 © MUXI Game Studio 
//       . All Rights Reserved 
//
//        Filename :  EventCenter.cs 
//
//        Created by 半世癫(Roc)
//
//======================================================================

using System;
using GalForUnity.Model;
using GalForUnity.Model.Plot;
using GalForUnity.Model.Scene;
using UnityEngine;
using UnityEngine.Events;

namespace GalForUnity.System.Event {
	/// <summary>
	/// EventCenter顾名思义,绝大部分能监听的事件都定义在这里
	/// </summary>
	public class EventCenter {
		// ReSharper disable all FieldCanBeMadeReadOnly.Global
		private static EventCenter _eventCenter = new EventCenter();
		/// <summary>
		/// 获得事件中心的实例
		/// </summary>
		/// <returns></returns>
		public static EventCenter GetInstance(){
			return _eventCenter;
		}
		/// <summary>
		/// 当某个角色的数值被改变是触发
		/// </summary>
		public UnityAction<int,string,int> RoleChangeEvent;
		/// <summary>
		/// 当某个角色的状态发生改变时触发
		/// </summary>
		public UnityAction<RoleModel> RoleStateChangeEvent;
		/// <summary>
		/// 当系统场景的状态发生改变时触发
		/// </summary>
		public UnityAction<SceneModel> SceneStateChangeEvent;
		/// <summary>
		/// 当剧情开始执行时触发
		/// </summary>
		public Func<PlotModel, RoleModel, bool> PlotExecuteEvent;
		/// <summary>
		/// 当剧情流中的某一项开始执行时触发
		/// </summary>
		public Func<PlotModel, RoleModel,PlotItem, bool> PlotItemExecuteEvent;
		/// <summary>
		/// 当剧情流执行完毕时触发
		/// </summary>
		public UnityAction<PlotModel, RoleModel> PlotExecuteOverEvent;
		/// <summary>
		/// 当剧情流通过检查器的检查时触发
		/// </summary>
		public UnityAction<PlotModel, RoleModel> PlotRequireCheckOkEvent;
		/// <summary>
		/// 当一天结束时触发
		/// </summary>
		public UnityAction<GameTime> DayOverEvent;
		public EventCenter(){
			//初始化所有委托
			RoleStateChangeEvent = (x)=> { };
			SceneStateChangeEvent = new UnityAction<SceneModel>((x)=>{});
			PlotExecuteEvent = (x,y) => false ;
			PlotItemExecuteEvent = (x,y,z) => false;
			PlotExecuteOverEvent = (x,y)=> { };
			PlotRequireCheckOkEvent = (x,y)=> { };
			DayOverEvent = (x) => { Debug.Log("当日结束,新的时间是:"+x); };
		}
		
	}
}

Clone this wiki locally