《UnityAPI.MonoBehaviour行为》(Yanlz+Unity+SteamVR+云技术+5G+AI+VR云游戏+Invoke+StopAllCoroutines+立钻哥哥++OK++)

《UnityAPI.MonoBehaviour行为》

版本

作者

参与者

完成日期

备注

UnityAPI_MonoBehaviour_V01_1.0

严立钻

 

2020.06.03

 

 

 

 

 

 

 

#《UnityAPI.MonoBehaviour行为》发布说明:

++++“UnityAPI.MonoBehaviour行为是对UnityAPIMonoBehaviour行为类的剖析和拓展

立钻哥哥:Unity是一个入门快、提高难的游戏引擎,想要提升能力,至少需要越过3道坎:API+Shader+综合能力

++1、API的积累:API的合理利用不仅可以减轻自己的编码负担,而且往往可以提高程序的运行效率;这也是钻哥开始“Unity API”独立打造分类的初衷

++2、Shader编程:想要做出一款精品游戏往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系统,优化了繁杂的“Open GL”编程

++3、综合能力(技术+业务+管理):一款产品的制作除了功能编程外,往往会涉及很多其他领域,例如产品架构、UI交互设计、模型制作等,作为主要的编程人员,对其他相关领域的了解程序往往会影响到产品制作直至最后的产品体验

++++立钻哥哥一直在推动【VR云游戏=Unity+SteamVR+云技术+5G+AI,这个只是一个引子,抛砖引玉让大家对整个知识体系有一个明确的落地方向,宝宝们可以根据自己的兴趣方向进行拓展:比如Unity这里是指一种“3D游戏引擎”,也可拓展至“UE4Cocos2dx”等游戏引擎;SteamVR是一种跨硬件解决方案,也可拓展至“VRTK”等第三方插件;“云技术+5G”是一种跨平台解决方案的核心技术,同样可拓展至其他平台解决方案;AI也是一种先进技术的举例,也可以拓展至任何一种前沿技术

 

 

@@提示:有些博客可能只是开了头,如果感兴趣的同学,可以“点赞”或“评论区留言”,只要关注的同学多了,那就会继续完善哟!(“++==”,表示没有写完的,如果关注度不高就不完善了;“++ok++”,表示此篇博客已经完成,是阶段性完整的!)

 

$$$$博客溯源:

++++VR云游戏=Unity+SteamVR+云技术+5G+AI;(说明:AI人工智能不是我们的主要研究技术,只是了解一下,领略一下有风的感觉!但是,VR是我们的研究重点

++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html

++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html

++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html

++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html

++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/

 

 

 

 

 

 

#MonoBehaviour行为

#MonoBehaviour行为

#MonoBehaviour行为

++A1、Description描述

++B2、Variables变量

++C3、Public Function共有函数

++D4、Message消息

 

 

 

#A1、Description描述

#A1、Description描述

++A1、Description描述

++++立钻哥哥:MonoBehaviour(行为)是每个脚本派生的类的基类

++++[namespace]:UnityEngine

++++[Inherits from]:Behaviour

++++注意:MonoBehaviour对象(编辑器中)的复选框,只有在其有Start()Awake()Update()FixedUpdate()OnGUI()函数时显示,没有这些函数时则隐藏;

++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

++++[Unity快速入门]:https://blog.csdn.net/VRunSoftYanlz/article/details/105776475

++++[UnityAPI目录]:https://blog.csdn.net/VRunSoftYanlz/article/details/106533906

++++[Application应用]:https://blog.csdn.net/VRunSoftYanlz/article/details/106086327

++++[Object对象]:https://blog.csdn.net/VRunSoftYanlz/article/details/106202194

++++[GameObject]:https://blog.csdn.net/VRunSoftYanlz/article/details/106223815

++++[MonoBehaviour]:https://blog.csdn.net/VRunSoftYanlz/article/details/106533256

++++[Component组件]:https://blog.csdn.net/VRunSoftYanlz/article/details/106367004

++++[Camera摄像机]:https://blog.csdn.net/VRunSoftYanlz/article/details/106148837

++++[Shader着色器]:https://blog.csdn.net/VRunSoftYanlz/article/details/106321040

++++[Material材质]:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303

++++[Physics物理]:https://blog.csdn.net/VRunSoftYanlz/article/details/106268062

++++[RaycastHit]:https://blog.csdn.net/VRunSoftYanlz/article/details/106292370

++++[ParticleSystem]:https://blog.csdn.net/VRunSoftYanlz/article/details/106341995

++++[WWW万维网]:https://blog.csdn.net/VRunSoftYanlz/article/details/106412890

++++[LineRenerer]:https://blog.csdn.net/VRunSoftYanlz/article/details/106306388

++++[WheelCollider]:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217

++++[MovieTexture]:https://blog.csdn.net/VRunSoftYanlz/article/details/106434063

 

 

 

 

 

#B2、Variables变量

#B2、Variables变量

++B2、Variables变量

++++B2.1、useGUILayout

++++B2.2、YanlzXREngine.MonoBehaviour.Variables

 

 

++B2.1、useGUILayout

++B2.1、useGUILayout

++B2.1、useGUILayout

++++立钻哥哥:使用界面布局

bool useGUILayout;

++++禁用此项,将会跳过GUILayout布局

++++它只用于在OnGUI中不使用GUI.WindowGUILayout的时候

 

 

 

 

 

 

 

#C3、Functions函数

#C3、Functions函数

++C3、Functions函数

++++C3.1、CancelInvoke

++++C3.2、Invoke

++++C3.3、InvokeRepeating

++++C3.4、IsInvoking

++++C3.5、StartCoroutine

++++C3.6、StopAllCoroutines

++++C3.7、StopCoroutine

++++C3.8、YanlzXREngine.MonoBehaviour.Variables

 

 

++C3.1、CancelInvoke

++C3.1、CancelInvoke

++C3.1、CancelInvoke

++++立钻哥哥:取消延迟调用

void CancelInvoke();

void CancelInvoke(string methodName);

++++在当前MonoBehaviour,取消所有Invoke调用

++++在当前behaviour,取消所有方法名为methodNameInvoke调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public Rigidbody projectile;

 

    void Update(){

        if(Input.GetButton(Fire1)){

            //CancelInvoke();

            CancelInvoke(MyLaunchProjectile);

        }

    }    //立钻哥哥:void Update(){}

 

    void MyLaunchProjectile(){

        instance = Instantiate(projectile);

        instance.velocity = Random.insideUnitSphere * 5;

    }    //立钻哥哥:void MyLaunchProjectile(){}

 

    void MyTestFunc(){

        InvokeRepeating(MyLaunchProjectile, 2, 0.3F);

    }    //立钻哥哥:void MyTestFunc(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++C3.2、Invoke

++C3.2、Invoke

++C3.2、Invoke

++++立钻哥哥:延迟调用

void Invoke(string methodName, float time);

++++time秒后,延迟调用方法methodName

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public Rigidbody projectile;

 

    void MyLaunchProjectile(){

        Rigidbody instance = Instantiate(projectile);

        instance.velocity = Random.insideUnitSphere * 5;

    }    //立钻哥哥:void MyLaunchProjectile(){}

 

    void MyTestFunc(){

        Invoke(MyLaunchProjectile, 2);

    }    //立钻哥哥:void MyTestFunc(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++C3.3、InvokeRepeating

++C3.3、InvokeRepeating

++C3.3、InvokeRepeating

++++立钻哥哥:重复延迟调用

void InvokeRepeating(string methodName, float time, float repeatRate);

++++time秒调用methodName方法,然后每repeatRate秒重复调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public Rigidbody projectile;

 

    void MyLaunchProjectile(){

        Rigidbody instance = Instantiate(projectile);

        instance.velocity = Random.insideUnitSphere * 5;

    }    //立钻哥哥:void MyLaunchProjectile(){}

 

    void MyTestFunc(){

        //Invoke(MyLaunchProjectile, 2);

        InvokeRepeating(MyLaunchProjectile, 2, 0.3F);

    }    //立钻哥哥:void MyTestFunc(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++C3.4、IsInvoking

++C3.4、IsInvoking

++C3.4、IsInvoking

++++立钻哥哥:是否延迟调用

bool IsInvoking(string methodName);

bool IsInvoking();

++++[methodName]:方法是否在等待调用?

++++此MonoBehaviour上是否有调用在等待;

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public Rigidbody projectile;

 

    void Update(){

        if(Input.GetKeyDown(KeyCode.Space) && !IsInvoking(MyLaunchProjectile)){

            Invoke(MyLaunchProjectile, 2);

        }

    }    //立钻哥哥:void Update(){}

 

    void MyLaunchProjectile(){

        Rigidbody instance = Instantiate(projectile);

        instance.velocity = Random.insideUnitSphere * 5;

    }    //立钻哥哥:void MyLaunchProjectile(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++C3.5、StartCoroutine

++C3.5、StartCoroutine

++C3.5、StartCoroutine

++++立钻哥哥:开始协同程序

public Coroutine StartCoroutine(IEnumerator routine);

public Coroutine StartCoroutine(string methodName, object value=null);

++++开始协同程序

++++开始一个叫methodName方法的协同程序;

++++一个协同程序在执行过程中,可以在任意位置使用yield语句;yield的返回值控制何时恢复协同程序向下执行;协同程序在对象自有帧执行过程中堪称优秀;协同程序在性能上没有更多的开销;StartCoroutine函数是立刻返回的,但是yield可以延迟结果;直到协同程序执行完毕

++++很多情况下,会用到StartCoroutine的一个变体;使用有字符串方法名的StartCoroutine允许用StopCoroutine去停止它;其缺点就是会有较高的性能开销,而且只能传递一个参数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void Start(){

        Debug.Log(立钻哥哥:Starting  + Time.time);

 

        StartCoroutine(MyWaitAndPrint(2.0F));

 

        Debug.Log(立钻哥哥:Before MyWaitAndPrint Finishes  + Time.time);

    }    //立钻哥哥:void Start(){}

 

    IEnumerator MyWaitAndPrint(float waitTime){

        yield return new WaitForSeconds(waitTime);

 

        Debug.Log(立钻哥哥:MyWaitAndPrint  + Time.time);

    }    //立钻哥哥:IEnumerator MyWaitAndPrint(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    //void Start(){}

    IEnumerator Start(){

        Debug.Log(立钻哥哥:Starting  + Time.time);

 

        //StartCoroutine(MyWaitAndPrint(2.0F));

        yield return StartCoroutine(MyWaitAndPrint(2.0F));

 

        Debug.Log(立钻哥哥:Before MyWaitAndPrint Finishes  + Time.time);

    }    //立钻哥哥:void Start(){}

 

    IEnumerator MyWaitAndPrint(float waitTime){

        yield return new WaitForSeconds(waitTime);

 

        Debug.Log(立钻哥哥:MyWaitAndPrint  + Time.time);

    }    //立钻哥哥:IEnumerator MyWaitAndPrint(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    IEnumerator Start(){

        StartCoroutine(MyDoSomething, 2.0F);

        yield return new WaitForSeconds(1);

 

        StopCoroutine(MyDoSomething);

    }    //立钻哥哥:void Start(){}

 

    IEnumerator MyDoSomething(float someParameter){

 

        while(true){

            Debug.Log(立钻哥哥:DoSomething Loop.);

            yield return null;

        }    //立钻哥哥:while(){}

 

    }    //立钻哥哥:IEnumerator MyWaitAndPrint(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++C3.6、StopAllCoroutines

