public void Awake() { MovieSystem.instance = this; this.InitializeModule_INTERNAL(); }
public bool IsMaterialLoadingType() { if (this.loadableStream == true) { return(MovieSystem.IsMaterialLoadingType()); } return(false); }
public static void UnloadResource_INTERNAL(IResourceReference resourceController, ResourceBase resource) { var item = WindowSystemResources.instance.loaded.FirstOrDefault(x => x.id == resource.GetId()); if (WindowSystemResources.Remove(item, resourceController, resource) == true) { MovieSystem.Unload(resourceController as IImageComponent, resource); } }
public void LateUpdate() { if (this.lastQualityIndex != QualitySettings.GetQualityLevel()) { this.lastQualityIndex = QualitySettings.GetQualityLevel(); MovieSystem.PlayPauseAll(); } }
private bool CanPlayByQuality_INTERNAL(Texture texture) { var item = MovieSystem.GetQualityItem(); if (item == null) { return(this.defaultPlayingState); } if (texture.width > item.minSize || texture.height > item.minSize) { return(item.canPlay); } return(this.defaultPlayingState); }
public IEnumerator Load <T>(IImageComponent component, Graphic graphic, string customResourcePath, System.Action <T> callback) where T : Object { if (ResourceBase.iterations == null) { ResourceBase.iterations = new Dictionary <Graphic, int>(); } if (ResourceBase.colorCache == null) { ResourceBase.colorCache = new Dictionary <Graphic, Color>(); } customResourcePath = customResourcePath ?? (string.IsNullOrEmpty(this.customResourcePath) == true ? null : this.customResourcePath); this.customResourcePath = customResourcePath; var isFade = (WindowSystemResources.GetAsyncLoadFadeTime() > 0f); var iterationFailed = false; var iteration = 0; var oldColor = Color.white; if (graphic != null) { var isEmpty = true; if (graphic is Image) { isEmpty = ((graphic as Image).sprite == null); } if (isEmpty == true && graphic is RawImage) { isEmpty = ((graphic as RawImage).texture == null); } if (isFade == true) { TweenerGlobal.instance.removeTweens(graphic); } if (ResourceBase.iterations.TryGetValue(graphic, out iteration) == false) { ResourceBase.iterations.Add(graphic, iteration); } if (ResourceBase.colorCache.TryGetValue(graphic, out oldColor) == true) { // restoring color graphic.color = oldColor; } else { ResourceBase.colorCache.Add(graphic, graphic.color); } oldColor = graphic.color; if (isEmpty == true) { graphic.color = new Color(oldColor.r, oldColor.g, oldColor.b, 0f); } ++ResourceBase.iterations[graphic]; iteration = ResourceBase.iterations[graphic]; //Debug.Log("Loading: " + customResourcePath + ", iter: " + iteration, graphic); } #region Load Resource if (this.loadableResource == true || string.IsNullOrEmpty(customResourcePath) == false) { var resourcePath = customResourcePath ?? this.resourcesPath; if (this.async == true) { var task = Resources.LoadAsync <T>(resourcePath); while (task.isDone == false) { yield return(false); } iterationFailed = !(graphic == null || iteration == ResourceBase.iterations[graphic]); if (iterationFailed == false) { if (this.multiObjects == true && this.objectIndex >= 0) { callback.Invoke(Resources.LoadAll(resourcePath)[this.objectIndex] as T); } else { callback.Invoke(task.asset as T); } } task = null; } else { if (this.multiObjects == true && this.objectIndex >= 0) { callback.Invoke(Resources.LoadAll(resourcePath)[this.objectIndex] as T); } else { var asset = Resources.Load <T>(resourcePath); callback.Invoke(asset); } } } else if (this.loadableStream == true) { var task = MovieSystem.LoadTexture(component); while (task.isDone == false) { yield return(false); } iterationFailed = !(graphic == null || iteration == ResourceBase.iterations[graphic]); if (iterationFailed == false) { //Debug.Log("Loaded: " + customResourcePath + ", iter: " + iteration, graphic); callback.Invoke(task.asset as T); } task.Dispose(); task = null; } #endregion if (iterationFailed == false && graphic != null) { if (isFade == true) { TweenerGlobal.instance.addTweenAlpha(graphic, WindowSystemResources.GetAsyncLoadFadeTime(), oldColor.a).tag(graphic).onCancel((g) => { g.color = oldColor; }); } else { graphic.color = oldColor; } } }
protected void OnDestory() { MovieSystem.instance = null; }
public void Awake() { MovieSystem.instance = this; }
private System.Collections.Generic.IEnumerator <byte> StartTask <T>(TaskItem task) /*where T : Object*/ { var isBytesOutput = (typeof(T) == typeof(byte[])); #region Load Resource if (task.resource.loadableWeb == true) { if (task.resource.webPath.Contains("://") == false) { task.resource.webPath = string.Format("file://{0}", task.resource.webPath); } WWW www = null; if (task.resource.cacheVersion > 0) { www = WWW.LoadFromCacheOrDownload(task.resource.webPath, task.resource.cacheVersion); } else { www = new WWW(task.resource.webPath); } while (www.isDone == false) { yield return(0); } if (string.IsNullOrEmpty(www.error) == true) { var type = typeof(T); if (type == typeof(Texture) || type == typeof(Texture2D)) { task.RaiseSuccess(task.resource.readableTexture == true ? www.texture : www.textureNonReadable); } else { task.RaiseSuccess(www.bytes); } } else { Debug.LogError(string.Format("Task WebRequest [{0}] error: {1}", www.url, www.error)); task.RaiseFailed(); } www.Dispose(); www = null; } else if (task.resource.loadableResource == true || (string.IsNullOrEmpty(task.customResourcePath) == false && task.resource.loadableAssetBundle == false)) { Object data = null; var resourcePath = task.customResourcePath ?? task.resource.resourcesPath; if (task.async == true) { var asyncTask = Resources.LoadAsync(resourcePath, isBytesOutput == true ? typeof(TextAsset) : typeof(T)); while (asyncTask.isDone == false) { yield return(0); } data = asyncTask.asset; asyncTask = null; } if (task.resource.multiObjects == true && task.resource.objectIndex >= 0) { task.RaiseSuccess(Resources.LoadAll(resourcePath)[task.resource.objectIndex]); } else { if (isBytesOutput == true) { if (data == null) { data = Resources.Load <TextAsset>(resourcePath); } task.RaiseSuccess(((data as TextAsset).bytes)); } else { if (data == null) { data = Resources.Load(resourcePath, typeof(T)); } task.RaiseSuccess(data); } } } else if (task.resource.loadableStream == true) { if (task.resource.IsMovie() == true) { Debug.Log("LoadMovie: " + task.component); task.task = MovieSystem.LoadTexture(task.component as IImageComponent); var startTime = Time.realtimeSinceStartup; var timer = 0f; while (task.task.isDone == false) { timer = Time.realtimeSinceStartup - startTime; if (timer >= 3f) { break; } yield return(0); } if (task.task != null && task.task.isDone == true) { //Debug.Log("Loaded: " + component.GetResource().GetStreamPath() + ", iter: " + iteration + ", type: " + typeof(T).ToString() + ", asset: " + task.asset, graphic); task.RaiseSuccess(task.task.asset); } else { task.RaiseFailed(); } } else { WWW www = null; if (task.resource.cacheVersion > 0) { www = WWW.LoadFromCacheOrDownload(task.resource.GetStreamPath(withFile: true), task.resource.cacheVersion); } else { www = new WWW(task.resource.GetStreamPath(withFile: true)); } while (www.isDone == false) { yield return(0); } if (string.IsNullOrEmpty(www.error) == true) { var type = typeof(T); //Debug.Log("LOADED: " + type.ToString() + " :: " + task.resource.GetStreamPath(withFile: true)); if (type == typeof(Texture) || type == typeof(Texture2D)) { task.RaiseSuccess(task.resource.readableTexture == true ? www.texture : www.textureNonReadable); } else { var data = www.bytes; if (isBytesOutput == true) { task.RaiseSuccess(data); } else { task.RaiseSuccess(null); } } } else { //Debug.Log("NOT LOADED: " + task.resource.GetStreamPath(withFile: true) + " :: " + www.error); task.RaiseFailed(); } www.Dispose(); www = null; } } else if (task.resource.loadableAssetBundle == true) { #if UNITY_IOS if (UnityEngine.iOS.OnDemandResources.enabled == true) { /*var request = UnityEngine.iOS.OnDemandResources.PreloadAsync(new string[] { odrTag } ); * // Wait until request is completed * yield return request; * // Check for errors * if (request.error != null) { * task.RaiseFailed(); * return; * } * var bundle = AssetBundle.CreateFromFile("res://" + resourceName);*/ } #endif var path = task.resource.GetAssetBundlePath(true); WWW www = null; if (task.resource.cacheVersion > 0) { www = WWW.LoadFromCacheOrDownload(path, task.resource.cacheVersion); } else { www = new WWW(path); } while (www.isDone == false) { yield return(0); } if (string.IsNullOrEmpty(www.error) == true && www.assetBundle != null) { var assets = www.assetBundle.LoadAllAssets(); var asset = assets[task.resource.objectIndexAssetBundle]; task.RaiseSuccess(asset); www.assetBundle.Unload(false); } else { task.RaiseFailed(); } www.Dispose(); www = null; } #endregion }
private void LoadAuto_INTERNAL(ILoadableResource resourceController, System.Action onDataLoaded, System.Action onComplete, System.Action onFailed = null, string customResourcePath = null) { var image = resourceController as IImageComponent; var async = image.GetResource().async; System.Action <Object> setup = (data) => { if (data == null) { if (onFailed != null) { onFailed.Invoke(); } WindowSystemLogger.Error(image, string.Format("Error in ResourcesManager: Required resource can't be loaded. Resource: {0}", image.GetResource().GetId())); return; } }; var source = image.GetGraphicSource(); var isMaterial = image.GetResource().IsMaterialLoadingType(); if (isMaterial == false) { MovieSystem.UnregisterOnUpdateTexture(this.ValidateTexture); } if (isMaterial == true) { this.LoadRefCounter_INTERNAL <Material>(resourceController, (data) => { setup.Invoke(data); image.SetMaterial(data, callback: () => { if (onComplete != null) { onComplete.Invoke(); } }); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, onFailed, async, customResourcePath); } else { if (source is Image) { this.LoadRefCounter_INTERNAL <Sprite>(resourceController, (data) => { setup.Invoke(data); image.SetImage(data, () => { if (onComplete != null) { onComplete.Invoke(); } }); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, onFailed, async, customResourcePath); } else if (source is RawImage) { this.LoadRefCounter_INTERNAL <Texture>(resourceController, (data) => { setup.Invoke(data); image.SetImage(data, () => { if (onComplete != null) { onComplete.Invoke(); } }); if (isMaterial == true) { MovieSystem.RegisterOnUpdateTexture(this.ValidateTexture); } if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, onFailed, async, customResourcePath); } } }
private IEnumerator StartTask <T>(TaskItem task) where T : Object { #region Load Resource if (task.resource.loadableResource == true || string.IsNullOrEmpty(task.customResourcePath) == false) { var resourcePath = task.customResourcePath ?? task.resource.resourcesPath; if (task.resource.async == true) { var asyncTask = Resources.LoadAsync <T>(resourcePath); while (asyncTask.isDone == false) { yield return(false); } if (task.resource.multiObjects == true && task.resource.objectIndex >= 0) { task.RaiseSuccess(Resources.LoadAll(resourcePath)[task.resource.objectIndex]); } else { task.RaiseSuccess(asyncTask.asset); } asyncTask = null; } else { if (task.resource.multiObjects == true && task.resource.objectIndex >= 0) { task.RaiseSuccess(Resources.LoadAll(resourcePath)[task.resource.objectIndex]); } else { var asset = Resources.Load <T>(resourcePath); task.RaiseSuccess(asset); } } } else if (task.resource.loadableStream == true) { task.task = MovieSystem.LoadTexture(task.component); var startTime = Time.realtimeSinceStartup; var timer = 0f; while (task.task.isDone == false) { timer = Time.realtimeSinceStartup - startTime; if (timer >= 3f) { break; } yield return(false); } if (task.task != null && task.task.isDone == true) { //Debug.Log("Loaded: " + component.GetResource().GetStreamPath() + ", iter: " + iteration + ", type: " + typeof(T).ToString() + ", asset: " + task.asset, graphic); task.RaiseSuccess(task.task.asset); } else { task.RaiseFailed(); } } #endregion }
private void Unload_INTERNAL(ILoadableResource resourceController, ResourceBase resource, bool resetController = true) { /* * if (resource.loaded == false) { * * * return; * * }*/ //Debug.LogWarning("Unload: " + resource.GetId() + " :: " + resource.GetStreamPath(), resourceController as MonoBehaviour); var item = this.loaded.FirstOrDefault(x => x.id == resource.GetId()); if (WindowSystemResources.Remove(item, resourceController as WindowComponent, forced: true) == true) { //Debug.LogWarning("Unload movie: " + resource.GetId(), resourceController as MonoBehaviour); MovieSystem.Unload(resourceController as IImageComponent, resource); } /*if (item != null) { * * if (item.references.Remove(resourceController as WindowComponent) == true) { * * this.loaded.RemoveAll(x => { * * if (x.id == resource.GetId() && x.references.Count == 0) { * * if (x.loadedObjectId < 0) Object.Destroy(x.loadedObject); * return true; * * } * * return false; * * }); * * } * * }*/ if (resetController == true) { var image = resourceController as IImageComponent; var source = image.GetImageSource(); if (source != null) { image.ResetImage(); resource.Unload(source.sprite); } else { var sourceRaw = image.GetRawImageSource(); if (sourceRaw != null) { image.ResetImage(); resource.Unload(sourceRaw.texture); } } } }