
Hello there!
did you ever ask how to load a resource from a non-resources folder? With Prefab Evolution! Here is the source code:
Please have a look at the end of this. It’s not my script and there are some things you should consider – i recommend to read the source as well. Just see at the end of this post and you’ll find the link to the source. I did not post this on guides on purpose, since it’s not my piece of code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
using UnityEngine; using System.Collections.Generic; using System.Linq; public class MyResources : ScriptableObject { [System.Serializable] private class ResourceInfo { public string path; public Object asset; } [SerializeField] private List<ResourceInfo> resources; static private MyResources instance; static private MyResources Instance { get { if (instance == null) { instance = Resources.Load("MyResources") as MyResources; } return instance; } } static public Object Load(string path) { var record = Instance.resources.FirstOrDefault(resource => resource.path == path); return record == null ? null : record.asset; } static public T Load<T>(string path) where T:Object { return Load(path) as T; } #if UNITY_EDITOR [UnityEditor.MenuItem("Assets/Create/MyResources")] static void Create() { var asset = ScriptableObject.CreateInstance<MyResources>(); var path = "Resources/MyResources.asset"; UnityEditor.AssetDatabase.CreateAsset(asset, path); UnityEditor.AssetDatabase.ImportAsset(path); } #endif } |
SOURCE:
Loading Prefabs from custom folder?! (NOT /Resources)
Antworten