Unity热更新方案C#Like(十)-详解支持的C#特性:宏和区域

C#Like是Unity的热更方案,使用纯C#语言写出可以热更新的代码,就像可以在所有平台使用DLL(动态链接库)文件一样.遵从KISS设计原则,让用户轻松构建或升级成Unity的热更新项目.

简介

本篇主要介绍C#Like支持的C#特性:宏和区域

  • C#Like免费版:不支持
  • C#Like完整版:支持#if #elif #else #endif #region #endregion

C#Like免费版:

示范代码如下:

using UnityEngine;  
  
namespace CSharpLike  
{  
    public partial class ExampleCSharp : LikeBehaviour  
    {  
        /// <summary>  
        /// 支持unity内置的宏和自定义的宏("Edit"->"Project Settings"->"Player"->"Scripting Define Symbols").  
        /// 和Unity一样,除了'UNITY_EDITOR/UNITY_EDITOR_WIN/UNITY_EDITOR_OSX/UNITY_EDITOR_LINUX'  
        /// (这几个带UNITY_EDITOR宏仅在调试模式下在编辑内生效)  
        /// </summary>  
        void TestMacroAndRegion()  
        {  
            Debug.LogError("示范区域和宏: 你不能在C#Like免费版里使用区域和宏(在完整版已支持).强烈推荐升级到完整版:");  
            // 我们提供以下方案给免费用户:  
            // 宏: 在非热更脚本里定义变量来代替  
            // 区域: 不使用 (你的代码在编辑器里看起来没有那么整洁).  
  
            // 示范宏 (模拟)  
            // 免费版  
            if (Application.platform == RuntimePlatform.WebGLPlayer)  
                Debug.Log("Test macro (simulate): is UNITY_WEBGL");  
            else  
                Debug.Log("Test macro (simulate): is not UNITY_WEBGL");  
            // 完整版  
//#if UNITY_WEBGL  
//            Debug.Log("Test macro: is UNITY_WEBGL");  
//#else  
//            Debug.Log("Test macro: is not UNITY_WEBGL");  
//#endif  
            Debug.LogError("Test Macro:");  
        }  
    }  
}

 C#Like完整版:

示范代码如下:

using UnityEngine;  
  
namespace CSharpLike  
{  
    public partial class ExampleCSharp : LikeBehaviour  
    {  
        /// <summary>  
        /// 支持unity内置的宏和自定义的宏("Edit"->"Project Settings"->"Player"->"Scripting Define Symbols").  
        /// 和Unity一样,除了'UNITY_EDITOR/UNITY_EDITOR_WIN/UNITY_EDITOR_OSX/UNITY_EDITOR_LINUX'  
        /// (这几个带UNITY_EDITOR的宏仅在调试模式下在编辑器内生效)  
        /// </summary>  
        void TestMacroAndRegion()  
        {  
            Debug.LogError("Test Macro:");  
#if UNITY_EDITOR   
            Debug.Log("test macro UNITY_EDITOR: in editor and in 'debug mode'");  
#else  
            Debug.Log("test macro UNITY_EDITOR: not in editor");  
#endif  
 
#if UNITY_2018_1_OR_NEWER && (!UNITY_2020_1)  
            Debug.Log("Test macro:enter UNITY_2018_1_OR_NEWER && (!UNITY_2020_1)");  
    #if UNITY_ANDROID || UNITY_IOS  
            Debug.Log("Test macro:enter UNITY_ANDROID || UNITY_IOS");  
    #elif UNITY_STANDALONE  
            Debug.Log("Test macro:enter UNITY_STANDALONE");  
    #endif  
#elif UNITY_2017  
            Debug.Log("Test macro:enter UNITY_2017");  
#else  
            Debug.Log("test macro:enter #else");  
#endif  
            Debug.Log("Test LogError:");  
#region Test Region  
            Debug.Log("Test Region: content 1");  
#endregion  
            Debug.Log("Test Region: content 2");  
#region Test Region2  
            Debug.Log("Test Region: content 3");  
#endregion  
            Debug.Log("Test Region: content 4");  
        }  
    }  
} 

 本系列文章导读:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C#Like

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值