예제 #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();
        }
예제 #2
0
    public void OnGUI()
    {
        if (!_capturing)
        {
            if (GUILayout.Button("Generate Documentation"))
            {
                var repository = InvertGraphEditor.DesignerWindow.DiagramViewModel.CurrentRepository;
                _screenshots = repository.AllOf <GraphNode>().ToList();
                _capturing   = true;
                NextScreenshot();
            }
            return;
        }

        if (drawer == null)
        {
            return;
        }
        foreach (var item in drawer.Children)
        {
            //if (!(item is DiagramNodeDrawer)) continue;
            //if (item is ScreenshotNodeDrawer) continue;
            item.Draw(InvertGraphEditor.PlatformDrawer, 1f);
        }


        if (Event.current.type == EventType.Repaint)
        {
            Texture2D texture2D = new Texture2D(Mathf.RoundToInt(this.position.width), Mathf.RoundToInt(this.position.height), (TextureFormat)3, false);

            texture2D.ReadPixels(new Rect(0f, 0f, this.position.width, this.position.height), 0, 0);
            texture2D.Apply();
            byte[] bytes = texture2D.EncodeToPNG();
            Object.DestroyImmediate((Object)texture2D, true);
            var directory = Path.Combine("Documentation", "Screenshots");
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            File.WriteAllBytes(Path2.Combine("Documentation", "Screenshots", _screenshots[_currentScreenshotIndex - 1].Name + ".png"), bytes);
            Debug.Log("Saved image " + _screenshots[_currentScreenshotIndex - 1].Name + ".png");
            NextScreenshot();
        }

        //this.Close();
    }