++C3.6、StopAllCoroutines

++C3.6、StopAllCoroutines

++++立钻哥哥:停止所有协同程序

void StopAllCoroutines();

++++停止运行此behaviour上的所有协同程序

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    

    IEnumerator MyDoSomething(){

        while(true){

            yield return null;

        }

    }    //立钻哥哥:IEnumerator MyDoSomething(){}

 

    void MyTestFunc(){

        StartCoroutine(MyDoSomething);

        StopAllCoroutines();

    }    //立钻哥哥:void MyTestFunc(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++C3.7、StopCoroutine

++C3.7、StopCoroutine

++C3.7、StopCoroutine

++++立钻哥哥:停止协同程序

void StopCoroutine(string methodName);

void StopCoroutine(IEnumerator routine);

++++停止此behaviour上运行的所有名为methodName的协同程序

++++请注意:只有StartCoroutine使用一个字符串方法名时,才能用StopCoroutine停用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    

    IEnumerator Start(){

        StartCoroutine(MyDoSomething, 2.0F);

        yield return new WaitForSeconds(1);

 

        StopCoroutine(MyDoSomething);

    }    //立钻哥哥:void Start(){}

 

    IEnumerator MyDoSomething(float someParameter){

        while(true){

            Debug.Log(立钻哥哥:DoSomething Loop.);

            yield return null;

        }    //立钻哥哥:while(){}

    }    //立钻哥哥:IEnumerator MyWaitAndPrint(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

 

 

#D4、Static Functions静态函数

#D4、Static Functions静态函数

++D4、Static Functions静态函数

++++D4.1、print

++++D4.2、YanlzXREngine.MonoBehaviour.StaticFunctions

 

 

++D4.1、print

++D4.1、print

++D4.1、print

++++立钻哥哥:打印

static void print(object message);

++++输出日志消息到Unity控制台;等同Debug.Log

 

 

 

 

 

 

 

#E5、Messages消息

#E5、Messages消息

++E5、Messages消息

++++D5.1、Awake

++++D5.2、FixedUpdate

++++D5.3、LateUpdate

++++D5.4、OnAnimatorIK

++++D5.5、OnAnimatorMove

++++D5.6、OnApplicationFocus

++++D5.7、OnApplicationPause

++++D5.8、OnApplicationQuit

++++D5.9、OnAudioFilterRead

++++D5.10、OnBecameInvisible

++++D5.11、OnBecameVisible

++++D5.12、OnCollisionEnter

++++D5.13、OnCollisionEnter2D

++++D5.14、OnCollisionExit

++++D5.15、OnCollisionExit2D

++++D5.16、OnCollisionStay

++++D5.17、OnCollisionStay2D

++++D5.18、OnConnectedToServer

++++D5.19、OnControllerColliderHit

++++D5.20、OnDestroy

++++D5.21、OnDisable

++++D5.22、OnDisconnectedFromServer

++++D5.23、OnDrawGizmos

++++D5.24、OnDrawGizmosSelected

++++D5.25、OnEnable

++++D5.26、OnFailedToConnect

++++D5.27、OnFailedToConnectToMasterServer

++++D5.28、OnGUI

++++D5.29、OnJointBreak

++++D5.30、OnLevelWasLoaded

++++D5.31、OnMasterServerEvent

++++D5.32、OnMouseDown

++++D5.33、OnMouseDrag

++++D5.34、OnMouseEnter

++++D5.35、OnMouseExit

++++D5.36、OnMouseOver

++++D5.37、OnMouseUp

++++D5.38、OnMouseUpAsButton

++++D5.39、OnNetworkInstantiate

++++D5.40、OnParticleCollision

++++D5.41、OnPlayerConnected

++++D5.42、OnPlayerDisconnected

++++D5.43、OnPostRender

++++D5.44、OnPreCull

++++D5.45、OnPreRender

++++D5.46、OnRenderImage

++++D5.47、OnRenderObject

++++D5.48、OnSerializeNetworkView

++++D5.49、OnServerInitialized

++++D5.50、OnTriggerEnter

++++D5.51、OnTriggerEnter2D

++++D5.52、OnTriggerExit

++++D5.53、OnTriggerExit2D

++++D5.54、OnTriggerStay

++++D5.55、OnTriggerStay2D

++++D5.56、OnValidate

++++D5.57、OnWillRenderObject

++++D5.58、Reset

++++D5.59、Start

++++D5.60、Update

++++D5.61、YanlzXREngine.MonoBehaviour.Messages

 

 

++D5.1、Awake

++D5.1、Awake

++D5.1、Awake

++++立钻哥哥:唤醒

MonoBehaviour.Awake();

++++当该脚本实例被载入时Awake被调用

++++Awake用于在游戏开始之前初始化变量或游戏状态;在脚本整个生命周期内它仅被调用一次;Awake在所有对象被初始化之后调用,所以可以安全地与其他对象对话或用诸如GameObject.FindWithTag这样的函数搜索它们;每个游戏物体上的Awake以随机的顺序被调用;因此,应该用Awake来设置脚本间的引用,并用Start来传递信息;Awake总是在Start之前被调用;它不能用来执行协同程序

++++使用Awake替代构造函数用来初始化,物体被构造时并没有定义组件的序列化状态;Awake像构造函数一样只被调用一次

++++Awake不能用作协同程序

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    private GameObject target;

 

    void Awake(){

        target = GameObject.FindWithTag(YanlzPlayer);

    }    //立钻哥哥:void Awake(){}

  

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.2、FixedUpdate

++D5.2、FixedUpdate

++D5.2、FixedUpdate

++++立钻哥哥:固定更新

MonoBehaviour.FixedUpdate();

++++MonoBehaviour启用时,其FixedUpdate在每一帧被调用

++++处理Rigidbody时,需要用FixedUpdate代替Update;例如:给刚体加一个作用力时,必须应用作用力在FixedUpdate里的固定帧,而不是Update中的帧;(两者帧长不同)

++++为了获取自最后一次调用FixedUpdate所用的时间,可以用Time.deltaTime;这个函数只有在Behaviour启用时被调用;实现组件功能时重载这个函数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void FixedUpdate(){

        rigidbody.AddForce(Vector3.up);

    }    //立钻哥哥:void FixedUpdate(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.3、LateUpdate

++D5.3、LateUpdate

++D5.3、LateUpdate

++++立钻哥哥:之后更新

MonoBehaviour.LateUpdate();

++++Behaviour启用时,其LateUpdate在每一帧被调用

++++LateUpdate是在所有Update函数调用后被调用;这可用于调整脚本执行顺序;例如:当物体在Update里移动时,跟随物体的摄像机可以在LateUpdate里实现

++++为了获取自最后一次调用LateUpdate所用的时间,可以用Time.deltaTime;这个函数只有在Behaviour启用时被调用;实现组件功能时重载这个函数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void LateUpdate(){

        transform.Translate(0, 0, Time.deltaTime * 1);

    }    //立钻哥哥:void LateUpdate(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.4、OnAnimatorIK

++D5.4、OnAnimatorIK

++D5.4、OnAnimatorIK

++++立钻哥哥:当动画器IK

MonoBehaviour.OnAnimatorIK(int layerIndex);

++++[layerIndex]:IK解算器被调用,该层的索引

++++设置动画的IK回调(反向运动学)

