Exemplo n.º 1
0
        /// <summary>
        /// Cancels all asynchronous calls made with the given userState.
        /// If userState is null, all asynchronous calls are cancelled.
        /// </summary>
        /// <param name="userState">Unique identifier for the asynchronous task.</param>
        public override void CancelAsync(object userState)
        {
            if (userState == null)
            {
                CancelAllAsyncOperations();
            }
            else
            {
                for (int index = 0; index < _asyncRequests.Count; index++)
                {
                    AsyncRequest asyncRequest = _asyncRequests[index];

                    if (asyncRequest.UserState == userState)
                    {
                        asyncRequest.Cancel();
                        _asyncRequests.RemoveAt(index);
                        index--;
                    }
                }
            }
        }
        private void DrawAudioArea()
        {
            //Remove request if completed
            if (request != null && request.status == AsyncRequest.Status.Completed)
            {
                request = null;
            }

            //Draw pending message or dowload progress bar
            if (request != null && !request.isDone)
            {
                if (request.status != AsyncRequest.Status.Downloading)
                {
                    GUILayout.Space(4);
                    Utils.DrawPendingLabel("Pending...");
                    GUILayout.Space(-10);
                    Utils.DrawSeparator();
                    GUILayout.Space(-5);
                }
                else
                {
                    GUILayout.Space(10);
                    Rect  rect     = GUILayoutUtility.GetRect(Screen.width, 30);
                    float progress = request.downloadProgress;
                    EditorGUI.ProgressBar(rect, progress, "Download : " + Mathf.RoundToInt(progress * 100) + "%");
                }
            }

            //Draw Audio preview
            else if (clip.clip != null)
            {
                DrawAudioPlayer();
            }

            //Draw commands
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (request != null)
            {
                if (GUILayout.Button("Cancel"))
                {
                    AsyncRequest.Cancel(clip.uuid);
                    request = null;
                }
                if (GUILayout.Button("Show pending list"))
                {
                    Resemble_Window.Open(Resemble_Window.Tab.Pool);
                }
                if (clip.clip != null && GUILayout.Button("Select placeholder"))
                {
                    EditorGUIUtility.PingObject(clip.clip);
                    Selection.activeObject = clip.clip;
                }
            }
            else if (clip.clip != null)
            {
                if (GUILayout.Button("Select file"))
                {
                    EditorGUIUtility.PingObject(clip.clip);
                    Selection.activeObject = clip.clip;
                }
            }
            GUILayout.EndHorizontal();
        }