Beispiel #1
0
    private static void CreateScreen_AfterCompilation()
    {
        var waitForCompilation = EditorPrefs.GetBool("Temp.EditorWaitCompilation.CreateFeatureComplex");

        if (waitForCompilation == true)
        {
            EditorPrefs.DeleteKey("Temp.EditorWaitCompilation.CreateFeatureComplex");

            var dir           = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Dir");
            var assetName     = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Name");
            var assetNameOrig = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Name.Orig");
            var assetPath     = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.ScriptPath");
            var newAssetPath  = EditorPrefs.GetString("Temp.EditorWaitCompilation.CreateFeatureComplex.NewScriptPath");

            if (assetNameOrig.EndsWith("Screen") == false)
            {
                var content = System.IO.File.ReadAllText(assetPath);
                content = content.Replace(@"/*#SCRIPTNAME_POST#*/", "Screen");
                System.IO.File.WriteAllText(assetPath, content);
            }
            else
            {
                var content = System.IO.File.ReadAllText(assetPath);
                content = content.Replace(@"/*#SCRIPTNAME_POST#*/", "");
                System.IO.File.WriteAllText(assetPath, content);
            }

            AssetDatabase.MoveAsset(assetPath, newAssetPath);
            AssetDatabase.ImportAsset(newAssetPath, ImportAssetOptions.ForceSynchronousImport);

            var guid = AssetDatabase.AssetPathToGUID(newAssetPath);
            var defs = new Dictionary <string, string>()
            {
                { "GUID", guid },
            };

            ScriptTemplates.CreateEmptyDirectory(dir, "Screens");
            ScriptTemplates.CreateEmptyDirectory(dir, "Components");
            ScriptTemplates.CreateEmptyDirectory(dir, "Layouts");

            var asset = AssetDatabase.LoadAssetAtPath <TextAsset>(newAssetPath);
            AssignIcon(asset, new GUIContent(Resources.Load <Texture>("EditorAssets/Scripts/window_icon")));


            ScriptTemplates.Create(dir + "/Screens", assetName + "Screen.prefab", "61-ScreenAsset", allowRename: false, customDefines: defs);
        }
    }
Beispiel #2
0
    public static void CreateScreen()
    {
        ScriptTemplates.Create("New Screen.cs", "01-ScreenTemplate", onCreated: (asset) => {
            var path      = ScriptTemplates.GetDirectoryFromAsset(asset);
            var assetName = asset.name;
            if (assetName.EndsWith("Screen") == true)
            {
                assetName = assetName.Replace("Screen", string.Empty);
            }
            ScriptTemplates.CreateEmptyDirectory(path, assetName);
            var dir          = path + "/" + assetName;
            var newAssetPath = dir + "/" + assetName + "Screen.cs";

            EditorPrefs.SetBool("Temp.EditorWaitCompilation.CreateFeatureComplex", true);
            EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Dir", dir);
            EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Name", assetName);
            EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.Name.Orig", asset.name);
            EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.ScriptPath", AssetDatabase.GetAssetPath(asset));
            EditorPrefs.SetString("Temp.EditorWaitCompilation.CreateFeatureComplex.NewScriptPath", newAssetPath);
        });
    }