using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
/// <summary>
/// 事件类
/// </summary>
public class TestEventArgs : EventArgs {
public enum TestEventType
{
Test1, // 事件1
Test2, // 事件2
}
public TestEventType m_eventType;
public int m_Id;
public TestEventArgs(TestEventType eventType, int Id)
{
m_eventType = eventType;
m_Id = Id;
}
}
public delegate void TestChangeHandler(object sender, PeiyangEventArgs e);
public class TestManager
{
public event TestChangeHandler TestChangeEvent;
private void OnTestChange(TestEventArgs.TestEventType type, int Id)
{
if (TestChangeEvent == null)
return;
TestChangeEvent(this, new TestEventArgs(type, Id));
}
public void OnRequest()
{
// 向请求服务器消息
}
public void OnJieShou()
{ // 接收服务器消息
OnTestChange(TestEventArgs.TestEventType.Test1, heroID);
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
// UI 上的组件了
public class UITest : UIPanelBase
{
void Awake()
{
TestManager.GetInstance().TestChangeEvent += UIEvent;
}
public override void OnRemove()
{
TestManager.GetInstance().TestChangeEvent -= UIEvent;
}
void UIEvent(object obj, TestEventArgs e)
{
int id = e.m_Id;
switch (e.m_eventType)
{
case TestgEventArgs.TestEventType.Test1:
{
// 事件1的时候, 你要做什么
}
break;
case TestEventArgs.TestEventType.Test2:
{
// 事件2的时候, 你要做什么
}
break;
}
}
}