Unity3D-启动unity事件,切换平台监听

来源:互联网 发布:淘宝入驻协议书 编辑:程序博客网 时间:2024/06/10 17:24

1,启动unity监听,针对unity启动监听,可以做些版本检测,以及平台切换监听,可以做些自己想做的操作

[InitializeOnLoad],添加这个标示,标示在unity启动的时候会执行这个脚本

unity官方给的解释是:

Running Editor Script Code on Launch

    Sometimes it is useful to be able to run some editor script code in a project as soon as Unity launches without requiring action from the user.You can do this by applying the InitializeOnLoad attribute to a class which has a static constructor. A static constructor is a function with the same name as the class, declared static and without a return type or parameters (see here for more information)
using UnityEngine;using UnityEditor;[InitializeOnLoad]public class Startup {    static Startup()    {        Debug.Log("Up and running");    }}

2,代码切换平台方法  EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android)

监听平台切换后方法 

EditorUserBuildSettings.activeBuildTargetChanged=delegate(){
if(EditorUserBuildSettings.activeBuildTarget==BuildTarget.Iphone){
Debug.Log("do you want to do");
}
};


0 0