コード例 #1
0
        VisualElement GetTableMissionItemVE(TableMissionItem data)
        {
            VisualElement ve = new VisualElement();

            ve.AddToClassList("progressItem");

            Label label = new Label("-");

            label.AddToClassList("label");

            ProgressBar progressBar = new ProgressBar()
            {
                title = "0%"
            };

            progressBar.AddToClassList("progress");

            var           p     = progressBar.Q(className: "unity-progress-bar__progress");
            VisualElement barVe = new VisualElement();

            barVe.AddToClassList("progressBar");
            p.Add(barVe);

            Button btn = new Button(() => RemoveMission(data))
            {
                text = "-"
            };

            btn.AddToClassList("btn");

            data.label     = label;
            data.bar       = progressBar;
            data.container = ve;

            ve.Add(label);
            ve.Add(progressBar);
            ve.Add(btn);

            return(ve);

            void RemoveMission(TableMissionItem d)
            {
                missionList.Remove(d);
                FreshMissionList();
            }
        }
コード例 #2
0
        void UpdateTableMissionItem(TableMissionItem item)
        {
            item.bar.value = item.progress * 100F;

            item.bar.title = item.progress.ToString("##0.0%");

            if (item.GroupCount <= 1)
            {
                item.label.text = item.title;
            }
            else
            {
                item.label.text = $"{item.title} ({item.currentGroupIndex + 1}/{item.GroupCount})";
            }

            item.bar.style.opacity = new StyleFloat(IsDone() == false ? 1F : 0.5F);

            bool IsDone()
            {
                return(item.currentGroupIndex == item.GroupCount - 1 && item.progress >= 1F);
            }
        }
コード例 #3
0
        IEnumerator UpdateIEnumerator()
        {
            isStop = false;
            SetIndex(0);
            isExecuting = true;

            missionList = missionList.Where(item => item.progress < 1F).ToList();
            FreshMissionList();

            yield return(null);

            Debug.Log("============== Table ==============");

            //

            while (currentMissionIndex < missionList.Count)
            {
                double t = EditorApplication.timeSinceStartup;

                TableMissionItem currentMissionItem = missionList[currentMissionIndex];

                PinFile(currentMissionItem.path);

                //建Table
                DesignDataAgent designDataAgent = null;


                List <Table> tables;
                using (StreamReader sr = new StreamReader(currentMissionItem.path))
                {
                    tables = Table.CreateTables(sr, Table.ParseType.tsv);
                }

                for (int i = 0; i < tables.Count; i++)
                {
                    bool result = true;

                    currentMissionItem.currentGroupIndex = i;
                    currentMissionItem.GroupCount        = tables.Count;
                    currentMissionItem.progress          = 0F;

                    Table table = tables[i];

                    if (tables.Count > 1 && i < tables.Count)
                    {
                        Debug.Log($"============ Group ({i + 1}/{tables.Count}) ============");
                    }

                    designDataAgent = new DesignDataAgent(table);

                    if (table.tableVersion == DesignDataAgent.lastestVersion)
                    {
                        //最新版本
                    }
                    else if (table.tableVersion >= DesignDataAgent.minSupportVersion)
                    {
                        EditorUtility.DisplayDialog("表格版本過舊", $"表格 {table.GetDefineValue("title")} 版本過舊,\n將嘗試進行相容性執行。\n\n請盡速將此表格升級版本。", "OK");
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("表格版本無法執行", $"表格 {table.GetDefineValue("title")} 版本過舊,\n且無法進行相容性執行。\n\n請盡速將此表格升級版本。", "OK");
                        isExecuting = false;
                        //SystemSounds.Exclamation.Play();
                        Debug.Log("=============== End ===============");
                        Debug.LogError("表格版本過舊無法執行");
                        yield break;
                    }


                    currentExecuteIEnumerator = designDataAgent.Execute();

                    btnBreakProgress.style.display = new StyleEnum <DisplayStyle>(DisplayStyle.Flex);
                    btnExecute.style.display       = new StyleEnum <DisplayStyle>(DisplayStyle.None);

                    double tStart = EditorApplication.timeSinceStartup;
                    while (result == true)
                    {
                        if (isStop == true)
                        {
                            yield break;
                        }

                        currentMissionItem.progress = designDataAgent.executeProgress;

                        UpdateTableMissionItem(currentMissionItem);

#if (TABLE_PARSE_DEBUG)
                        result = currentExecuteIEnumerator.MoveNext();
#else
                        try
                        {
                            result = currentExecuteIEnumerator.MoveNext();
                        }
                        catch (System.Exception e)
                        {
                            //失敗時直接結束
                            result = false;
                            throw e;
                        }
#endif
                        //如果操作間隔 > 1frame最長時間,則跳下一個
                        if (EditorApplication.timeSinceStartup - tStart > frameWaitingTimeMax)
                        {
                            tStart = EditorApplication.timeSinceStartup;
                            yield return(null);
                        }
                    }
                }

                SetIndex(currentMissionIndex + 1);

                Debug.Log($"Spent {EditorApplication.timeSinceStartup - t:#.0}s");
            }

            isExecuting = false;

            //

            if (IsAllMissionExecuteFinished() == true)
            {
                Debug.Log("=============== End ===============");
                //SystemSounds.Beep.Play();
            }
            else
            {
                Debug.LogError("Error");
                //SystemSounds.Exclamation.Play();
            }

            UnbindUpdate();

            SetActive(btnBreakProgress, false);
            SetActive(btnExecute, true);
        }