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));
        }
示例#2
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);
        }
示例#3
0
        public DesignDataAgent(Table table)
        {
            targetTable   = table;
            methodManager = new DesignDataAgentMethodManager(this);

            //匯入基礎Method
            ImportBasicMethod();

            //匯入擴充Method
            ImportExtensionMethod();


            void ImportBasicMethod()
            {
                new DesignDataAgentBasicMethods().Import(this, methodManager);
            }

            void ImportExtensionMethod()
            {
                const string key         = "import";
                JsonData     tableDefine = targetTable.tableDefine;

                if (tableDefine.Keys.Contains(key) == false)
                {
                    return;
                }

                List <string> importKitNames = null;

                if (targetTable.tableVersion >= 1)
                {
                    importKitNames = new List <string>();
                    for (int i = 0; i < tableDefine[key].Count; i++)
                    {
                        importKitNames.Add((string)tableDefine[key][i]);
                    }
                }
                else if (targetTable.tableVersion >= 0)
                {
                    importKitNames = new List <string>(((string)tableDefine[key]).Split(';'));
                }

                if (importKitNames != null && importKitNames.Count > 0)
                {
                    Debug.Log("============ Extensions ============");
                }

                foreach (var el in importKitNames)
                {
                    Type type = Type.GetType(el.Trim());
                    if (type != null)
                    {
                        Assembly assembly = type.Assembly;
                        var      target   = assembly.CreateInstance(el);

                        if (target is IDesignDataAgentMethods methods)
                        {
                            Debug.Log($"Import {methods}");
                            methods.Import(this, methodManager);
                        }
                        else
                        {
                            throw new Exception("Import 的 target 非 IDesignDataAgentMethods");
                        }
                    }
                    else
                    {
                        throw new Exception($"找不到 Import 的項目 {el.Trim()}");
                    }
                }
            }
        }