internal DesignDataAgentMethodManager(DesignDataAgent designDataAgent)
        {
            this.designDataAgent = designDataAgent;

            parseMethodQuery = new Dictionary <string, Func <DesignDataAgent.CellInfo, CommandParam, DesignDataAgent.CommandExecuteResult> >();
            paramFuncQuery   = new Dictionary <string, Func <string[], string> >();
        }
        public void Import(DesignDataAgent designDataAgent, DesignDataAgentMethodManager designDataAgentMethodManager)
        {
            this.designDataAgent = designDataAgent;

            //Register method by this way.
            designDataAgentMethodManager.RegisterMethod(DesignDataAgentMethodManager.GetParseMethod(this));

            //Register param function by this way.
            designDataAgentMethodManager.RegisterParamFunc(DesignDataAgentMethodManager.GetParamMethod(this));
        }
Beispiel #3
0
        public void Import(DesignDataAgent designDataAgent, DesignDataAgentMethodManager designDataAgentMethodManager)
        {
            this.designDataAgent = designDataAgent;

            designDataAgentMethodManager.RegisterMethod(new Dictionary <string, Func <DesignDataAgent.CellInfo, CommandParam, DesignDataAgent.CommandExecuteResult> >
            {
                //DO

                ["int"]     = SetInt,
                ["float"]   = SetFloat,
                ["bool"]    = SetBool,
                ["string"]  = SetString,
                ["object"]  = SetObject,
                ["Vector2"] = SetVector2,
                ["Sprite"]  = SetSprite,
                ["enum"]    = SetEnumByName,

                ["Method"]    = Method,
                ["ForMethod"] = ForMethod,

                ["CreateAsset"] = CreateAsset,
                ["SaveAssets"]  = SaveAssets,
                ["Reset"]       = ResetPropertyValue,
                ["ClearArray"]  = ClearArray,
                ["Print"]       = PrintText,
                ["Invoke"]      = InvokeFunction,
                ["SetRoot"]     = SetRoot,

                //IF

                ["NotEmpty"]         = NotEmpty,
                ["IsEmpty"]          = IsEmpty,
                ["IsEmptyString"]    = IsEmptyString,
                ["IsNotEmptyString"] = IsNotEmptyString,
                ["IsFirst"]          = IsFirst,
                ["IsLast"]           = IsLast,
                ["IsExist"]          = IsExist,
                ["IsNotExist"]       = IsNotExist,
                ["IsTrue"]           = IsTrue,
                ["IsFalse"]          = IsFalse,
                ["IsEqual"]          = IsEqual,
                ["IsNotEqual"]       = IsNotEqual,
            },
                                                        logRegister: false);

            designDataAgentMethodManager.RegisterParamFunc(new Dictionary <string, Func <string[], string> >
            {
                ["Calc"]         = Calc,
                ["GetCellValue"] = GetCellValue,
                ["ToInt"]        = ToInt,
            },
                                                           logRegister: false);
        }
        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);
        }