++++在它的内部IK系统更新之前,OnAnimatorIK()是通过Animator组件立即被调用;这个回调用来设置IK的目标位置和它们各自的权重

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public float leftFootPositionWeight;

    public float leftFootRotationWeight;

    public Transform leftFootObj;

    private Animator animator;

 

    void Start(){

        animator = GetComponent<Animator>();

    }    //立钻哥哥:void Start(){}

 

    void OnAnimatorIK(int layerIndex){

        animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootPositionWeight);

        animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootRotationWeight);

        animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootObj.position);

        animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootObj.rotation);

    }    //立钻哥哥:void OnAnimatorIK(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.5、OnAnimatorMove

++D5.5、OnAnimatorMove

++D5.5、OnAnimatorMove

++++立钻哥哥:当动画器移动

MonoBehaviour.OnAnimatorMove();

++++用于修改根运动处理动画移动的回调

++++在该状态机和动画已经被求值之后,但在OnAnimatorIK之前,该回调将在每帧调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnAnimatorMove(){

        Animator animator = GetComponent<Animator>();

 

        if(animator){

            Vector3 newPosition = transform.position;

            newPosition.z += animator.GetFloat(Runspeed) * Time.deltaTime;

            transform.position = newPosition;

        }    //立钻哥哥:if(){}

 

    }    //立钻哥哥:void OnAnimatorMove(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.6、OnApplicationFocus

++D5.6、OnApplicationFocus

++D5.6、OnApplicationFocus

++++立钻哥哥:当应用程序聚焦

MonoBehaviour.OnApplicationFocus(bool focusStatus)

++++当玩家获得或失去焦点时发送给所有游戏对象

++++OnApplicationFocus可以作为协同程序,在函数中简单使用yield状态;如果作为协同执行,它将在初始帧中再次被计算:首先作为一个早期的通知,第二次在正常协同更新步骤

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public bool paused;

 

    void OnGUI(){

        if(paused){

            GUI.Label(new Rect(100, 100, 50, 30), 立钻哥哥:Game paused.);

        }

    }    //立钻哥哥:void OnGUI(){}

 

    void OnApplicationFocus(bool focusStatuss)(){

        paused = focusStatus;

    }    //立钻哥哥:void OnApplicationFocus(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.7、OnApplicationPause

++D5.7、OnApplicationPause

++D5.7、OnApplicationPause

++++立钻哥哥:当应用程序暂停

MonoBehaviour.OnApplicationPause(bool pauseStatus);

++++当玩家暂停发送给所有游戏对象

++++OnApplicationPause可以作为协同程序,在函数中简单使用yield状态;如果作为协同执行,它将在初始帧中再次被计算:首先作为一个早期的通知,第二次在正常协同更新步骤

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public bool paused;

 

    void OnGUI(){

        if(paused){

            GUI.Label(new Rect(100, 100, 50, 30), 立钻哥哥:Game paused.);

        }

    }    //立钻哥哥:void OnGUI(){}

 

    void OnApplicationPause(bool focusStatuss)(){

        paused = focusStatus;

    }    //立钻哥哥:void OnApplicationPause(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.8、OnApplicationQuit

++D5.8、OnApplicationQuit

++D5.8、OnApplicationQuit

++++立钻哥哥:当应用程序退出

MonoBehaviour.OnApplicationQuit();

++++在应用退出之前发送给所有的游戏物体

++++当用户停止运行模式时在编辑器中调用;当Web被关闭时在网络播放器中被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnApplicationQuit()(){

        PlayerPrefs.Save();

    }    //立钻哥哥:void OnApplicationQuit(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.9、OnAudioFilterRead

++D5.9、OnAudioFilterRead

++D5.9、OnAudioFilterRead

++++立钻哥哥:当音频过滤器读取

MonoBehaviour.OnAudioFilterRead(float[] data, int channels);

++++[data]:包含音频数据的浮点数数组

++++[channels]:int是传递给此委托音频数据的通道数

++++如果OnAudioFilterRead被执行,Unity将插入一个自定义的过滤器到音频DSP

++++该过滤器插入作为MonoBehaviour脚本以相同的顺序被插入显示在检视面板

++++OnAudioFilterRead每次被调用是通过过滤器访问音频块(这种情况经常发生,每~20ms取决于采样频率和平台);音频数据是范围在[-1.0f; 1.0f]的浮点数数组并包含以前音频链中的过滤器或AudioSource中的AudioClip;如果实在链中的第一个过滤器并且剪辑没有附加到音频源,此过滤器将是“已播放”;这样可以使用滤波器作为音频剪辑,程序生成音频

++++如果OnAudioFilterRead被执行,VU表将显示在检视面板,显示采样等级;过滤器的处理时间也被计算并以毫秒显示在旁边的VU表(如果过滤器占用太多时间,它会变红色,因此mixer将吃掉音频数据);注意:OnAudioFilterRead不允许从主线程外调用

立钻哥哥:If OnAudioFilterRead is implemented a VU meter will show up in the inspector showing the outgoing samples level. The process time of the filter is also measured and the spent milliseconds will show up next to the VU Meter(it turns red if the filter is taking up too much time, so the mixer will starv audio data). Also note, that OnAudioFilterRead is called on a different thread from the main thread(namelly the audio thread) so calling into many Unity functions from this function is not allowed(a warning will show up).

 

 

 

 

 

++D5.10、OnBecameInvisible

++D5.10、OnBecameInvisible

++D5.10、OnBecameInvisible

++++立钻哥哥:当不可见

MonoBehaviour.OnBecameInvisible();

++++renderer(渲染器)在任何摄像机上都不可见时调用OnBecameInvisible

++++这个消息发送到所有附在渲染器的脚本上;OnBecameVisibleOnBecameInvisible可以用于只需要在物体可见时才进行的计算

++++OnBecameInvisible可以被用作协同程序,在函数中调用yield语句;当在编辑器中运行时,场景面板摄像机也会导致这个函数被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnBecameInvisible()(){

        enabled = false;

    }    //立钻哥哥:void OnBecameInvisible(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.11、OnBecameVisible

++D5.11、OnBecameVisible

++D5.11、OnBecameVisible

++++立钻哥哥:当可见

MonoBehaviour.OnBecameVisible();

++++renderer(渲染器)在任何摄像机上可见时调用OnBecameVisible

++++这个消息发送到所有附在渲染器的脚本上;OnBecameVisibleOnBecameInvisible可以用于只需要在物体可见时才进行的计算

++++OnBecameVisible可以被用作协同程序,在函数中调用yield语句;当在编辑器中运行时,场景面板摄像机也会导致这个函数被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnBecameVisible()(){

        enabled = true;

    }    //立钻哥哥:void OnBecameVisible(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.12、OnCollisionEnter

++D5.12、OnCollisionEnter

++D5.12、OnCollisionEnter

++++立钻哥哥:当进入碰撞

MonoBehaviour.OnCollisionEnter(Collision collision);

++++当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionEnter将被调用

++++相对于OnTriggerEnterOnCollisionEnter传递的是Collision类而不是ColliderCollision包含接触点,碰撞速度等细节;如果在函数中不使用碰撞信息,省略collisionInfo参数以避免不必要的运算;注意如果碰撞体附加了一个非动力学刚体,只发送碰撞事件

++++OnCollisionEnter可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnCollisionEnter(Collision collision){

        foreach(ContactPoint contact in collision.contacts){

            Debug.DrawRay(contact.point, contact.normal, Color.white);

        }

 

        if(collision.relativeVelocity.magnitude > 2){

            audio.Play();

        }

    }    //立钻哥哥:void OnCollisionEnter(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.13、OnCollisionEnter2D

++D5.13、OnCollisionEnter2D

++D5.13、OnCollisionEnter2D

++++立钻哥哥:当进入2D碰撞

MonoBehaviour.OnCollisionEnter2D(Collision2D coll);

++++当进入的碰撞器与这个对象的碰撞器接触,发送信息(仅限2D物理)

++++关于碰撞的更多信息在调用期间中通过Collision2D参数报告;如果不需要该信息,那么可以声明OnCollisionEnter2D不带参数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnCollisionEnter2D(Collision2D coll){

        if(coll.gameObject.tag == MyEnemy){

            coll.gameObject.SendMessage(MyApplyDamage, 10);

        }

    }    //立钻哥哥:void OnCollisionEnter2D(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.14、OnCollisionExit

++D5.14、OnCollisionExit

++D5.14、OnCollisionExit

++++立钻哥哥:当退出碰撞

MonoBehaviour.OnCollisionExit(Collision collisionInfo);

++++当此collider/rigidbody停止触发另一个rigidbody/collider时,OnCollisionExit将被调用

++++相对于OnTriggerExitOnCollisionExit传递的是Collision类而不是ColliderCollision包含接触点,碰撞速度等细节;如果在函数中不使用碰撞信息,省略collisionInfo参数以避免不必要的运算;注意:如果碰撞体附加了一个非动力学刚体,只发送碰撞事件

++++OnCollisionExit可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnCollisionExit(Collision collisionInfo){

        Debug.Log(立钻哥哥:No longer in contact with  + collisionInfo.transform.name);

    }    //立钻哥哥:void OnCollisionExit(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.15、OnCollisionExit2D

++D5.15、OnCollisionExit2D

++D5.15、OnCollisionExit2D

++++立钻哥哥:当退出2D碰撞

MonoBehaviour.OnCollisionExit2D(Collision2D coll);

++++当另一个对象的碰撞器停止接触这个对象的碰撞器时,发送信息(仅限2D物理)

++++关于碰撞的更多信息在调用期间中通过Collision2D参数报告;如果不需要该信息,那么可以声明OnCollisionExit2D不带参数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public int bumpCount;

 

    void OnCollisionExit2D(Collision2D collisionInfo){

        if(coll.gameObject.tag == MyDogemCar){

            bumpCount++;

        }

    }    //立钻哥哥:void OnCollisionExit2D(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.16、OnCollisionStay

