Exemplo n.º 1
0
        public void Perform(MVVMNode node)
        {
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return;
            }
            if (!EditorUtility.DisplayDialog("Warning!", "Before scaffolding the core, make sure you saved and compiled!",
                                             "Yes, I saved and compiled!",
                                             "Cancel"))
            {
                return;
            }

            var paths      = InvertApplication.Container.Resolve <DatabaseService>().CurrentConfiguration.CodeOutputPath + "/";
            var scenesPath = System.IO.Path.Combine(paths, "Scenes");

            var sceneName         = node.Graph.Namespace + "KernelScene.unity";
            var sceneNameWithPath = System.IO.Path.Combine(scenesPath, sceneName);

            var          prefabName         = node.Graph.Namespace + "Kernel.prefab";
            var          prefabNameWithPath = Path2.Combine(paths, prefabName);
            var          relativeScenesPath = System.IO.Path.Combine(paths, "Scenes");
            var          relativeScenePath  = System.IO.Path.Combine(relativeScenesPath + "/", sceneName);
            uFrameKernel uFrameMVVMKernel   = null;

            if (File.Exists(sceneNameWithPath))
            {
                var gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(prefabNameWithPath, typeof(GameObject));
                uFrameMVVMKernel = gameObject.GetComponent <uFrameKernel>();
                SyncKernel(node, uFrameMVVMKernel.gameObject);
            }
            else
            {
                var eScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
                if (!Directory.Exists(scenesPath))
                {
                    Directory.CreateDirectory(scenesPath);
                }
                uFrameMVVMKernel = FindComponentInScene <uFrameKernel>() ?? new GameObject("Kernel").AddComponent <uFrameKernel>();
                var services = SyncKernel(node, uFrameMVVMKernel.gameObject);

                services.gameObject.AddComponent <ViewService>();
                services.gameObject.AddComponent <SceneManagementService>();

                PrefabUtility.CreatePrefab(prefabNameWithPath, uFrameMVVMKernel.gameObject, ReplacePrefabOptions.ConnectToPrefab);
                EditorSceneManager.SaveScene(eScene, relativeScenePath);
            }

            if (!UnityEditor.EditorBuildSettings.scenes.Any(s => s.path.EndsWith(node.Graph.SystemPath + "KernelScene.unity")))
            {
                var list = EditorBuildSettings.scenes.ToList();
                list.Add(new EditorBuildSettingsScene(relativeScenePath, true));
                EditorBuildSettings.scenes = list.ToArray();
            }
            AssetDatabase.Refresh();
        }
Exemplo n.º 2
0
    public override void Perform(DiagramViewModel node)
    {
        if (!EditorApplication.SaveCurrentSceneIfUserWantsTo())
        {
            return;
        }
        if (!EditorUtility.DisplayDialog("Warning!", "Before scaffolding the core, make sure you saved and compiled!",
                                         "Yes, I saved and compiled!", "Cancel"))
        {
            return;
        }

        var paths      = node.GraphData.Project.SystemDirectory;
        var scenesPath = System.IO.Path.Combine(paths, "Scenes");

        var sceneName         = node.GraphData.Project.Name + "KernelScene.unity";
        var sceneNameWithPath = System.IO.Path.Combine(scenesPath, sceneName);

        var prefabName = node.GraphData.Project.Name + "Kernel.prefab";
        var project    = node.GraphData.Project as Object;
        var path       = AssetDatabase.GetAssetPath(project);

        var prefabNameWithPath = path.Replace(project.name + ".asset", prefabName);

        var relativeScenesPath = System.IO.Path.Combine(node.GraphData.AssetDirectory, "Scenes");
        var relativeScenePath  = System.IO.Path.Combine(relativeScenesPath, sceneName);


        uFrameKernel uFrameMVVMKernel = null;

        if (File.Exists(sceneNameWithPath))
        {
            //EditorApplication.OpenScene(sceneNameWithPath);
            var gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(prefabNameWithPath, typeof(GameObject));
            uFrameMVVMKernel = gameObject.GetComponent <uFrameKernel>();
            SyncKernel(node, uFrameMVVMKernel.gameObject);
        }
        else
        {
#if UNITY_5
            EditorApplication.NewEmptyScene();
#else
            EditorApplication.NewScene();
#endif
            if (!Directory.Exists(scenesPath))
            {
                Directory.CreateDirectory(scenesPath);
            }
            uFrameMVVMKernel = FindComponentInScene <uFrameKernel>() ??
                               new GameObject("Kernel").AddComponent <uFrameKernel>();
            var services = SyncKernel(node, uFrameMVVMKernel.gameObject);

            services.gameObject.AddComponent <ViewService>();
            services.gameObject.AddComponent <SceneManagementService>();

            //    var pref ab : Object = PrefabUtility.CreateEmptyPrefab(localPath);
            //PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ConnectToPrefab);
            PrefabUtility.CreatePrefab(prefabNameWithPath, uFrameMVVMKernel.gameObject, ReplacePrefabOptions.ConnectToPrefab);
            EditorApplication.SaveScene(relativeScenePath);
        }
        if (!UnityEditor.EditorBuildSettings.scenes.Any(s =>
        {
            return(s.path.EndsWith(node.GraphData.Project.Name + "KernelScene.unity"));
        }))
        {
            var list = EditorBuildSettings.scenes.ToList();
            list.Add(new EditorBuildSettingsScene(relativeScenePath, true));
            EditorBuildSettings.scenes = list.ToArray();
        }
        AssetDatabase.Refresh();
    }