Exemple #1
0
        private void LoaderStateChange(CloudFileLoader obj)
        {
            IMCTaskLoader loader = (IMCTaskLoader)obj.Parms;

            loader.cloudFileLoader = null;
            if (obj.loadState == LoadState.Complete)
            {
                FileSystem.Instance.WriteToFile(loader.path, obj.byteBuffer, obj.byteBuffer.Length);
                Texture2D t2d = new Texture2D(1, 1);
                t2d.LoadImage(obj.byteBuffer);
                obj.byteBuffer = null;
                obj            = null;
                System.GC.Collect();
                SetTexture2DToImageControl(loader, t2d);
            }
            else if (obj.loadState != LoadState.Wait && obj.loadState != LoadState.Loading)
            {
                loader.loadState = LoadState.Error;
                taskQueues.Remove(loader);
                loader.target.LoadComplete(loader);
                loader = null;
                obj    = null;
                System.GC.Collect();
                NextTask();
            }
        }
Exemple #2
0
        public void RemoveTask(string instanceID)
        {
            IMCTaskLoader loader = FindLoaderByInstanceID(instanceID);

            if (loader == null)
            {
                return;
            }
            if (loader.loadState == LoadState.Wait)
            {
                taskQueues.Remove(loader);
                loader.loadState = LoadState.Stop;
                loader.target.LoadComplete(loader);
                loader = null;
            }
            else if (loader.loadState == LoadState.Loading)
            {
                if (loader.cloudFileLoader != null)
                {
                    loader.cloudFileLoader.StopTask();
                    loader.cloudFileLoader = null;
                }
                if (loader.enumerator != null)
                {
                    StopCoroutine(loader.enumerator);
                    loader.enumerator = null;
                }
                taskQueues.Remove(loader);
                loader.loadState = LoadState.Stop;
                loader.target.LoadComplete(loader);
                loader = null;
                NextTask();
            }
        }
Exemple #3
0
        public void LoadImage(string url, string path)
        {
            if (isLoadIng)
            {
                StopLoadImage();
            }

            IMCTaskLoader itl = new IMCTaskLoader();

            if (FileSystem.Instance.FileExists(path) || !FileSystem.Instance.FileExists(path) && url != "")
            {
                isLoadIng       = true;
                m_url           = url;
                m_path          = path;
                itl.controlType = controlType;
                itl.instanceID  = GetInstanceID().ToString();
                itl.target      = this;
                itl.path        = m_path;
                itl.url         = m_url;
                IMCUIManager.Instance.AddTask(itl);
            }
            else
            {
                itl.loadState = LoadState.Error;
                LoadComplete(itl);
            }
        }
Exemple #4
0
 public override void LoadComplete(IMCTaskLoader loader)
 {
     isLoadIng = false;
     if (LoadStateChangeAction != null)
     {
         LoadStateChangeAction(loader.loadState);
     }
     loader = null;
 }
Exemple #5
0
        private void SetTexture2DToImageControl(IMCTaskLoader loader, Texture2D texture)
        {
            loader.loadState = LoadState.Complete;
            IMCUIBehaviour behaviour = loader.target;

            behaviour.SetTexture(texture);
            taskQueues.Remove(loader);
            loader.target.LoadComplete(loader);
            loader = null;
            NextTask();
        }
Exemple #6
0
 private void TaskProcessing(IMCTaskLoader loader)
 {
     loader.loadState = LoadState.Loading;
     if (FileSystem.Instance.FileExists(loader.path))
     {
         loader.enumerator = LoadImageFromLocalEnumerator(loader);
         StartCoroutine(loader.enumerator);
     }
     else
     {
         DownLoadImage(loader);
     }
 }
Exemple #7
0
 public void AddTask(IMCTaskLoader loader)
 {
     if (!DetectionSupportControlType(loader))
     {
         return;
     }
     taskQueues.Add(loader);
     loader.loadState = LoadState.Wait;
     if (GetLoadingTaskCount() < MaxTaskCount)
     {
         TaskProcessing(loader);
     }
 }
Exemple #8
0
        private bool DetectionSupportControlType(IMCTaskLoader loader)
        {
            switch (loader.target.controlType)
            {
            case ControlType.IMCImage:
                return(true);

            case ControlType.IMCRawImage:
                return(true);

            default:
                return(false);
            }
        }
Exemple #9
0
        private IEnumerator LoadImageFromLocalEnumerator(IMCTaskLoader loader)
        {
            var url =
#if UNITY_IOS
                "file://" + loader.path;
#else
                "file:///" + loader.path;
#endif
            WWW www = new WWW(url);
            yield return(www);

            if (www.texture != null)
            {
                SetTexture2DToImageControl(loader, www.texture);
                Resources.UnloadUnusedAssets();
                //System.GC.Collect();
                www.Dispose();
                www = null;
            }
            yield return(0);
        }
Exemple #10
0
        public void LoadImage(string path)
        {
            if (isLoadIng)
            {
                StopLoadImage();
            }
            IMCTaskLoader itl = new IMCTaskLoader();

            if (FileSystem.Instance.FileExists(path))
            {
                isLoadIng      = true;
                m_path         = path;
                m_url          = "";
                itl.instanceID = GetInstanceID().ToString();
                itl.target     = this;
                IMCUIManager.Instance.AddTask(itl);
            }
            else
            {
                itl.loadState = LoadState.Error;
                LoadComplete(itl);
            }
        }
Exemple #11
0
 public virtual void LoadComplete(IMCTaskLoader loader)
 {
 }
Exemple #12
0
 private void DownLoadImage(IMCTaskLoader loader)
 {
     loader.cloudFileLoader = CloudFileSystem.Instance.CreateHttpDownLoadByLoadType(loader.url, loader.path, LoadType.DownLoadMemory, loader.instanceID, loader);
     loader.cloudFileLoader.LoaderStateChange += LoaderStateChange;
 }