private Object Load_INTERNAL(string path, System.Type type) { //var watch = new System.Diagnostics.Stopwatch(); //watch.Start(); var pathHash = ResourceBase.GetJavaHash(path); var typeHash = ResourceBase.GetJavaHash(type.FullName); var resourceKey = ResourceBase.GetKey(pathHash, typeHash); Object output = null; if (output == null) { ResourceEntity entity; if (this.resources.TryGetValue(resourceKey, out entity) == true) { output = entity.resource; } } if (output == null) { var key = ResourceBase.GetKey(pathHash, 0); ResourceEntity entity; if (this.resources.TryGetValue(key, out entity) == true) { if (entity.resource is GameObject && type != typeof(GameObject)) { output = (entity.resource as GameObject).GetComponent(type); } else { output = entity.resource; } } } if (output == null) { output = Resources.Load(path, type); //this.resources.Add(resourceKey, new ResourceEntity() { resource = output }); } //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) Debug.Log(string.Format("Resource `{0}` got in {1}ms ({2} ticks)", path, watch.ElapsedMilliseconds, watch.ElapsedTicks)); //watch.Stop(); return(output); }
public void OnValidate() { if (GUI.changed == false) { return; } if (this.preloadedResourcesEditor == null) { return; } var changed = true; if (this.prevResourcesEditor != null) { changed = false; if (this.prevResourcesEditor.Length == this.preloadedResourcesEditor.Length) { for (int i = 0; i < this.preloadedResourcesEditor.Length; ++i) { if (this.preloadedResourcesEditor[i] != this.preloadedResourcesEditor[i]) { changed = true; break; } } } else { changed = true; } } if (changed == false) { return; } var objects = ME.ListPool <Object> .Get(); var objectPaths = ME.ListPool <string> .Get(); var objectTypes = ME.ListPool <string> .Get(); for (int i = 0; i < this.preloadedResourcesEditor.Length; ++i) { var dir = UnityEditor.AssetDatabase.GetAssetPath(this.preloadedResourcesEditor[i]); string[] guids = null; if (System.IO.Directory.Exists(dir) == true) { guids = UnityEditor.AssetDatabase.FindAssets("t:Object", new string[] { dir }); } else { guids = new string[] { UnityEditor.AssetDatabase.AssetPathToGUID(dir) }; } for (int j = 0; j < guids.Length; ++j) { var path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[j]); var isGo = false; if (UnityEditor.AssetDatabase.LoadAssetAtPath <Object>(path) is GameObject) { isGo = true; } var allAssets = (isGo == true ? new Object[] { UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(path) } : UnityEditor.AssetDatabase.LoadAllAssetsAtPath(path)); for (int k = 0; k < allAssets.Length; ++k) { path = UnityEditor.AssetDatabase.GetAssetPath(allAssets[k]); var type = allAssets[k].GetType().FullName; objectTypes.Add(type); objectPaths.Add(path); objects.Add(allAssets[k]); } } } this.preloadedResources.Clear(); for (int i = 0; i < objects.Count; ++i) { var item = objects[i]; if (item is TextAsset) { continue; } if (item is Sprite) { continue; } if (item is Animator) { continue; } var path = ResourceBase.GetResourcePathFromAssetPath(objectPaths[i]); var pathHash = ResourceBase.GetJavaHash(path); var typeHash = (string.IsNullOrEmpty(objectTypes[i]) == false ? ResourceBase.GetJavaHash(objectTypes[i]) : 0); var resourceKey = ResourceBase.GetKey(pathHash, typeHash); if (string.IsNullOrEmpty(path) == false && this.preloadedResources.Any(x => x.key == resourceKey) == false) { this.preloadedResources.Add(new PreloadedResourceEntity() { resource = item, key = resourceKey, }); } else { //if (Constants.LOGS_ENABLED == true) Debug.LogWarning(string.Format("Duplicated entity at path: {0} ({1})", path, objectTypes[i])); } } this.prevResourcesEditor = this.preloadedResourcesEditor; ME.ListPool <Object> .Release(objects); ME.ListPool <string> .Release(objectPaths); ME.ListPool <string> .Release(objectTypes); }