public static ResourceAuto CreateWebRequest(string path, int cacheVersion = 0, bool readable = false)
        {
            var item = new ResourceAuto();

            item.async           = true;
            item.id              = ResourceBase.GetJavaHash(path);
            item.controlType     = ControlType.Show | ControlType.Hide;
            item.loadableWeb     = true;
            item.cacheVersion    = cacheVersion;
            item.readableTexture = readable;
            item.webPath         = path;

            return(item);
        }
        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);
        }
Exemplo n.º 3
0
        public virtual void Validate(Object item)
        {
            if (item == null)
            {
                return;
            }

            ME.EditorUtilities.SetValueIfDirty(ref this.assetPath, UnityEditor.AssetDatabase.GetAssetPath(item));

            #region Resources
            {
                var resourcePath = (this.assetPath.Contains("/Resources/") == true ? this.assetPath.Split(new string[] { "/Resources/" }, System.StringSplitOptions.None)[1] : string.Empty);
                var ext          = System.IO.Path.GetExtension(resourcePath);
                ME.EditorUtilities.SetValueIfDirty(ref this.resourcesPath, resourcePath.Substring(0, resourcePath.Length - ext.Length));

                ME.EditorUtilities.SetValueIfDirty(ref this.loadableResource, (string.IsNullOrEmpty(this.resourcesPath) == false));
            }
            #endregion

            #region StreamingAssets
            {
                var streamingAssetsPath = (this.assetPath.Contains("/StreamingAssets/") == true ? this.assetPath.Split(new string[] { "/StreamingAssets/" }, System.StringSplitOptions.None)[1] : string.Empty);
                var platformSplit       = streamingAssetsPath.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);

                if (platformSplit.Length > 0)
                {
                    var localPath          = string.Join("/", platformSplit, 1, platformSplit.Length - 1);
                    var localDir           = System.IO.Path.GetDirectoryName(localPath);
                    var filenameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(streamingAssetsPath);

                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathIOS, this.GetPlatformDirectory(Platform.iOS, localDir, filenameWithoutExt));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathAndroid, this.GetPlatformDirectory(Platform.Android, localDir, filenameWithoutExt));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathStandalone, this.GetPlatformDirectory(Platform.Standalone, localDir, filenameWithoutExt));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathPS4, this.GetPlatformDirectory(Platform.PS4, localDir, filenameWithoutExt));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathXBOXONE, this.GetPlatformDirectory(Platform.XBOXONE, localDir, filenameWithoutExt));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathCommon, this.GetPlatformDirectory(Platform.Common, localDir, filenameWithoutExt));

                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathIOSMovieAudio, this.GetMovieAudio(this.streamingAssetsPathIOS));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathAndroidMovieAudio, this.GetMovieAudio(this.streamingAssetsPathAndroid));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathStandaloneMovieAudio, this.GetMovieAudio(this.streamingAssetsPathStandalone));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathPS4MovieAudio, this.GetMovieAudio(this.streamingAssetsPathPS4));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathXBOXONEMovieAudio, this.GetMovieAudio(this.streamingAssetsPathXBOXONE));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathCommonMovieAudio, this.GetMovieAudio(this.streamingAssetsPathCommon));

                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathIOSIsMovie, this.IsMovie(this.streamingAssetsPathIOS));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathAndroidIsMovie, this.IsMovie(this.streamingAssetsPathAndroid));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathStandaloneIsMovie, this.IsMovie(this.streamingAssetsPathStandalone));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathPS4IsMovie, this.IsMovie(this.streamingAssetsPathPS4));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathXBOXONEIsMovie, this.IsMovie(this.streamingAssetsPathXBOXONE));
                    ME.EditorUtilities.SetValueIfDirty(ref this.streamingAssetsPathCommonIsMovie, this.IsMovie(this.streamingAssetsPathCommon));
                }

                ME.EditorUtilities.SetValueIfDirty(ref this.loadableStream, (string.IsNullOrEmpty(streamingAssetsPath) == false));
            }
            #endregion

            #region AssetBundles
            var importer = UnityEditor.AssetImporter.GetAtPath(this.assetPath);
            ME.EditorUtilities.SetValueIfDirty(ref this.loadableAssetBundle, importer != null && string.IsNullOrEmpty(importer.assetBundleName) == false);
            if (this.loadableAssetBundle == true)
            {
                ME.EditorUtilities.SetValueIfDirty(ref this.assetBundleName, importer.assetBundleName);
                ME.EditorUtilities.SetValueIfDirty(ref this.loadableResource, false);
                ME.EditorUtilities.SetValueIfDirty(ref this.loadableStream, false);
                ME.EditorUtilities.SetValueIfDirty(ref this.multiObjectsAssetBundle, true);

                WindowSystemAssetBundlesMap map = null;
                var objects = UnityEditor.AssetDatabase.FindAssets("t:ScriptableObject");
                for (int i = 0, size = objects.Length; i < size; ++i)
                {
                    var path = UnityEditor.AssetDatabase.GUIDToAssetPath(objects[i]);
                    if (path.Contains("WindowSystemAssetBundlesMap"))
                    {
                        map = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(WindowSystemAssetBundlesMap)) as WindowSystemAssetBundlesMap;
                        break;
                    }
                }

                if (map == null)
                {
                    Debug.LogError("Missing WindowSystemAssetBundlesMap!");
                }
                else
                {
                    ME.EditorUtilities.SetValueIfDirty(ref this.objectIndexAssetBundle, map.GetIndex(this.assetBundleName, this.assetPath));
                }
            }
            #endregion

            var uniquePath = (this.multiObjects == true) ? (string.Format("{0}#{1}", this.GetAssetPath(), this.objectIndex)) : this.GetAssetPath();
            ME.EditorUtilities.SetValueIfDirty(ref this.id, ResourceBase.GetJavaHash(uniquePath));

            ME.EditorUtilities.SetValueIfDirty(ref this.canBeUnloaded, ((item is GameObject) == false && (item is Component) == false));
        }
        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);
        }