예제 #1
0
        /// <summary>
        /// シーン内のスクリプト作成を行う
        /// </summary>
        public static IEnumerable <MonoScriptData> BuildScripts(string folderPath, string folderName, ScriptDependency dependency)
        {
            var datas = dependency.DataList
                        .SelectMany(data => data.ComponentDataList);

            var classNameList = new List <string>();

            foreach (var data in datas)
            {
                NamePostprocessor.Initialize(folderName); // 設定

                var className = data.RawComponentName;
                className = NamePostprocessor.Rename(className); // リネーム
                className = NameCorrector.CorrectNameIfInvalid(className);

                if (classNameList.Contains(className))
                {
                    Debug.LogErrorFormat("クラス名重複 : className = {0}", className);
                    continue;
                }
                classNameList.Add(className);

                var templateName = data.TemplateName;
                var scriptName   = string.Format("{0}.cs", className);
                var script       = CreateScriptAsset(folderPath, folderName, scriptName, templateName);

                yield return(new MonoScriptData
                {
                    Script = script,
                    RawComponentName = data.RawComponentName
                });
            }
        }
예제 #2
0
        /// <summary>
        /// 複数シーン作成ダイアログ表示
        /// </summary>
        public static void DisplayBuildDialogMulti(string[] sceneNames)
        {
            // スクリプトの依存関係取得
            var scriptDependency = DataLoader.LoadScriptDependency();

            // ダイアログを開く
            var    fullpath = EditorUtility.SaveFolderPanel("シーン作成先のフォルダ選択", "Assets", "");
            string path     = "Assets" + fullpath.Substring(Application.dataPath.Length);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var corrctedSceneNames = sceneNames.Select(name => NameCorrector.CorrectNameIfInvalid(name)).ToArray();

            if (corrctedSceneNames.Length == 0)
            {
                return;
            }


            // 作成
            var   dataList      = new List <TemporaryFileData.Data>();
            float progressDelta = 1f / sceneNames.Length;
            float progress      = 0f;

            foreach (var sceneName in corrctedSceneNames)
            {
                // プログレスバー
                progress += progressDelta;
                EditorUtility.DisplayProgressBar(string.Format("シーン\"{0}\"の作成中...", sceneName), "", progress);

                if (string.IsNullOrEmpty(sceneName))
                {
                    continue;
                }
                // if (AssetChecker.Exists(Path.Combine(path, sceneName))) { continue; }

                bool success;
                var  data = TryBuildScene(Path.Combine(path, sceneName), out success);
                if (success)
                {
                    dataList.Add(data);
                }
            }

            // コンパイル終了時の処理 設定
            EditorUtility.DisplayProgressBar("マネージャオブジェクトの作成中...", "", 1f);
            var file = new TemporaryFileData(dataList.ToArray());

            UnityCallback.SetActionOnCompiled(file);
        }
예제 #3
0
        /// <summary>
        /// スクリプト作成
        /// </summary>
        /// <param name="folderPath">フォルダパス</param>
        /// <param name="folderName">作成先のフォルダ名</param>
        public static MonoScript CreateScriptAsset(string folderPath, string folderName, string scriptName, string templateName)
        {
            // 補正
            folderName = NameCorrector.CorrectNameIfInvalid(folderName);

            var scriptPath = string.Format("{0}/{1}", folderPath, scriptName);
            var template   = DataLoader.LoadScriptTemplate(templateName);

            if (template == null)
            {
                Debug.LogErrorFormat("template \"{0}\"not found", templateName);
                return(null);
            }

            var templatePath = AssetDatabase.GetAssetPath(template);

            return(CreateScriptAssetFromTemplate(
                       @namespace: folderName,
                       sceneName: folderName,
                       scriptPath: scriptPath,
                       templatePath: templatePath
                       ));
        }