您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
50 行
1.1 KiB
50 行
1.1 KiB
using System;
|
|
using UnityEngine;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Use this attribute to limit the types allowed on a weak asset reference field
|
|
/// </summary>
|
|
[AttributeUsage(AttributeTargets.Field)]
|
|
public class AssetTypeAttribute : Attribute
|
|
{
|
|
public Type assetType;
|
|
|
|
public AssetTypeAttribute(Type t)
|
|
{
|
|
assetType = t;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Weak asset reference that does not result in assets getting pulled in. Use has
|
|
/// responsibility to find another way to actually get asset loaded
|
|
/// </summary>
|
|
[System.Serializable]
|
|
public class WeakAssetReference
|
|
{
|
|
public string guid = "";
|
|
|
|
#if UNITY_EDITOR
|
|
public T LoadAsset<T>() where T : UnityEngine.Object
|
|
{
|
|
var path = AssetDatabase.GUIDToAssetPath(guid);
|
|
return AssetDatabase.LoadAssetAtPath<T>(path);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// This base is here to allow CustomPropertyDrawer to pick it up
|
|
[System.Serializable]
|
|
public class WeakBase
|
|
{
|
|
public string guid = "";
|
|
}
|
|
|
|
// Derive from this to create a typed weak asset reference
|
|
[System.Serializable]
|
|
public class Weak<T> : WeakBase
|
|
{
|
|
}
|