/*private void ___() { * * 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) { * * if (ResourceBase.iterations.TryGetValue(graphic, out iteration) == false) { * * ResourceBase.iterations.Add(graphic, iteration); * * } * ++ResourceBase.iterations[graphic]; * iteration = ResourceBase.iterations[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) { * * if (this.task != null) { * * //Debug.LogWarning("Resource start loading while old was not complete"); * * } * * this.task = MovieSystem.LoadTexture(component); * while (this.task != null && this.task.isDone == false) { * * iterationFailed = !(graphic == null || iteration == ResourceBase.iterations[graphic]); * if (iterationFailed == true && this.task != null) { * * //Debug.Log("Break: " + this.GetStreamPath()); * * this.task.Break(); * this.task.Dispose(); * this.task = null; * callback.Invoke(null); * yield break; * * } * * yield return false; * * } * * if (this.task != null) { * * iterationFailed = !(graphic == null || iteration == ResourceBase.iterations[graphic]); * if (iterationFailed == false) { * * //Debug.Log("Loaded: " + component.GetResource().GetStreamPath() + ", iter: " + iteration + ", type: " + typeof(T).ToString() + ", asset: " + task.asset, graphic); * * callback.Invoke(this.task.asset as T); * * } else { * * callback.Invoke(null); * * } * * this.task.Dispose(); * this.task = null; * * } * * } #endregion * * }*/ #if UNITY_EDITOR public static void Validate(ILoadableResource resourceController) { if (Application.isPlaying == true) { return; } var mapInstance = WindowSystemResourcesMap.FindFirst(); if (mapInstance == null) { return; } if (resourceController.GetResource().controlType != AutoResourceItem.ControlType.None) { var image = resourceController as IImageComponent; mapInstance.Register(image); var source = image.GetImageSource(); if (source != null) { resourceController.GetResource().Validate(source.sprite); image.ResetImage(); //image.SetImage(resourceController.GetResource().tempSprite); } else { var sourceRaw = image.GetRawImageSource(); if (sourceRaw != null) { resourceController.GetResource().Validate(sourceRaw.texture); image.ResetImage(); } } resourceController.GetResource().Validate(resourceController.GetResource().tempObject); } else { if (resourceController.GetResource().loadableResource == true) { var image = resourceController as IImageComponent; mapInstance.Unregister(image); image.SetImage(resourceController.GetResource().tempObject as Sprite); image.SetImage(resourceController.GetResource().tempObject as Texture); resourceController.GetResource().Reset(); } } }
private void LoadAuto_INTERNAL(ILoadableResource resourceController, System.Action onDataLoaded, System.Action onComplete, string customResourcePath = null) { var image = resourceController as IImageComponent; System.Action <Object> setup = (data) => { if (data == null) { WindowSystemLogger.Error(image, string.Format("Error in ResourcesManager: Required resource can't be loaded. Resource: {0}", image.GetResource().GetId())); return; } var res = resourceController.GetResource(); res.loadedObject = data; res.loadedObjectId = data.GetInstanceID(); res.loaded = true; }; Graphic source = image.GetImageSource(); if (source != null) { this.LoadAndSetup_INTERNAL <Sprite>(image, source, (data) => { setup.Invoke(data); image.SetImage(data, () => { if (onComplete != null) { onComplete.Invoke(); } }); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, customResourcePath); } else { source = image.GetRawImageSource(); if (source != null) { this.LoadAndSetup_INTERNAL <Texture>(image, source, (data) => { setup.Invoke(data); image.SetImage(data, () => { if (onComplete != null) { onComplete.Invoke(); } }); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, customResourcePath); } } }
public static void LoadAuto(ILoadableResource resourceController, System.Action onDataLoaded, System.Action onComplete, bool onShowHide) { var type = resourceController.GetResource().controlType; if (onShowHide == true && (type & AutoResourceItem.ControlType.Show) != 0) { WindowSystemResources.instance.LoadAuto_INTERNAL(resourceController, onDataLoaded, onComplete); } else if (onShowHide == false && (type & AutoResourceItem.ControlType.Init) != 0) { WindowSystemResources.instance.LoadAuto_INTERNAL(resourceController, onDataLoaded, onComplete); } }
public static void UnloadAuto(ILoadableResource resourceController, bool onShowHide) { var type = (resourceController.GetResource() as ResourceAuto).controlType; if (onShowHide == true && (type & ResourceAuto.ControlType.Hide) != 0) { WindowSystemResources.instance.Unload_INTERNAL(resourceController as IResourceReference, resourceController.GetResource()); } else if (onShowHide == false && (type & ResourceAuto.ControlType.Deinit) != 0) { WindowSystemResources.instance.Unload_INTERNAL(resourceController as IResourceReference, resourceController.GetResource()); } }
public void Register(ILoadableResource component) { this.CleanUp(); if (component == null) return; if (this.items.Any(x => x.component == component) == false) { this.items.Add(new Item() { component = component as WindowComponent, texture = component.GetResource().tempObject }); } }
private void LoadRefCounter_INTERNAL <T>(ILoadableResource image, System.Action <T> callbackOnLoad, System.Action callbackOnFailed, bool async, string customResourcePath) /*where T : Object*/ { IResourceReference reference = null; if (image is ILoadableReference) { reference = (image as ILoadableReference).GetReference(); } else { reference = image as IResourceReference; } var resource = image.GetResource(); this.LoadRefCounter_INTERNAL(reference, resource, callbackOnLoad, callbackOnFailed, async, customResourcePath); }
public void Register(ILoadableResource component) { this.CleanUp(); if (component == null) { return; } if (this.items.Any(x => x.component == component) == false) { this.items.Add(new Item() { component = component as WindowComponent, texture = component.GetResource().tempObject }); } }
private void LoadAuto_INTERNAL(ILoadableResource resourceController, System.Action onDataLoaded, System.Action onComplete, System.Action onFailed = null, string customResourcePath = null) { var image = resourceController as IImageComponent; 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 res = resourceController.GetResource(); res.loadedObject = data; res.loadedObjectId = data.GetID(); res.loaded = true; }; Graphic source = image.GetImageSource(); if (source == null) { source = image.GetRawImageSource(); } var isMaterial = image.GetResource().IsMaterialLoadingType(); if (isMaterial == true) { } else { MovieSystem.UnregisterOnUpdateTexture(this.ValidateTexture); } if (isMaterial == true) { this.LoadAndSetup_INTERNAL <Material>(image, source, (data) => { setup.Invoke(data); image.SetMaterial(data, callback: () => { if (onComplete != null) { onComplete.Invoke(); } }); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, onFailed, customResourcePath); } else { if (source is Image) { this.LoadAndSetup_INTERNAL <Sprite>(image, source, (data) => { setup.Invoke(data); image.SetImage(data, () => { if (onComplete != null) { onComplete.Invoke(); } }); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, onFailed, customResourcePath); } else if (source is RawImage) { this.LoadAndSetup_INTERNAL <Texture>(image, source, (data) => { setup.Invoke(data); image.SetImage(data, () => { if (onComplete != null) { onComplete.Invoke(); } }); MovieSystem.RegisterOnUpdateTexture(this.ValidateTexture); if (onDataLoaded != null) { onDataLoaded.Invoke(); } }, onFailed, customResourcePath); } } }