Exemple #1
0
        private void CreateScriptableObject()
        {
            var directory = Path.Combine(Application.dataPath, m_scriptPath);
            var file      = directory + m_name + ".cs";

            if (File.Exists(file))
            {
                Debug.Log("ScriptObject already exists!");
                CreateAsset();
                return;
            }

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var assetPath    = m_assetPath.Replace("Resources/", string.Empty) + m_name;
            var replacements = new Dictionary <string, string>()
            {
                { "$ClassName", m_name },
                { "$AssetPath", assetPath },
            };
            var fileString = ScriptWizard.Create(m_templateName, replacements);

            File.WriteAllText(file, fileString, Encoding.UTF8);

            AssetDatabase.Refresh();
            m_isNeedCreate = true;

            Debug.Log("Create ScriptObject: " + m_name);
            Debug.Log("Wait for compiling...");
        }
        private static void CreateEnumFile(string folder)
        {
            var enumName  = folder.Split('/').Last();
            var className = enumName + "Class";

            var enums = string.Empty;
            var files = GetFiles(folder);

            foreach (var file in files)
            {
                var fileName = file.Split('/').Last();
                fileName = fileName.Split('.').First();
                enums   += fileName + ",\n\t";
            }

            var replacements = new Dictionary <string, string>()
            {
                { "$EnumName", enumName },
                { "$Enums", enums },
            };
            var fileString = ScriptWizard.Create(m_templateName, replacements);

            if (!Directory.Exists(m_root))
            {
                Directory.CreateDirectory(m_root);
            }

            File.WriteAllText(m_root + "/" + className + ".cs", fileString, Encoding.UTF8);
            AssetDatabase.Refresh();
        }