Archived
分散文件结构,添加了枚举类型的一个辅助类
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
public static class MacroObject
|
||||
{
|
||||
#region 对象操作
|
||||
|
||||
/// <summary>
|
||||
/// 无论如何都要获取一个组件
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static T GetComponentAnyway<T>(this GameObject obj)
|
||||
where T : Component
|
||||
{
|
||||
var component = obj.GetComponent<T>();
|
||||
if(component is null)
|
||||
component = obj.AddComponent<T>();
|
||||
return component;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无论如何都要获取一个对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetObjectAnyway<T>(this T obj)
|
||||
where T : new()
|
||||
{
|
||||
if(obj is null)
|
||||
obj = new T();
|
||||
return obj;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user