Example #1
0
        static void OnPostprocessAllAssets(
            string[] importedAssets,
            string[] deletedAssets,
            string[] movedAssets,
            string[] movedFromAssetPaths)
        {
            if (importedAssets.Length > 20)
            {
                Debug.LogWarning("Lots of assets imported at once. Skipping state-machine code generator.");
                File.WriteAllText("Temp/importedScripts.txt", string.Empty);
                return;
            }

            List <string> importedScripts = new List <string>();

            foreach (var path in importedAssets)
            {
                var importer = AssetImporter.GetAtPath(path) as MonoImporter;
                if (importer)
                {
                    if (importer.userData == StateCodeGenerator.GeneratorUserData)
                    {
                        string generatedAssetPath = StateCodeGenerator.GetGeneratedScriptPath(importer);
                        if (!string.IsNullOrEmpty(generatedAssetPath))
                        {
                            Debug.Log(string.Format("Clearing statemachine code for {0}", path));
                            File.WriteAllText(generatedAssetPath, string.Empty);
                        }
                    }
                    importedScripts.Add(path);
                }
            }

            if (importedScripts.Count > 0)
            {
                string importedScriptsText = string.Join(",", importedScripts.ToArray()) + ",";
                File.AppendAllText("Temp/importedScripts.txt", importedScriptsText);
            }
        }
Example #2
0
        public static void GenerateScripts()
        {
            List <string> generatedFiles = new List <string>();

            if (!File.Exists("Temp/importedScripts.txt"))
            {
                return;
            }

            string importedScriptsText = File.ReadAllText("Temp/importedScripts.txt");

            string[] importedScripts = importedScriptsText.Split(',');

            var uniquePaths = importedScripts.Distinct();

            foreach (var path in uniquePaths)
            {
                var importer = AssetImporter.GetAtPath(path) as MonoImporter;
                if (importer)
                {
                    string generatedFilePath;
                    bool   generated = StateCodeGenerator.GenerateCode(path, out generatedFilePath);
                    if (generated)
                    {
                        generatedFiles.Add(generatedFilePath);
                    }
                }
            }

            File.WriteAllText("Temp/importedScripts.txt", string.Empty);

            if (generatedFiles.Count > 0)
            {
                Debug.Log(generatedFiles.Aggregate("Generated: ", (current, next) => string.Format("{0}\n{1}", current, next)));
                AssetDatabase.Refresh();
            }
        }