++D5.16、OnCollisionStay

++D5.16、OnCollisionStay

++++立钻哥哥:当停留碰撞

MonoBehaviour.OnCollisionStay(Collision collisionInfo);

++++当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionStay将会在每一帧被调用

++++相对于OnTriggerExitOnCollisionExit传递的是Collision类而不是ColliderCollision包含接触点,碰撞速度等细节;如果在函数中不使用碰撞信息,省略collisionInfo参数以避免不必要的运算;注意:如果碰撞体附加了一个非动力学刚体,只发送碰撞事件

++++OnCollisionStay可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnCollisionStay(Collision collisionInfo){

        foreach(ContactPoint contact in collisionInfo.contacts){

            Debug.DrawRay(contact.point, contact.normal, Color.white);

        }

    }    //立钻哥哥:void OnCollisionStay(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.17、OnCollisionStay2D

++D5.17、OnCollisionStay2D

++D5.17、OnCollisionStay2D

++++立钻哥哥:当停留2D碰撞

MonoBehaviour.OnCollisionStay2D(Collision2D coll);

++++当另一个对象的碰撞器每帧接触这个对象的碰撞器时,发送信息(仅限2D物理)

++++关于碰撞的更多信息在调用期间中通过Collision2D参数报告;如果不需要该信息,那么可以声明OnCollisionStay2D不带参数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public float rechargeRate = 10.0F;

    public float batteryLevel;

 

    void OnCollisionStay2D(Collision2D colli){

        if(coll.gameObject.tag == MyRechargePoint){

            batteryLevel = Mathf.Min(batteryLevel + rechargeRate * Time.deltaTime, 100.0F);

        }

    }    //立钻哥哥:void OnCollisionStay2D(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.18、OnConnectedToServer

++D5.18、OnConnectedToServer

++D5.18、OnConnectedToServer

++++立钻哥哥:当连接到服务器

MonoBehaviour.OnConnectedToServer();

++++当成功连接到服务器时,在客户端调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnConnectedToServer(){

        Debug.Log(立钻哥哥:Connected to server.);

    }    //立钻哥哥:void OnConnectedToServer(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.19、OnControllerColliderHit

++D5.19、OnControllerColliderHit

++D5.19、OnControllerColliderHit

++++立钻哥哥:当控制器碰到碰撞器

MonoBehaviour.OnControllerColliderHit(ContollerColliderHit hit);

++++在移动时,当controller碰撞到collider时,OnControllerColliderHit被调用

++++它可以用来在角色碰到物体时推开物体

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public float pushPower = 2.0F;

 

    void OnControllerColliderHit(ControllerColliderHit hit){

        Rigidbody body = hit.collider.attachedRigidbody;

 

        if(body == null || body.isKinematic){

            return;

        }

 

        if(hit.moveDirection.y < -0.3F){

            return;

        }

 

        Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);

        body.velocity = pushDir * pushPower;

 

    }    //立钻哥哥:void OnControllerColliderHit(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.20、OnDestroy

++D5.20、OnDestroy

++D5.20、OnDestroy

++++立钻哥哥:当销毁

MonoBehaviour.OnDestroy();

++++MonoBehaviour将被销毁时,这个函数被调用

++++OnDestroy被调用只会在预先已经被激活的游戏物体上

++++OnDestroy不能用于协同程序

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnDestroy(){

        Debug.Log(立钻哥哥:Script was destroyed.);

    }    //立钻哥哥:void OnDestroy(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.21、OnDisable

++D5.21、OnDisable

++D5.21、OnDisable

++++立钻哥哥:当禁用

MonoBehaviour.OnDisable();

++++当对象变为不可用或非激活状态时此函数被调用

++++当物体被销毁时它将被调用,并且可用于任意清理代码;当脚本编译完成之后被重新加载时,OnDisable将被调用,OnEnable在脚本被载入后调用

++++OnDisable不能用于协同程序

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnDisable(){

        Debug.Log(立钻哥哥:Script was removed.);

    }    //立钻哥哥:void OnDisable(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.22、OnDisconnectedFromServer

++D5.22、OnDisconnectedFromServer

++D5.22、OnDisconnectedFromServer

++++立钻哥哥:当从服务器断开连接

MonoBehaviour.OnDisconnectedFromServer(NetworkDisconnection info);

++++当失去连接或从服务器端断开时在客户端调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnDisconnectedFromServer(NetworkDisconnection info){

        Debug.Log(立钻哥哥:Disconnected from server:  + info);

    }    //立钻哥哥:void OnDisconnectedFromServer(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.23、OnDrawGizmos

++D5.23、OnDrawGizmos

++D5.23、OnDrawGizmos

++++立钻哥哥:当绘制Gizmos

MonoBehaviour.OnDrawGizmos();

++++如果想绘制可被点选的gizmos,执行OnDrawGizmos

++++这允许在场景中快速选择重要的对象

++++注意:OnDrawGizmos使用相对于场景视图的鼠标位置

++++如果在检视面板这个组件被折叠,这个函数将不被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnDrawGizmos(){

        Gizmos.color = Color.yellow;

        Gizmos.DrawSphere(transform.position, 1);

    }    //立钻哥哥:void OnDrawGizmos(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.24、OnDrawGizmosSelected

++D5.24、OnDrawGizmosSelected

++D5.24、OnDrawGizmosSelected

++++立钻哥哥:当选择时绘制Gizmos

MonoBehaviour.OnDrawGizmosSelected();

++++如果想在物体被选中时绘制gizmos,执行这个函数

++++Gizmos只在物体被选择的时候绘制;Gizmos不能被点选,这可以使设置更容易;例如:一个爆炸脚本可以绘制一个球来显示爆炸半径

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    float explosionRadius = 5.0f;

 

    void OnDrawGizmosSelected(){

        Gizmos.color = Color.white;

        Gizmos.DrawSphere(transform.position, explosionRadius);

    }    //立钻哥哥:void OnDrawGizmosSelected(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.25、OnEnable

++D5.25、OnEnable

++D5.25、OnEnable

++++立钻哥哥:当启用

MonoBehaviour.OnEnable();

++++当对象被启用并激活状态时此函数被调用

++++OnEnable不能用于协同程序;

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnEnable(){

        Debug.Log(立钻哥哥:Script was enabled.);

    }    //立钻哥哥:void OnEnable(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.26、OnFailedToConnect

++D5.26、OnFailedToConnect

++D5.26、OnFailedToConnect

++++立钻哥哥:当连接失败

MonoBehaviour.OnFailedToConnect(NetworkConnectionError error);

++++当一个连接因为某些原因失败时在客户端调用

++++失败原因将作为NetworkConnectionError枚举传入

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnFailedToConnect(NetworkConnectionError error){

        Debug.Log(立钻哥哥:Could not connect to server:  + error);

    }    //立钻哥哥:void OnFailedToConnect(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.27、OnFailedToConnectToMasterServer

++D5.27、OnFailedToConnectToMasterServer

++D5.27、OnFailedToConnectToMasterServer

++++立钻哥哥:当连接到MasterServer失败

MonoBehaviour.OnFailedToConnectToMasterServer(NetworkConnectionError info);

++++当连接MasterServer出现问题时在客户端或服务器端调用

++++失败原因将作为NetworkConnectionError枚举传入

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnFailedToConnectToMasterServer(NetworkConnectionError info){

        Debug.Log(立钻哥哥:Could not connect to master server:  + info);

    }    //立钻哥哥:void OnFailedToConnectToMasterServer(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

++D5.28、OnGUI

++D5.28、OnGUI

++D5.28、OnGUI

++++立钻哥哥:当界面

MonoBehaviour.OnGUI();

++++渲染和处理GUI事件时调用

++++这意味着OnGUI程序将会在每一帧被调用;要得到更多的GUI事件的信息查阅Event;如果MonoBehaviourenabled属性设为falseOnGUI()将不会被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnGUI(){

        if(GUI.Button(new Rect(10, 10, 150, 100), 立钻哥哥:I am a button.)){

            Debug.Log(立钻哥哥:You clicked the button!);

        }

    }    //立钻哥哥:void OnGUI(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.29、OnJointBreak

++D5.29、OnJointBreak

++D5.29、OnJointBreak

++++立钻哥哥:当关节断开

MonoBehaviour.OnJointBreak(float breakForce);

++++当附在同一对象上的关节被断开时调用

++++当一个力大于这个关节的承受力时,关节将被断开;此时OnJointBreak将被调用,应用到关节的力将被传入;之后这个关节将自动从游戏对象中移除并删除

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnJointBreak(float breakForce){

        Debug.Log(立钻哥哥:Joint Broke! Force:  + breakForce);

    }    //立钻哥哥:void OnJointBreak(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.30、OnLevelWasLoaded

++D5.30、OnLevelWasLoaded

++D5.30、OnLevelWasLoaded

++++立钻哥哥:当关卡被加载

MonoBehaviour.OnLevelWasLoaded(int level);

++++当一个新关卡被载入时此函数被调用

++++/level/是被加载的关卡的索引;使用菜单项[File->Build Setting ...]来查看索引引用的是哪个场景

++++OnLevelWasLoaded可以协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnLevelWasLoaded(int level){

        if(level == 13){

            Debug.Log(立钻哥哥:Woohoo.);

        }

    }    //立钻哥哥:void OnLevelWasLoaded(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.31、OnMasterServerEvent

++D5.31、OnMasterServerEvent

