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

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" ) ;
}
} ;


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值