public static void GenerateCodeFile(MenuCommand menuCommand)
        {
            m_CodeReplaceDict.Clear();
            m_SCEventSubStrs   = "";
            m_SCEventUnsubStrs = "";
            m_SCCallbackStrs   = "";
            m_CSRequsetStrs    = "";
            m_NowComment       = "";
            m_Name             = "";

            //UnityEngine.GameObject txt2 = menuCommand.context as UnityEngine.GameObject;

            UnityEngine.Object txt = Selection.activeObject;

            string selectionPath = AssetDatabase.GetAssetPath(txt);
            string directory     = Path.GetDirectoryName(selectionPath);
            string fileName      = Path.GetFileNameWithoutExtension(selectionPath);

            m_Name = fileName;

            GenerateCode(selectionPath);
            AddCodeReplace();

            string outputDirectory = Defitions.ScriptGenerator.DirectoryPrefix + "ProtoInterfaceGenerator/Generation";
            string outputFile      = outputDirectory + "/" + fileName + "NetworkRequest.txt";

            //string outputFile = directory + "/" + fileName + "NetworkRequest.txt";

            TemplateScriptGenerator.GenerateScriptFile(m_CodeTemplateFile, outputFile, m_CodeReplaceDict, Encoding.UTF8);

            AssetDatabase.ImportAsset(outputFile);
            AssetDatabase.Refresh();

            Debug.Log("生成完成");
        }
Beispiel #2
0
        public static void GenerateConfigAssets(string configAssetPath, string configPath, List <string> specifiedPathList)
        {
            List <string> paths = DynamicAssetGenerator.GeneratePaths(specifiedPathList, ".png");
            Dictionary <string, Sprite> assets = DynamicAssetGenerator.GenerateAssets <Sprite>(paths);

            List <DynamicAssetConfig> dynamicAssetConfigs = LoadDynamicAssetConfig(configPath);

            Dictionary <string, Sprite> configAssets = new Dictionary <string, Sprite>(dynamicAssetConfigs.Count);

            string variableDefinitioStr = "";

            foreach (DynamicAssetConfig config in dynamicAssetConfigs)
            {
                if (assets.ContainsKey(config.Resource))
                {
                    configAssets.Add(config.Resource, assets[config.Resource]);

                    if (config.Variable != "Null")
                    {
                        variableDefinitioStr += GetDefintionCode(config.Variable, config.Comment, config.Index);
                    }
                }
            }

            GenerateSpriteAssetFile(configAssetPath, configAssets);


            Dictionary <string, string> replaceStrDict = new Dictionary <string, string>
            {
                ["__Variable_Definition__"] = variableDefinitioStr,
            };

            TemplateScriptGenerator.GenerateScriptFile(Defitions.DynamicAssets.DefintionTemplateFile, Defitions.DynamicAssets.DynamicAssetDefintionFile, replaceStrDict, Encoding.UTF8);
        }
Beispiel #3
0
            public static Dictionary <string, string> GenerateToggleListnerCode(string className, string variableName)
            {
                List <CodeBlock> codeBlocks = new List <CodeBlock>()
                {
                    new CodeBlock()
                    {
                        BlockName           = s_BlockListener,
                        CodeReplacementDict = new Dictionary <string, string>()
                        {
                            [s_ReplaceClass]    = className,
                            [s_ReplaceVariable] = variableName,
                        }
                    },

                    new CodeBlock()
                    {
                        BlockName           = s_BlockCallback,
                        CodeReplacementDict = new Dictionary <string, string>()
                        {
                            [s_ReplaceVariable] = variableName,
                        }
                    }
                };

                return(TemplateScriptGenerator.GenerateCodeBlockDict(Defitions.VariableGenerator.VariableCodeFile, codeBlocks));
            }