++D5.31、OnMasterServerEvent

++++立钻哥哥:当MasterServer事件

MonoBehaviour.OnMasterServerEvent(MasterServerEvent msEvent);

++++当报告事件来自MasterServer时在客户端或服务器调用

++++例如:当一个客户列表接收完成或客户注册成功后被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void Start(){

        Network.InitializeServer(32, 25000);

    }    //立钻哥哥:void Start(){}

 

    void OnServerInitialized(){

        MasterServer.RegisterHost(MyGameVer1.0.0_42, 立钻哥哥:My Game Instance, 立钻哥哥:This is a comment and place to store data.);

    }    //立钻哥哥:void OnServerInitialized(){}

 

    void OnMasterServerEvent(MasterServerEvent msEvent){

        if(msEvent == MasterServerEvent.RegistrationSucceeded){

            Debug.Log(立钻哥哥:Server registered.);

        }

    }    //立钻哥哥:void OnMasterServerEvent(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.32、OnMouseDown

++D5.32、OnMouseDown

++D5.32、OnMouseDown

++++立钻哥哥:当鼠标按下

MonoBehaviour.OnMouseDown();

++++当用户鼠标在GUIElementCollider上点击时OnMouseDown被调用

++++该事件将发送给ColliderGUIElement上的所有脚本

++++这个函数不会在属于[Ignore Raycast]的层上调用

++++OnMouseDown可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在ColliderGUIElement的脚本上

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseDown(){

        Application.LoadLevel(YanlzTestSomeLevel);

    }    //立钻哥哥:void OnMouseDown(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.33、OnMouseDrag

++D5.33、OnMouseDrag

++D5.33、OnMouseDrag

++++立钻哥哥:当鼠标拖拽

MonoBehaviour.OnMouseDrag();

++++当用户鼠标在GUIElementCollider上拖拽时OnMouseDrag被调用

++++OnMouseDrag在鼠标按下的每一帧被调用

++++这个函数不会在属于[Ignore Raycast]的层上调用

++++OnMouseDrag可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在ColliderGUIElement的脚本上

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseDrag(){

        renderer.material.color -= Color.white * Time.deltaTime;

    }    //立钻哥哥:void OnMouseDrag(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.34、OnMouseEnter

++D5.34、OnMouseEnter

++D5.34、OnMouseEnter

++++立钻哥哥:当鼠标进入

MonoBehaviour.OnMouseEnter();

++++当鼠标进入到GUIElement(GUI元素)或Collider(碰撞体)中时调用OnMouseEnter

++++这个函数不会在属于[Ignore Raycast]的层上调用;

++++OnMouseEnter可以被作为协同程序,在函数体内使用yield语句,这个事件发送到所有附在ColliderGUIElement的脚本上;

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseEnter(){

        renderer.material.color = Color.red;

    }    //立钻哥哥:void OnMouseEnter(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.35、OnMouseExit

++D5.35、OnMouseExit

++D5.35、OnMouseExit

++++立钻哥哥:当鼠标退出

MonoBehaviour.OnMouseExit();

++++当用户鼠标不再GUIElementCollider上时OnMouseExit被调用

++++OnMouseExitOnMouseEnter相反

++++这个函数不会在属于[Ignore Raycast]的层上调用

++++OnMouseExit可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在ColliderGUIElement的脚本上

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseExit(){

        renderer.material.color = Color.white;

    }    //立钻哥哥:void OnMouseExit(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

++D5.36、OnMouseOver

++D5.36、OnMouseOver

++D5.36、OnMouseOver

++++立钻哥哥:当鼠标经过

MonoBehaviour.OnMouseOver();

++++当用户鼠标在GUIElementCollider上经过时OnMouseOver被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseOver(){

        renderer.material.color -= new Color(0.1F, 0, 0) * Time.deltaTime;

    }    //立钻哥哥:void OnMouseOver(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.37、OnMouseUp

++D5.37、OnMouseUp

++D5.37、OnMouseUp

++++立钻哥哥:当鼠标弹起

MonoBehaviour.OnMouseUp();

++++当用户释放鼠标按钮时调用OnMouseUp

++++在鼠标按下的同一GUIElementCollider上,OnMouseUp才调用

++++这个函数不会在属于[Ignore Raycast]的层上调用

++++OnMouseUp可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在ColliderGUIElement的脚本上

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseUp(){

        Debug.Log(立钻哥哥:Drag ended!);

    }    //立钻哥哥:void OnMouseUp(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.38、OnMouseUpAsButton

++D5.38、OnMouseUpAsButton

++D5.38、OnMouseUpAsButton

++++立钻哥哥:当鼠标作为按钮弹起时

MonoBehaviour.OnMouseUpAsButton();

++++OnMouseUpAsButton只有当鼠标在同一个GUIElementCollider按下,在释放时调用

++++这个函数不会在属于[Ignore Raycast]的层上调用

++++OnMouseUpAsButton可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在ColliderGUIElement的脚本上

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnMouseUpAsButton(){

        Application.LoadLevel(YanlzTestSomeLevel);

    }    //立钻哥哥:void OnMouseUpAsButton(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.39、OnNetworkInstantiate

++D5.39、OnNetworkInstantiate

++D5.39、OnNetworkInstantiate

++++立钻哥哥:当网络实例

MonoBehaviour.OnNetworkInstantiate(NetworkMessageInfo info);

++++当对象使用Network.Instantiate进行网络初始化时调用

++++这对于禁用或启用一个已经初始化的对象组件来说是非常有用的,它们的行为取决于它们是在本地还是在远端

++++注意:NetworkMessageInfo里的networkView属性不能在OnNetworkInstantiate里使用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnNetworkInstantiate(NetworkMessageInfo info){

        Debug.Log(立钻哥哥:New object instantiated by  + info.sender);

    }    //立钻哥哥:void OnNetworkInstantiate(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.40、OnParticleCollision

++D5.40、OnParticleCollision

++D5.40、OnParticleCollision

++++立钻哥哥:当粒子碰撞

MonoBehaviour.OnParticleCollision(GameObject other);

++++当粒子碰到碰撞器时,OnParticleCollision被调用

++++这个可以用于游戏对象被粒子击中时应用伤害到它上面

++++[老的粒子系统(Legacy particle system)]:这个消息被发送到所有附加到theWorldParticleCollider的脚本上和被集中的碰撞体上;这个消息只有当在theWorldParticleCollider检视面板中启用了sendCollisionMessage才会被发送

++++[忍者飞镖粒子系统(Shuriken particle system)]:这个消息发送给碰到碰撞器并附件粒子系统的脚本;当OnParticleCollision从附加到带有刚体的游戏对象的脚本调用时,游戏对象的参数表示粒子系统;该碰撞器在任何给定帧接收每个粒子系统碰撞最多一条消息,甚至当粒子系统在当前帧碰到带有多个粒子的碰撞器时;为了检索所有的碰撞的粒子系统的详细信息,ParticleSystem.GetCollisionEvents必须用来检索ParticleSystem.CollisionEvent数组;当OnParticleCollision从附加到粒子系统的脚本调用时,游戏对象的参数表示附件有碰撞器由粒子系统碰到的对象;该粒子系统将在每个碰撞器最多接收一条消息;如上,ParticleSystem.GetCollisionEvents必须用来检索所有的碰撞事件的对象;在检视面板的粒子碰撞栏[Send Collision Message]启用,消息才会发送

++++OnParticleCollision可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnParticleCollision(GameObject other){

        Rigidbody body = other.rigidbody;

        if(body){

            Vector3 direction = other.transform.position - transform.position;

            direction = direction.normalized;

            body.AddForce(direction * 5);

        }

    }    //立钻哥哥:void OnParticleCollision(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    private ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16];

 

    void OnParticleCollision(GameObject other){

        ParticleSystem particleSystem;

        particleSystem = other.GetComponent<ParticleSystem>();

        int safeLength = particleSystem.safeCollisionEventSize;

 

        if(collisionEvents.Length < safeLength){

            collisionEvents = new ParticleSystem.CollisionEvent[safeLength];

        }    //立钻哥哥:if(){}

 

       int numCollisionEvents = particleSystem.GetCollisionEvents(gameObject, collisionEvents);

       int i = 0;

       while(i < numCollisionEvents){

           if(gameObject.rigidbody){

                Vector3 pos = collisionEvents[i].intersection;

                Vector3 force = collisionEvents[i].velocity * 10;

                gameObject.rigidbody.AddForce(force);

            }    //立钻哥哥:if(){}

 

            i++;

        }    //立钻哥哥:while(){}

 

    }    //立钻哥哥:void OnParticleCollision(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    private ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16];

 

    void OnParticleCollision(GameObject other){

        //ParticleSystem particleSystem;

        //particleSystem = other.GetComponent<ParticleSystem>();

        int safeLength = particleSystem.safeCollisionEventSize;

 

        if(collisionEvents.Length < safeLength){

            collisionEvents = new ParticleSystem.CollisionEvent[safeLength];

        }    //立钻哥哥:if(){}

 

        int numCollisionEvents = particleSystem.GetCollisionEvents(gameObject, collisionEvents);

        int i = 0;

        while(i < numCollisionEvents){

            //if(gameObject.rigidbody){

            if(other.rigidbody){

                Vector3 pos = collisionEvents[i].intersection;

                Vector3 force = collisionEvents[i].velocity * 10;

                gameObject.rigidbody.AddForce(force);

            }    //立钻哥哥:if(){}

 

            i++;

        }    //立钻哥哥:while(){}

 

    }    //立钻哥哥:void OnParticleCollision(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.41、OnPlayerConnected

