免费国产网站_秋霞午夜一区二区三区视频_99热在线看_日韩精品久久一区二区_午夜看一级毛片_天天鲁在视频在线观看

  • 您的位置:首頁 > 新聞動態 > Unity3D

    UNITY3D處理碰撞事件的封裝類

    2018/9/22??????點擊:
      Unity的物理系統,處理碰撞事件,需要自行實現MonoBehaviour中的void OnTriggerEnter(Collider)等方法,MonoBehaviour的生命周期方法,有些不太常用,可能會經常不記得、或者打錯名字,調試還不容易找到原因,很不方便。  
    我們可以把常用接口封裝起來,讓需要實現碰撞事件的類,繼承已經封裝好的類即可。
    using System;
    using UnityEngine;
    [RequireComponent(typeof(Collider))]
    public class ColliderListener : MonoBehaviour {
    public ActiononTriggerEnter = delegate { };
    public ActiononTriggerStay = delegate { };
    public ActiononTriggerExit = delegate { };
    public ActiononCollisionEnter = delegate { };
    public ActiononCollisionStay = delegate { };
    public ActiononCollisionExit = delegate { };
    private void OnTriggerEnter(Collider other) {
    onTriggerEnter(other);
    }
    private void OnTriggerStay(Collider other) {
    onTriggerStay(other);
    }
    private void OnTriggerExit(Collider other) {
    onTriggerExit(other);
    }
    private void OnCollisionEnter(Collision other) {
    onCollisionEnter(other);
    }
    private void OnCollisionStay(Collision other) {
    onCollisionStay(other);
    }
    private void OnCollisionExit(Collision other) {
    onCollisionExit(other);
    }
    public virtual void Clear() {
    onTriggerEnter = delegate { };
    onTriggerStay = delegate { };
    onTriggerExit = delegate { };
    onCollisionEnter = delegate { };
    onCollisionStay = delegate { };
    onCollisionExit = delegate { };
    }
    }

    主站蜘蛛池模板: 长垣县| 平乐县| 兰坪| 凤台县| 赤城县| 广州市| 西平县| 侯马市| 湘潭市| 丽水市| 马龙县| 封开县| 武川县| 德江县| 分宜县| 蓬溪县| 潼关县| 吴江市| 东莞市| 阿图什市| 淮南市| 乌拉特中旗| 东光县| 修水县| 满洲里市| 都昌县| 泽普县| 雷州市| 肇州县| 新民市| 耒阳市| 广河县| 全州县| 陇南市| 疏附县| 镇江市| 孟连| 株洲县| 孙吴县| 祁连县| 永康市|