Beispiel #4
0
        private static void CreateScript(string templateFile, string outputFile)
        {
            UnityEngine.Object activeObject = Selection.activeObject;
            string             directory    = AssetDatabase.GetAssetPath(activeObject);

            Dictionary <string, string> codeReplaceDict = new Dictionary <string, string>()
            {
                ["__Name__"]            = "NewCodeBlockTemplate",
                ["__Test_Code_Block__"] = GetCodeBlockTest(10)
            };

            TemplateScriptGenerator.GenerateScriptFile(templateFile, directory + "/" + outputFile, codeReplaceDict, Encoding.UTF8);
        }
        private static void GenerateUIFormScript()
        {
            string outputDirectory = Defitions.VariableGenerator.UIFormDirectory + m_ClassName + "/";

            string uiformPath = outputDirectory + m_ClassName + ".cs";

            Dictionary <string, string> CodeReplacement = new Dictionary <string, string>()
            {
                ["__Name__"] = m_ClassName,
                ["__Variable_ButtonCallback__"] = m_ClickCallbacks
            };

            TemplateScriptGenerator.GenerateScriptFile(Defitions.VariableGenerator.UIFormTemplateFile, uiformPath, CodeReplacement, Encoding.UTF8);
        }
        private static void GenerateCode(string selectionPath)
        {
            List <string> rowStr = TemplateScriptGenerator.ReadTxtFileByRow(selectionPath);

            foreach (string str in rowStr)
            {
                if (new Regex(m_NameCommentRegex).IsMatch(str))
                {
                    Match commnetMatch = new Regex(m_NameCommentRegex).Match(str);

                    m_NameCommnet = commnetMatch.Groups["comment"].Value;
                }

                if (new Regex(m_CommentRegex).IsMatch(str))
                {
                    Match commnetMatch = new Regex(m_CommentRegex).Match(str);

                    m_NowComment = commnetMatch.Groups["comment"].Value;
                }


                if (new Regex(m_SCInterfaceRegex).IsMatch(str))
                {
                    Match nameMatch = new Regex(m_SCInterfaceRegex).Match(str);

                    string name  = nameMatch.Groups["interfaceName"].Value;
                    string index = nameMatch.Groups["interfaceIndex"].Value;

                    m_SCEventSubStrs   += string.Format(m_SCEventSubFormat, name, name);
                    m_SCEventUnsubStrs += string.Format(m_SCEventUnsubFormat, name, name);
                    m_SCCallbackStrs   += string.Format(m_SCEventCallbackFormat, m_NowComment, name, name, name, name, name);
                }

                if (new Regex(m_CSInterfaceRegex).IsMatch(str))
                {
                    Match nameMatch = new Regex(m_CSInterfaceRegex).Match(str);

                    string name  = nameMatch.Groups["interfaceName"].Value;
                    string index = nameMatch.Groups["interfaceIndex"].Value;

                    m_CSRequsetStrs += string.Format(m_CSRequsetFormat, m_NowComment, name, name, name, name, name);
                }
            }
        }
Beispiel #7
0
 private static string GetVariableCode(List <CodeBlock> codeBlocks)
 {
     return(TemplateScriptGenerator.GenerateCodeBlock(Defitions.ScriptGenerator.SampleFolder + "/CodeBlock.txt", codeBlocks, Encoding.UTF8));
 }
Beispiel #8
0
 private static string GetCodeBlock(List <CodeBlock> codeBlocks)
 {
     return(TemplateScriptGenerator.GenerateCodeBlock(Defitions.DynamicAssets.DefintionCodeBlockTemplateFile, codeBlocks, Encoding.UTF8));
 }
 private static string GenerateVariableCode(List <CodeBlock> codeBlocks)
 {
     return(TemplateScriptGenerator.GenerateCodeBlock(Defitions.VariableGenerator.VariableCodeFile, codeBlocks, Encoding.UTF8));
 }
Beispiel #10
0
        private static void GenerateUIFormVariableScript()
        {
            string outputFile = Defitions.VariableGenerator.VariableDirectory + m_ClassName + ".Variable.cs";

            TemplateScriptGenerator.GenerateScriptFile(Defitions.VariableGenerator.CodeTemplateFile, outputFile, m_CodeReplaceDict, m_Encoding);
        }