modify
This commit is contained in:
parent
cd4c084587
commit
32bc5f972a
@ -1,114 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AlicizaX
|
||||
{
|
||||
/// <summary>
|
||||
/// 辅助器创建器相关的实用函数。
|
||||
/// </summary>
|
||||
public static class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建辅助器。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要创建的辅助器类型。</typeparam>
|
||||
/// <param name="helperTypeName">要创建的辅助器类型名称。</param>
|
||||
/// <param name="customHelper">若要创建的辅助器类型为空时,使用的自定义辅助器类型。</param>
|
||||
/// <returns>创建的辅助器。</returns>
|
||||
public static T CreateHelper<T>(string helperTypeName, T customHelper) where T : MonoBehaviour
|
||||
{
|
||||
return CreateHelper(helperTypeName, customHelper, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建辅助器。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要创建的辅助器类型。</typeparam>
|
||||
/// <param name="helperTypeName">要创建的辅助器类型名称。</param>
|
||||
/// <param name="customHelper">若要创建的辅助器类型为空时,使用的自定义辅助器类型。</param>
|
||||
/// <param name="index">要创建的辅助器索引。</param>
|
||||
/// <returns>创建的辅助器。</returns>
|
||||
public static T CreateHelper<T>(string helperTypeName, T customHelper, int index) where T : MonoBehaviour
|
||||
{
|
||||
T helper = null;
|
||||
if (!string.IsNullOrEmpty(helperTypeName))
|
||||
{
|
||||
System.Type helperType = Utility.Assembly.GetType(helperTypeName);
|
||||
if (helperType == null)
|
||||
{
|
||||
Log.Warning("Can not find helper type '{0}'.", helperTypeName);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!typeof(T).IsAssignableFrom(helperType))
|
||||
{
|
||||
Log.Warning("Type '{0}' is not assignable from '{1}'.", typeof(T).FullName, helperType.FullName);
|
||||
return null;
|
||||
}
|
||||
|
||||
helper = (T)new GameObject().AddComponent(helperType);
|
||||
}
|
||||
else if (customHelper == null)
|
||||
{
|
||||
Log.Warning("You must set custom helper with '{0}' type first.", typeof(T).FullName);
|
||||
return null;
|
||||
}
|
||||
else if (customHelper.gameObject.InScene())
|
||||
{
|
||||
helper = index > 0 ? Object.Instantiate(customHelper) : customHelper;
|
||||
}
|
||||
else
|
||||
{
|
||||
helper = Object.Instantiate(customHelper);
|
||||
}
|
||||
|
||||
return helper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建辅助器。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要创建的辅助器类型。</typeparam>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="helperTypeName">要创建的辅助器类型名称。</param>
|
||||
/// <param name="customHelper">若要创建的辅助器类型为空时,使用的自定义辅助器类型。</param>
|
||||
/// <param name="index">要创建的辅助器索引。</param>
|
||||
/// <returns>创建的辅助器。</returns>
|
||||
public static T CreateHelper<T>(GameObject target, string helperTypeName, T customHelper, int index) where T : MonoBehaviour
|
||||
{
|
||||
GameFrameworkGuard.NotNull(target, nameof(target));
|
||||
T helper = null;
|
||||
if (!string.IsNullOrEmpty(helperTypeName))
|
||||
{
|
||||
System.Type helperType = Utility.Assembly.GetType(helperTypeName);
|
||||
if (helperType == null)
|
||||
{
|
||||
Log.Warning("Can not find helper type '{0}'.", helperTypeName);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!typeof(T).IsAssignableFrom(helperType))
|
||||
{
|
||||
Log.Warning("Type '{0}' is not assignable from '{1}'.", typeof(T).FullName, helperType.FullName);
|
||||
return null;
|
||||
}
|
||||
|
||||
helper = (T)target.AddComponent(helperType);
|
||||
}
|
||||
else if (customHelper == null)
|
||||
{
|
||||
Log.Warning("You must set custom helper with '{0}' type first.", typeof(T).FullName);
|
||||
return null;
|
||||
}
|
||||
else if (customHelper.gameObject.InScene())
|
||||
{
|
||||
helper = index > 0 ? Object.Instantiate(customHelper) : customHelper;
|
||||
}
|
||||
else
|
||||
{
|
||||
helper = Object.Instantiate(customHelper);
|
||||
}
|
||||
|
||||
return helper;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7b03d310d08d45429a94d6f62c942b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user