如何实现unity函数的再次封装
展开全部
这里我将用unity内的Debug打印方法为例进行封装:
1.新建一个unity工程项目;
2.新建一个脚本Debugger.cs;
using UnityEngine;
using System.Collections;
public class Debugger {
//是否调试打印的开关
public static bool
isOpenDebugger = false;
public static void
Log(object message)
{
Log(message, null);
}
public static void
Log(object message, UnityEngine.Object context)
{
if (isOpenDebugger)
{
Debug.Log(message, context);
}
}
public static void
LogError(object message)
{
LogError(message, null);
}
public static void
LogError(object message, UnityEngine.Object context)
{
if (isOpenDebugger)
{
Debug.LogError(message, context);
}
}
public static void
LogWarning(object message)
{
LogWarning(message, null);
}
public static void
LogWarning(object message, UnityEngine.Object context)
{
if (isOpenDebugger)
{
Debug.LogWarning(message, context);
}
}
}
3.打开VS,新建一个类库项目
4.更改新建后的项目类名为Debugger,并且将unity项目中Debugger类中的内容复制到VS新建的类库项目当中;
1.新建一个unity工程项目;
2.新建一个脚本Debugger.cs;
using UnityEngine;
using System.Collections;
public class Debugger {
//是否调试打印的开关
public static bool
isOpenDebugger = false;
public static void
Log(object message)
{
Log(message, null);
}
public static void
Log(object message, UnityEngine.Object context)
{
if (isOpenDebugger)
{
Debug.Log(message, context);
}
}
public static void
LogError(object message)
{
LogError(message, null);
}
public static void
LogError(object message, UnityEngine.Object context)
{
if (isOpenDebugger)
{
Debug.LogError(message, context);
}
}
public static void
LogWarning(object message)
{
LogWarning(message, null);
}
public static void
LogWarning(object message, UnityEngine.Object context)
{
if (isOpenDebugger)
{
Debug.LogWarning(message, context);
}
}
}
3.打开VS,新建一个类库项目
4.更改新建后的项目类名为Debugger,并且将unity项目中Debugger类中的内容复制到VS新建的类库项目当中;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询