Asset fields
AssetField
class can be used to ref an asset (path and bundledAsset)
(find bundle automatically)
public BundleSceneField MyScene;
public AudioField MyMusic;
public MaterialField MyMaterial;
public GameObjectField MyPrefab;
public TextureField MyTexture;
public Texture2DField MyTexture2D;
...
public AssetField MyGenericAsset;
Debug.Log(Scene.Path);
Debug.Log(Scene.BundledAsset);
var myMusic = await myAudioField.Load();
Your own Asset Field
Runtime
using EODE.Wonderland;
[System.Serializable] public class AudioField : AssetField {
public async System.Threading.Tasks.Task<AudioClip> Load() {
return await AssetBundles.LoadAsset<AudioClip>(BundledAsset);
}
}
Editor
using EODE.Wonderland;
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(BundleSceneField), true)]
public class BundleSceneFieldEditor : AssetFieldEditor {
protected override string GetAssetPath(Rect position, Object oldAsset) {
return AssetDatabase.GetAssetPath(EditorGUI.ObjectField(position, oldAsset, typeof(SceneAsset), false) as SceneAsset);
}
}
// Texture2D example
[CustomPropertyDrawer(typeof(Texture2DField), true)]
public class Texture2DFieldEditor : AssetFieldEditor {
protected override string GetAssetPath(Rect position, Object oldAsset) {
position.width = 70;
position.height = 70;
return AssetDatabase.GetAssetPath(EditorGUI.ObjectField(position, oldAsset, typeof(Texture2D), false) as Texture2D);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
if (WithBundle) return 87f;
else return 72f;
}
}