++D5.41、OnPlayerConnected

++D5.41、OnPlayerConnected

++++立钻哥哥:当玩家连接

MonoBehaviour.OnPlayerConnected(NetworkPlayer player);

++++当一个新玩家成功连接时在服务器上被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    private int playerCount = 0;

 

    void OnPlayerConnected(NetworkPlayer player){

        Debug.Log(立钻哥哥:Player  + playerCount +  connected from  + player.ipAddress + : + player.port);

    }    //立钻哥哥:void OnPlayerConnected(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.42、OnPlayerDisconnected

++D5.42、OnPlayerDisconnected

++D5.42、OnPlayerDisconnected

++++立钻哥哥:当玩家断开连接

MonoBehaviour.OnPlayerDisconnected(NetworkPlayer player);

++++当一个玩家从服务器上断开时在服务器端调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnPlayerDisConnected(NetworkPlayer player){

        Debug.Log(立钻哥哥:Clean up after player  + player);

 

        Network.RemoveRPCs(player);

        Network.DestroyPlayerObjects(player);

    }    //立钻哥哥:void OnPlayerDisConnected(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.43、OnPostRender

++D5.43、OnPostRender

++D5.43、OnPostRender

++++立钻哥哥:当渲染之后

MonoBehaviour.OnPostRender();

++++当渲染之后

++++只有该脚本附加摄像机并启用时才会调用这个函数;OnPostRender可以是一个协同程序,在函数中调用yield语句

++++OnPostRender在摄像机渲染完所有物体之后被调用;如果想在摄像机和GUI渲染完成后做些什么,就用WaitForEndOfFrame协同程序

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    //When attached to a camera, will clear alpha channel of cameras render texture to pure white. Useful if you have camera rendering into a texture and later want to display it in GUI.

    Material mat;

 

    void OnPostRender(){

        //Create a shader that renders white only to alpha channel.

        if(!mat){

            mat = new Material( Shader \Hidden/SetAlpha\ { +

                    SubShader{ +

                        Pass { +

                            ZTest Always Cull Off ZWrite Off +

                            ColorMask A +

                        } +

                    } +

                }

            );

        } //立钻哥哥:if(){} //Draw a quad over the whole screen with the above shader

 

        GL.PushMatrix();

        GL.LoadOrtho();

 

        for(var i = 0; i < mat.passCount; ++i){

            mat.SetPass(i);

            GL.Begin(GL.QUADS);

            GL.Vertex3(0, 0, 0.1f);

            GL.Vertex3(1, 0, 0.1f);

            GL.Vertex3(1, 1, 0.1f);

            GL.Vertex3(0, 1, 0.1f);

            GL.End();

        }

 

        GL.PopMatrix();

 

    }    //立钻哥哥:void OnPostRender(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.44、OnPreCull

++D5.44、OnPreCull

++D5.44、OnPreCull

++++立钻哥哥:当消隐之前

MonoBehaviour.OnPreCull();

++++在摄像机消隐场景之前被调用

++++消隐决定哪个物体对于摄像机来说是可见的.OnPreCull仅是在这个过程被调用

++++只有脚本被附加到摄像机上时才会调用这个函数

++++如果想改变摄像机的参数(比如:fieldOfView或者transform),可以在这里做这些;场景物体的可见性将根据摄像机的参数在OnPreCull之后确定

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnPreCull(){

        camera.ResetWorldToCameraMatrix();

        camera.ResetProjectionMatrix();

        camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1));

    }    //立钻哥哥:void OnPreCull(){}

 

    void OnPreRender(){

        GL.SetRevertBackfacing(true);

    }    //立钻哥哥:void OnPreRender(){}

 

    void OnPostRender(){

        GL.SetRevertBackfacing(false);

    }    //立钻哥哥:void OnPostRender(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.45、OnPreRender

++D5.45、OnPreRender

++D5.45、OnPreRender

++++立钻哥哥:当渲染之前

MonoBehaviour.OnPreRender();

++++在摄像机渲染场景之前被调用

++++只有脚本被附加到摄像机并被启用时才会调用这个函数

++++注意:如果改变了摄像机的参数(如:fieldOfView),它将只作用于下一帧;应该用OnPreCull代替.OnPreRender可以是一个协同程序,在函数中调用yield语句即可

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    private bool revertFogState = false;

 

    void OnPreRender(){

        revertFogState = RenderSettings.fog;

        RenderSettings.fog = enabled;

    }    //立钻哥哥:void OnPreRender(){}

 

    void OnPostRender(){

        RenderSettings.fog = revertFogState;

    }    //立钻哥哥:void OnPostRender(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.46、OnRenderImage

++D5.46、OnRenderImage

++D5.46、OnRenderImage

++++立钻哥哥:当渲染图像

MonoBehaviour.OnRenderImage(RenderTexture src, RenderTexture dest);

++++当完成所有渲染图像后被调用,用来渲染图像后期效果

++++后期效果处理(仅Unity Pro

++++允许使用基于着色器的过滤器来处理最终的图像;输入的图像是源渲染纹理,结果是目标渲染纹理;当有多个图像过滤器附加在摄像机上时,它们序列化地处理图片,将第一个过滤器的目标作为下一个过滤器的源

++++这个消息被发送到所有附加在摄像机上的脚本

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public Material mat;

 

    void OnRenderIamge(RenderTexture src, RenderTexture dest){

        Graphic.Blit(src, dest, mat);

    }    //立钻哥哥:void OnRenderImage(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.47、OnRenderObject

++D5.47、OnRenderObject

++D5.47、OnRenderObject

++++立钻哥哥:当渲染对象

MonoBehaviour.OnRenderObject();

++++在摄像机场景渲染完成后被调用

++++该函数可以用来渲染自己的物体,用Graphics.DrawMesh或者其他函数;这个函数类似于OnPostRender,除非OnRenderObject被其他物体用脚本函数调用,否则它是否附于摄像机都没有关系

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public Mesh mainMesh;

    public Mesh miniMapMesh;

 

    void OnRenderObject(){

        if(Camera.current.name == MiniMapCam){

            Graphics.DrawMeshNow(miniMapMesh, transform.position, transform.rotation);

        }else{

            Graphics.DrawMeshNow(mainMesh, transform.position, transform.rotation);

        }

    }    //立钻哥哥:void OnRenderObject(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.48、OnSerializeNetworkView

++D5.48、OnSerializeNetworkView

++D5.48、OnSerializeNetworkView

++++立钻哥哥:当序列化网络视图

MonoBehaviour.OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info);

++++在一个网络视图脚本中,用于自定义变量同步

++++它自动决定被序列化的变量是否应该发送或接收,查看下面的例子获取更好的描述;这个依赖于谁拥有这个物体,例如,所有者发送,其他物体接收

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public int currentHealth = 0;

 

    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info){

         if(stream.isWriting){

             int healthC = currentHealth;

             stream.Serialize(ref healthC);

         }else{

             int healthZ = 0;

             stream.Serialize(ref healthZ);

             currentHealth = healthZ;

         }

    }    //立钻哥哥:void OnSerializeNetworkView(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.49、OnServerInitialized

++D5.49、OnServerInitialized

++D5.49、OnServerInitialized

++++立钻哥哥:当服务器初始化

MonoBehaviour.OnServerInitialized();

++++Network.InitializeServer被调用并完成时,在服务器上调用这个函数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnServerInitialized(){

        Debug.Log(立钻哥哥:Server initialized and ready.);

    }    //立钻哥哥:void OnServerInitialized(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.50、OnTriggerEnter

++D5.50、OnTriggerEnter

++D5.50、OnTriggerEnter

++++立钻哥哥:当进入触发器

MonoBehaviour.OnTriggerEnter(Collider other);

++++Collider(碰撞体)进入trigger(触发器)时调用OnTriggerEnter

++++这个消息被发送到触发器碰撞体和刚体(或者碰撞体假设没有刚体);注意:如果碰撞体附加了一个刚体,也只发送触发器事件

++++OnTriggerEnter可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    

    void OnTriggerEnter(Collider other){

        Destroy(other.gameObject);

    }    //立钻哥哥:void OnTriggerEnter(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.51、OnTriggerEnter2D

++D5.51、OnTriggerEnter2D

++D5.51、OnTriggerEnter2D

++++立钻哥哥:当进入2D触发器

MonoBehaviour.OnTriggerEnter2D(Collider2D other);

++++当另一个对象进入到这个对象附加的触发碰撞器时发送消息(仅2D物理)

++++关于更多其他碰撞信息在调用期间通过Collider2D参数报告

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public bool characterInQuicksand;

    

    void OnTriggerEnter2D(Collider2D other){

        characterInQuicksand = true;

    }    //立钻哥哥:void OnTriggerEnter2D(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.52、OnTriggerExit

++D5.52、OnTriggerExit

++D5.52、OnTriggerExit

++++立钻哥哥:当退出触发器

MonoBehaviour.OnTriggerExit(Collider other);

++++Collider(碰撞体)停止触发trigger(触发器)时调用OnTriggerExit

++++这个消息被发送到触发器和接触到这个触发器的碰撞体;注意:如果碰撞体附加了一个刚体,也只发送触发器事件

++++OnTriggerExit可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    

    void OnTriggerExit(Collider other){

        Destroy(other.gameObject);

    }    //立钻哥哥:void OnTriggerExit(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.53、OnTriggerExit2D

++D5.53、OnTriggerExit2D

++D5.53、OnTriggerExit2D

++++立钻哥哥:当退出2D触发器

