Exemplo n.º 1
0
        public static void AddGlobalInstallers()
        {
            var dir = UnityEditorUtil.TryGetCurrentDirectoryInProjectsTab();

            var assetName = GlobalCompositionRoot.GlobalInstallersResourceName + ".asset";

            if (dir == null)
            {
                EditorUtility.DisplayDialog("Error",
                                            "Could not find directory to place the {0} asset.  Please try again by right clicking in the desired folder within the projects pane.".Fmt(assetName), "Ok");
                return;
            }

            var parentFolderName = Path.GetFileName(dir);

            if (parentFolderName != "Resources")
            {
                EditorUtility.DisplayDialog("Error", "{0} must be placed inside a directory named 'Resources'.  Please try again by right clicking within the Project pane in a valid Resources folder.".Fmt(assetName), "Ok");
                return;
            }

            var asset = ScriptableObject.CreateInstance <GlobalInstallerConfig>();

            string assetPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(dir, assetName));

            AssetDatabase.CreateAsset(asset, assetPath);
            AssetDatabase.Refresh();

            Debug.Log("Created new asset at '{0}'".Fmt(assetPath));
        }
Exemplo n.º 2
0
        public static void ValidateScenesFromScript()
        {
            var sceneNames = UnityEditorUtil.GetArgument("scenes").Split(',');

            Assert.That(sceneNames.Length > 0);

            ValidateScenes(
                sceneNames.Select(x => UnityEditorUtil.GetScenePath(x)).ToList(), true);
        }
Exemplo n.º 3
0
        static List <ZenjectResolveException> ValidateDecoratorCompRoot(SceneDecoratorCompositionRoot decoratorCompRoot, int maxErrors)
        {
            var sceneName = decoratorCompRoot.SceneName;
            var scenePath = UnityEditorUtil.GetScenePath(sceneName);

            if (scenePath == null)
            {
                return(new List <ZenjectResolveException>()
                {
                    new ZenjectResolveException(
                        "Could not find scene path for decorated scene '{0}'".Fmt(sceneName)),
                });
            }

            var rootObjectsBefore = UnityUtil.GetRootGameObjects();

            OpenSceneAdditive(scenePath);

            var newRootObjects = UnityUtil.GetRootGameObjects().Except(rootObjectsBefore);

            // Use finally to ensure we clean up the data added from OpenSceneAdditive
            try
            {
                var previousBeforeInstallHook = SceneCompositionRoot.BeforeInstallHooks;
                SceneCompositionRoot.BeforeInstallHooks = (container) =>
                {
                    if (previousBeforeInstallHook != null)
                    {
                        previousBeforeInstallHook(container);
                    }

                    decoratorCompRoot.AddPreBindings(container);
                };

                var previousAfterInstallHook = SceneCompositionRoot.AfterInstallHooks;
                SceneCompositionRoot.AfterInstallHooks = (container) =>
                {
                    decoratorCompRoot.AddPostBindings(container);

                    if (previousAfterInstallHook != null)
                    {
                        previousAfterInstallHook(container);
                    }
                };

                var compRoot = newRootObjects.SelectMany(x => x.GetComponentsInChildren <SceneCompositionRoot>()).OnlyOrDefault();

                if (compRoot != null)
                {
                    return(ValidateCompRoot(compRoot, maxErrors));
                }

                var newDecoratorCompRoot = newRootObjects.SelectMany(x => x.GetComponentsInChildren <SceneDecoratorCompositionRoot>()).OnlyOrDefault();

                if (newDecoratorCompRoot != null)
                {
                    return(ValidateDecoratorCompRoot(newDecoratorCompRoot, maxErrors));
                }

                return(new List <ZenjectResolveException>()
                {
                    new ZenjectResolveException(
                        "Could not find composition root for decorated scene '{0}'".Fmt(sceneName)),
                });
            }
            finally
            {
#if UNITY_5_3_OR_NEWER
                EditorSceneManager.CloseScene(EditorSceneManager.GetSceneByPath(scenePath), true);
#else
                foreach (var newObject in newRootObjects)
                {
                    GameObject.DestroyImmediate(newObject);
                }
#endif
            }
        }
Exemplo n.º 4
0
 public static bool ValidateAllActiveScenes(bool exitAfter)
 {
     return(ValidateScenes(UnityEditorUtil.GetAllActiveScenePaths(), exitAfter));
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }

            GUILayout.Space(5);

            var binder = target as SceneDecoratorCompositionRoot;

            EditorGUILayout.BeginHorizontal();
            {
                binder.SceneName = EditorGUILayout.TextField("Decorated Scene", binder.SceneName);

                GUILayout.Space(10);

                if (GUILayout.Button("Open", GUILayout.MaxWidth(40)))
                {
                    EditorApplication.delayCall += () =>
                    {
                        var scenePath = UnityEditorUtil.TryGetScenePath(binder.SceneName);

                        if (scenePath == null)
                        {
                            EditorUtility.DisplayDialog("Error",
                                                        "Could not find scene with name '{0}'.  Is it added to your build settings?".Fmt(binder.SceneName), "Ok");
                        }
                        else
                        {
#if UNITY_5_3
                            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
#else
                            if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
#endif
                            {
                                ZenEditorUtil.OpenScene(scenePath);

                                var compRoot = ZenEditorUtil.TryGetSceneCompositionRoot();

                                if (compRoot != null)
                                {
                                    Selection.activeGameObject = compRoot.gameObject;
                                }
                                else
                                {
                                    var decoratorCompRoot = ZenEditorUtil.TryGetSceneDecoratorCompositionRoot();

                                    if (decoratorCompRoot != null)
                                    {
                                        Selection.activeGameObject = decoratorCompRoot.gameObject;
                                    }
                                }
                            }
                        }
                    };
                }
            }
            EditorGUILayout.EndHorizontal();

            foreach (var list in _propLists)
            {
                list.DoLayoutList();
            }

            GUI.enabled = true;
            serializedObject.ApplyModifiedProperties();
        }