Unity -- Event范例
来源:互联网 发布:python去除特殊符号 编辑:程序博客网 时间:2024/05/14 13:24
[代码]
using System.Collections;using System.Collections.Generic;using UnityEngine;using System;/// <summary>/// 调用 -- 示例/// </summary>public class EventExample : MonoBehaviour{ void Start () { //定义一个禽兽 TheBeast beast = new TheBeast("李雷"); //定义三个美女 new Beauty("韩梅梅", new Vector3(90.31F, 63.75F, 91.64F), beast); new Beauty("凤姐", new Vector3(94.07F, 66.40F, 95.45F), beast); new Beauty("AngelBaby", new Vector3(81.13F, 58.09F, 86.21F), beast); //禽兽大喊"美女在哪?!"后执行的内容. beast.Shouting(); }}/// <summary>/// 禽兽/// </summary>public class TheBeast{ //定义一个事件. public event Action BeastShouted; private string name; //禽兽名字 //构造 public TheBeast(string name) { this.name = name; } //禽兽行为 public void Shouting() { Debug.LogFormat("名为{0}的禽兽大喝一声: \"美女在哪?!\" ", name); //触发事件 BeastShouted(); }}/// <summary>/// 美女/// </summary>public class Beauty{ private string name; //美女名字 private Vector3 BWH; //美女三围 //构造 -- 构造时顺便注册"禽兽大吼"的事件. public Beauty(string name, Vector3 BWH, TheBeast qs) { this.name = name; this.BWH = BWH; //注册事件 qs.BeastShouted += Scampering; } public void Scampering() { Debug.LogFormat("三围({0})的美女{1} 边喊救命,边消失在视野中...", BWH, name); }}
[输出结果]
0 0
- Unity -- Event范例
- Unity Delegate Event
- Unity Event&Delegate 例子
- Unity 事件Event
- jQuery.event自定义事件机制-jQuery.event.special范例
- unity NGUI Tutorial event system
- Unity 动态加载Animator Event 事件
- Unity(三)C#委托中的事件Event
- 自定义Unity 容器的扩展 --- Unity Application Block Event Broker
- Unity中Navigation组件的使用代码范例和注意事项
- 范例
- 范例
- 关于unity 使用delegate 和 event 小例子
- 解决unity中Animation Event无法正确保存的问题
- Unity UGUI 原理篇(四):Event System Manager 事件與觸發
- 【设计模式】使用unity实现观察者模式(delegate,event)
- Unity UGUI 原理篇(四):Event System Manager 事件與觸發
- unity的UI Event事件(Event Trigger和EventSystem对比)
- LeetCode 20. Valid Parentheses
- iOS开发中使用算法之冒泡法
- 排序—希尔排序
- ACM递归递推练习 Problem J
- 看板实施步骤
- Unity -- Event范例
- 《计算导论与C语言基础》第4周编程作业: 感性接触计算机程序
- ubuntu安装openmpi
- Python3
- Python标准模块--Iterators和Generators
- OpenCV+ITK混合编程
- HTML5学习摘要
- 《程序员羊皮卷》----摘抄
- Linux线程浅析[线程的同步和互斥之线程信号量]