diff --git a/src/BetterSceneLoader.Core/ImageGrid.cs b/src/BetterSceneLoader.Core/ImageGrid.cs index a2a8f00..cfd8cbe 100644 --- a/src/BetterSceneLoader.Core/ImageGrid.cs +++ b/src/BetterSceneLoader.Core/ImageGrid.cs @@ -175,7 +175,7 @@ public void CreateUI(string name, int sortingOrder, string titleText) loadingIcon.transform.SetRect(0.1f, 0.1f, 0.9f, 0.9f); var loadiconTex = PngAssist.ChangeTextureFromByte(Resource.GetResourceAsBytes(typeof(ImageGrid).Assembly, "Resources.loadicon")); loadingIcon.sprite = Sprite.Create(loadiconTex, new Rect(0, 0, loadiconTex.width, loadiconTex.height), new Vector2(0.5f, 0.5f)); - LoadingIcon.Init(loadingIcon, -5f); + LoadingIcon.Init(loadingPanel.gameObject, loadingIcon, -5f); imagelist = UIUtility.CreateScrollView("Imagelist", mainPanel.transform); imagelist.transform.SetRect(0f, 0f, 1f, 1f, marginSize, marginSize, -marginSize, -headerSize - marginSize / 2f); @@ -306,11 +306,10 @@ private void PopulateGrid(bool forceUpdate = false) private IEnumerator LoadButtonsAsync(Transform parent, List> scenefiles) { + LoadingIcon.loadingCount++; foreach(var scene in scenefiles) { - LoadingIcon.loadingState[currentCategoryFolder] = true; var uri = "file:///" + EncodePath(scene.Value); - #if KKS using(var uwr = UnityWebRequestTexture.GetTexture(uri, true)) { @@ -334,8 +333,7 @@ private IEnumerator LoadButtonsAsync(Transform parent, List(); - rotator.image = image; - rotator.speed = speed; + var icon = parent.AddComponent(); + icon.image = image; + icon.speed = speed; } - public static readonly Dictionary loadingState = new Dictionary(); - private bool rotate; - private bool prevState; + public static int loadingCount = 0; private Image image; private float speed; - private void Start() - { - image.enabled = false; - StartCoroutine(LoadingIndicator()); - } - - private IEnumerator LoadingIndicator() - { - while(true) - { - bool state = loadingState.Values.Contains(true); - if(state != prevState) - { - prevState = state; - rotate = state; - - if(state) - { - rotate = true; - image.enabled = true; - } - else - { - rotate = false; - image.enabled = false; - } - } - - yield return new WaitForSeconds(0.1f); - } - } - private void Update() { - if(rotate) + if(loadingCount > 0) { + if(!image.enabled) image.enabled = true; image.rectTransform.rotation *= Quaternion.Euler(0f, 0f, speed); } + else + { + if(image.enabled) image.enabled = false; + } } } }