MonoBehaviour.OnTriggerExit2D(Collider2D other);

++++当另一个对象离开附加在这个对象的触发碰撞器时发送消息(仅2D物理)

++++关于更多其他碰撞信息在调用期间通过Collider2D参数报告

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public bool characterInQuicksand;

    

    void OnTriggerExit2D(Collider2D other){

        characterInQuicksand = false;

    }    //立钻哥哥:void OnTriggerExit2D(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.54、OnTriggerStay

++D5.54、OnTriggerStay

++D5.54、OnTriggerStay

++++立钻哥哥:当停留触发器

MonoBehaviour.OnTriggerStay(Collider other);

++++当碰撞体接触触发器时,OnTriggerStay将在每一帧被调用

++++这个消息被发送到触发器和接触到这个触发器的碰撞体;注意:如果碰撞体附加了一个刚体,也只发送触发器事件

++++OnTriggerStay可以被用作协同程序,在函数中调用yield语句

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnTriggerStay(Collider other){

        if(other.attachedRigidbody){

            other.attachedRigidbody.AddForce(Vector3.up * 10);

        }

    }    //立钻哥哥:void OnTriggerStay(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.55、OnTriggerStay2D

++D5.55、OnTriggerStay2D

++D5.55、OnTriggerStay2D

++++立钻哥哥:当停留在2D触发器

MonoBehaviour.OnTriggerStay2D(Collider2D other);

++++当另一个对象停留在这个对象附加的触发碰撞器内时,每帧发送消息(仅2D物理)

++++关于更多其他碰撞信息在调用期间通过Collider2D参数报告

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnTriggerStay2D(Collider other){

        if(other.attachedRigidbody){

            other.attachedRigidbody.AddForce(-0.1f * other.attachedRigidbody.velocity);

        }

    }    //立钻哥哥:void OnTriggerStay2D(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.56、OnValidate

++D5.56、OnValidate

++D5.56、OnValidate

++++立钻哥哥:当验证

MonoBehaviour.OnValidate();

++++当该脚本被加载或检视面板的值被修改时,此函数被调用(仅在编辑器被调用)

++++使用这个函数来验证的MonoBehaviours数据;当在编辑器修改数据时,这可以用来确保数据保持在一定的范围内

 

 

 

 

 

++D5.57、OnWillRenderObject

++D5.57、OnWillRenderObject

++D5.57、OnWillRenderObject

++++立钻哥哥:当将渲染对象

MonoBehaviour.OnWillRenderObject();

++++如果该对象可见,OnWillRenderObject每次会被摄像机调用

++++如果MonoBehaviour被禁用,该函数不会被调用

++++该函数在对象消隐期间仅在渲染每个要消隐对象之前被调用

++++在合适的场景使用,参加脚本/Water.cs/从菜单导入包[Assets->Import Package->Water(Pro Only)]

++++注意:Camera.current设置摄像机来渲染对象

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void OnWillRenderObject(){

        //Tint the object red for identification if it is being shown on the overhead mini-map view.

        if(Camera.current.name == MiniMapCam){

            renderer.material.color = Color.red;

        }else{

             renderer.material.color = Color.write;

        }

    }    //立钻哥哥:void OnWillRenderObject(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.58、Reset

++D5.58、Reset

++D5.58、Reset

++++立钻哥哥:重设

MonoBehaviour.Reset();

++++重设为默认值

++++Reset是在用户点击检视面板的Reset按钮或者首次添加该组件时被调用;此函数只在编辑模式下被调用;Reset最常用于在检视面板中给定一个最常见的默认值

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public GameObject target;

 

    void Reset(){

        if(!target){

            target = GameObject.FindWithTag(YanlzPlayer);

        }

    }    //立钻哥哥:void Reset(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.59、Start

++D5.59、Start

++D5.59、Start

++++立钻哥哥:开始

MonoBehaviour.Start();

++++Start仅在当第一次脚本启用Update方法被调用之前调用

++++就像Awake函数,在该脚本的生命周期Start被初始化一次;然而,Awake被调用时在脚本对象初始化时调用,不管脚本是否被启用;在同一帧如果在初始化的时候没有启用脚本,Start不会被调用

++++在任何对象Start函数被调用之前,Awake函数在场景所有对象被调用;这其实是很有用的,对象A的初始化代码依赖对象B已经被初始化,对象B初始化应该在Awake中,A的代码应该在Start

++++凡对象在游戏时实例化,在场景对象的Start的函数已经完成之后,它们的Awake函数自然被调用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

    public GameObject target;

 

    void Start(){

        target = GameObject.FindWithTag(YanlzPlayer);  

    }    //立钻哥哥:void Start(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

++D5.60、Update

++D5.60、Update

++D5.60、Update

++++立钻哥哥:更新

MonoBehaviour.Update();

++++MonoBehaviour启用时,其Update在每一帧被调用

++++Update是实现各种游戏行为最常见的函数

++++为了获取自最后一次调用Update所用的时间,可以用Time.deltaTime;这个函数只有在Behaviour启用时被调用;实现组件功能时重载这个函数

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzMonoBehaviour : MonoBehaviour{

 

    void Update(){

        transform.Translate(0, 0, Time.deltaTime * 1);

    }    //立钻哥哥:void Update(){}

 

}    //立钻哥哥:public class YanlzMonoBehaviour{}

 

 

 

 

 

 

 

#F6、立钻哥哥对MonoBehaviour类的拓展

#F6、立钻哥哥对MonoBehaviour类的拓展

++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

++++[Unity快速入门]:https://blog.csdn.net/VRunSoftYanlz/article/details/105776475

++++[UnityAPI目录]:https://blog.csdn.net/VRunSoftYanlz/article/details/106533906

++++[Application应用]:https://blog.csdn.net/VRunSoftYanlz/article/details/106086327

++++[Object对象]:https://blog.csdn.net/VRunSoftYanlz/article/details/106202194

++++[GameObject]:https://blog.csdn.net/VRunSoftYanlz/article/details/106223815

++++[MonoBehaviour]:https://blog.csdn.net/VRunSoftYanlz/article/details/106533256

++++[Component组件]:https://blog.csdn.net/VRunSoftYanlz/article/details/106367004

++++[Camera摄像机]:https://blog.csdn.net/VRunSoftYanlz/article/details/106148837

++++[Shader着色器]:https://blog.csdn.net/VRunSoftYanlz/article/details/106321040

++++[Material材质]:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303

++++[Physics物理]:https://blog.csdn.net/VRunSoftYanlz/article/details/106268062

++++[RaycastHit]:https://blog.csdn.net/VRunSoftYanlz/article/details/106292370

++++[ParticleSystem]:https://blog.csdn.net/VRunSoftYanlz/article/details/106341995

++++[WWW万维网]:https://blog.csdn.net/VRunSoftYanlz/article/details/106412890

++++[LineRenerer]:https://blog.csdn.net/VRunSoftYanlz/article/details/106306388

++++[WheelCollider]:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217

++++[MovieTexture]:https://blog.csdn.net/VRunSoftYanlz/article/details/106434063

 

 

 

 

 

@@提示:有些博客可能只是开了头,如果感兴趣的同学,可以“点赞”或“评论区留言”,只要关注的同学多了,那就会继续完善哟!(“++==”,表示没有写完的,如果关注度不高就不完善了;“++ok++”,表示此篇博客已经完成,是阶段性完整的!)

 

 

 

