public static void PrecacheWithSounds <T>(WeakAssetRef <T> asset) where T : Component { var t = asset.Load(); if (t != null) { t.gameObject.PrecacheSounds(); } }
public static void PrecacheWithSounds <T>(this WeakAssetRef <T> asset, System.Action <T> f) where T : Component { var t = asset.Load(); if (t != null) { t.gameObject.PrecacheSounds(); f(t); } }
public static bool WeakRefField(string displayName, WeakAssetRef weakRef) { var editorPath = weakRef.inspectorEditorPath; var assetPath = weakRef.inspectorAssetPath; UnityEngine.Object curObj = null; if (!string.IsNullOrEmpty(editorPath)) { curObj = AssetDatabase.LoadAssetAtPath(editorPath, weakRef.inspector_assetType); } bool changed = false; var newObj = EditorGUILayout.ObjectField(displayName, curObj, weakRef.inspector_assetType, false); if (newObj != curObj) { if (newObj != null) { var newEditorPath = AssetDatabase.GetAssetPath(newObj); var newAssetPath = Utils.GetResourceRelativePath(newEditorPath); if (string.IsNullOrEmpty(newAssetPath)) { EditorUtility.DisplayDialog("Error", "Assets referenced in this field must be inside a Resources folder.", "OK"); } else { weakRef.InspectorUpdate(newEditorPath, newAssetPath); changed = true; } } else { weakRef.InspectorUpdate(string.Empty, string.Empty); changed = true; } } return(changed); }