++++VR云游戏=Unity+SteamVR+云技术+5G+AI;(说明:AI人工智能不是我们的主要研究技术,只是了解一下,领略一下有风的感觉!但是,VR是我们的研究重点

++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html

++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html

++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html

++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html

++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/

 

 

 

 

【XR游戏开发QQ群:784477094

++立钻哥哥推荐的拓展学习链接(Link_Url)

立钻哥哥推荐的拓展学习链接(Link_Url)

++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/

++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846

++++HTC_VIVE开发基础https://blog.csdn.net/VRunSoftYanlz/article/details/81989970

++++Oculus杂谈https://blog.csdn.net/VRunSoftYanlz/article/details/82469850

++++Oculus安装使用https://blog.csdn.net/VRunSoftYanlz/article/details/82718982

++++Unity+SteamVR=>VRhttps://blog.csdn.net/VRunSoftYanlz/article/details/88809370

++++Unity减少VR晕眩症https://blog.csdn.net/VRunSoftYanlz/article/details/89115518

++++SteamVR简介https://blog.csdn.net/VRunSoftYanlz/article/details/86484254

++++SteamVR脚本功能分析https://blog.csdn.net/VRunSoftYanlz/article/details/86531480

++++SteamVR2.0开发指南https://blog.csdn.net/VRunSoftYanlz/article/details/86618187

++++SteamVR2.2.0开发指南https://blog.csdn.net/VRunSoftYanlz/article/details/88784527

++++SteamVR2.2.0快速入门https://blog.csdn.net/VRunSoftYanlz/article/details/88833579

++++SteamVR2.2.0交互系统https://blog.csdn.net/VRunSoftYanlz/article/details/89199778

++++SteamVR2.2.0传送机制https://blog.csdn.net/VRunSoftYanlz/article/details/89390866

++++SteamVR2.2.0教程(一)https://blog.csdn.net/VRunSoftYanlz/article/details/89324067

++++SteamVR2.2.0教程(二)https://blog.csdn.net/VRunSoftYanlz/article/details/89894097

++++SteamVR_Skeleton_Poserhttps://blog.csdn.net/VRunSoftYanlz/article/details/89931725

++++SteamVR实战之PMCorehttps://blog.csdn.net/VRunSoftYanlz/article/details/89463658

++++SteamVR/Extrashttps://blog.csdn.net/VRunSoftYanlz/article/details/86584108

++++SteamVR/Inputhttps://blog.csdn.net/VRunSoftYanlz/article/details/86601950

++++OpenXR简介https://blog.csdn.net/VRunSoftYanlz/article/details/85726365

++++VRTK杂谈https://blog.csdn.net/VRunSoftYanlz/article/details/82562993

++++VRTK快速入门(杂谈)https://blog.csdn.net/VRunSoftYanlz/article/details/82955267

++++VRTK官方示例(目录)https://blog.csdn.net/VRunSoftYanlz/article/details/82955410

++++VRTK代码结构(目录)https://blog.csdn.net/VRunSoftYanlz/article/details/82780085

++++VRTK(SceneResources)https://blog.csdn.net/VRunSoftYanlz/article/details/82795400

++++VRTK_ControllerEventshttps://blog.csdn.net/VRunSoftYanlz/article/details/83099512

++++VRTK_InteractTouchhttps://blog.csdn.net/VRunSoftYanlz/article/details/83120220

++++虚拟现实行业应用https://blog.csdn.net/VRunSoftYanlz/article/details/88360157

++++Steam平台上的VRhttps://blog.csdn.net/VRunSoftYanlz/article/details/88960085

++++Steam平台热销VRhttps://blog.csdn.net/VRunSoftYanlz/article/details/89007741

++++VR实验:以太网帧的构成https://blog.csdn.net/VRunSoftYanlz/article/details/82598140

++++实验四:存储器扩展实验https://blog.csdn.net/VRunSoftYanlz/article/details/87834434

++++FrameVR示例V0913https://blog.csdn.net/VRunSoftYanlz/article/details/82808498

++++FrameVR示例V1003https://blog.csdn.net/VRunSoftYanlz/article/details/83066516

++++SwitchMachineV1022https://blog.csdn.net/VRunSoftYanlz/article/details/83280886

++++PlaySceneManagerV1022https://blog.csdn.net/VRunSoftYanlz/article/details/83280886

++++Unity5.x用户手册https://blog.csdn.net/VRunSoftYanlz/article/details/81712741

++++Unity面试题ABChttps://blog.csdn.net/vrunsoftyanlz/article/details/78630687

++++Unity面试题Dhttps://blog.csdn.net/VRunSoftYanlz/article/details/78630838

++++Unity面试题Ehttps://blog.csdn.net/vrunsoftyanlz/article/details/78630913

++++Unity面试题Fhttps://blog.csdn.net/VRunSoftYanlz/article/details/78630945

++++Cocos2dx面试题https://blog.csdn.net/VRunSoftYanlz/article/details/78630967

++++禅道[zentao]https://blog.csdn.net/VRunSoftYanlz/article/details/83964057

++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818

++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502

++++Lua快速入门篇(基础概述)https://blog.csdn.net/VRunSoftYanlz/article/details/81041359

++++框架知识点https://blog.csdn.net/VRunSoftYanlz/article/details/80862879

++++游戏框架(UI框架夯实篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80781140

++++游戏框架(初探篇)https://blog.csdn.net/VRunSoftYanlz/article/details/80630325

++++.Net框架设计https://blog.csdn.net/VRunSoftYanlz/article/details/87401225

++++从零开始学架构https://blog.csdn.net/VRunSoftYanlz/article/details/88095895

++++设计模式简单整理https://blog.csdn.net/vrunsoftyanlz/article/details/79839641

++++专题:设计模式(精华篇)https://blog.csdn.net/VRunSoftYanlz/article/details/81322678

++++U3D小项目参考https://blog.csdn.net/vrunsoftyanlz/article/details/80141811

++++Unity小游戏算法分析https://blog.csdn.net/VRunSoftYanlz/article/details/87908365

++++Unity案例(Vehicle)https://blog.csdn.net/VRunSoftYanlz/article/details/82355876

++++UML类图https://blog.csdn.net/vrunsoftyanlz/article/details/80289461

++++PowerDesigner简介https://blog.csdn.net/VRunSoftYanlz/article/details/86500084

++++Unity知识点0001https://blog.csdn.net/vrunsoftyanlz/article/details/80302012

++++Unity知识点0008https://blog.csdn.net/VRunSoftYanlz/article/details/81153606

++++U3D_Shader编程(第一篇:快速入门篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80372071

++++U3D_Shader编程(第二篇:基础夯实篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80372628

++++Unity引擎基础https://blog.csdn.net/vrunsoftyanlz/article/details/78881685

++++Unity面向组件开发https://blog.csdn.net/vrunsoftyanlz/article/details/78881752

++++Unity物理系统https://blog.csdn.net/vrunsoftyanlz/article/details/78881879

++++Unity2D平台开发https://blog.csdn.net/vrunsoftyanlz/article/details/78882034

++++UGUI基础https://blog.csdn.net/vrunsoftyanlz/article/details/78884693

++++UGUI进阶https://blog.csdn.net/vrunsoftyanlz/article/details/78884882

++++UGUI综合https://blog.csdn.net/vrunsoftyanlz/article/details/78885013

++++Unity动画系统基础https://blog.csdn.net/vrunsoftyanlz/article/details/78886068

++++Unity动画系统进阶https://blog.csdn.net/vrunsoftyanlz/article/details/78886198

++++Navigation导航系统https://blog.csdn.net/vrunsoftyanlz/article/details/78886281

++++Unity特效渲染https://blog.csdn.net/vrunsoftyanlz/article/details/78886403

++++Unity数据存储https://blog.csdn.net/vrunsoftyanlz/article/details/79251273

++++Unity中Sqlite数据库https://blog.csdn.net/vrunsoftyanlz/article/details/79254162

++++WWW类和协程https://blog.csdn.net/vrunsoftyanlz/article/details/79254559

++++Unity网络https://blog.csdn.net/vrunsoftyanlz/article/details/79254902

++++Unity资源加密https://blog.csdn.net/VRunSoftYanlz/article/details/87644514

++++PhotonServer简介https://blog.csdn.net/VRunSoftYanlz/article/details/86652770

++++编写Photon游戏服务器https://blog.csdn.net/VRunSoftYanlz/article/details/86682935

++++C#事件https://blog.csdn.net/vrunsoftyanlz/article/details/78631267

++++C#委托https://blog.csdn.net/vrunsoftyanlz/article/details/78631183

++++C#集合https://blog.csdn.net/vrunsoftyanlz/article/details/78631175

++++C#泛型https://blog.csdn.net/vrunsoftyanlz/article/details/78631141

++++C#接口https://blog.csdn.net/vrunsoftyanlz/article/details/78631122

++++C#静态类https://blog.csdn.net/vrunsoftyanlz/article/details/78630979

++++C#中System.String类https://blog.csdn.net/vrunsoftyanlz/article/details/78630945

++++C#数据类型https://blog.csdn.net/vrunsoftyanlz/article/details/78630913

++++Unity3D默认的快捷键https://blog.csdn.net/vrunsoftyanlz/article/details/78630838

++++游戏相关缩写https://blog.csdn.net/vrunsoftyanlz/article/details/78630687

++++UnityAPI.Rigidbody刚体https://blog.csdn.net/VRunSoftYanlz/article/details/81784053

++++UnityAPI.Material材质https://blog.csdn.net/VRunSoftYanlz/article/details/81814303

++++UnityAPI.Android安卓https://blog.csdn.net/VRunSoftYanlz/article/details/81843193

++++UnityAPI.AndroidJNI安卓JNIhttps://blog.csdn.net/VRunSoftYanlz/article/details/81879345

++++UnityAPI.Transform变换https://blog.csdn.net/VRunSoftYanlz/article/details/81916293

++++UnityAPI.WheelCollider轮碰撞器https://blog.csdn.net/VRunSoftYanlz/article/details/82356217

++++UnityAPI.Resources资源https://blog.csdn.net/VRunSoftYanlz/article/details/83155518

++++JSON数据结构https://blog.csdn.net/VRunSoftYanlz/article/details/82026644

++++CocosStudio快速入门https://blog.csdn.net/VRunSoftYanlz/article/details/82356839

++++Unity企业内训(目录)https://blog.csdn.net/VRunSoftYanlz/article/details/82634668

++++Unity企业内训(第1讲)https://blog.csdn.net/VRunSoftYanlz/article/details/82634733

++++Unity企业内训(第2讲)https://blog.csdn.net/VRunSoftYanlz/article/details/82861180

++++Unity企业内训(第3讲)https://blog.csdn.net/VRunSoftYanlz/article/details/82927699

++++Unity企业内训(第4讲)https://blog.csdn.net/VRunSoftYanlz/article/details/83479776

++++Unity企业内训(第5讲)https://blog.csdn.net/VRunSoftYanlz/article/details/83963811

++++Unity企业内训(第6讲)https://blog.csdn.net/VRunSoftYanlz/article/details/84207696

++++钻哥带您了解产品原型https://blog.csdn.net/VRunSoftYanlz/article/details/87303828

++++插件<Obi Rope>https://blog.csdn.net/VRunSoftYanlz/article/details/83963905

++++计算机组成原理(教材篇)https://blog.csdn.net/VRunSoftYanlz/article/details/82719129

++++5G接入:云计算和雾计算https://blog.csdn.net/VRunSoftYanlz/article/details/88372718

++++云计算通俗讲义https://blog.csdn.net/VRunSoftYanlz/article/details/88652803

++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz

--_--VRunSoft:lovezuanzuan--_--

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值