Esempio n. 1
0
        public static string AddCSharpClassTemplate(
            string friendlyName, string defaultFileName,
            string templateStr, string folderPath)
        {
            var absolutePath = EditorUtility.SaveFilePanel(
                "Choose name for " + friendlyName,
                folderPath,
                defaultFileName + ".cs",
                "cs");

            if (absolutePath == "")
            {
                // Dialog was cancelled
                return(null);
            }

            if (!absolutePath.ToLower().EndsWith(".cs"))
            {
                absolutePath += ".cs";
            }

            var className = Path.GetFileNameWithoutExtension(absolutePath);

            File.WriteAllText(absolutePath, templateStr.Replace("CLASS_NAME", className));

            AssetDatabase.Refresh();

            var assetPath = UniDiUnityEditorUtil.ConvertFullAbsolutePathToAssetPath(absolutePath);

            EditorUtility.FocusProjectWindow();
            Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetPath);

            return(assetPath);
        }
Esempio n. 2
0
        static void CreateProjectContextInternal(string absoluteDir)
        {
            var assetPath  = UniDiUnityEditorUtil.ConvertFullAbsolutePathToAssetPath(absoluteDir);
            var prefabPath = (Path.Combine(assetPath, ProjectContext.ProjectContextResourcePath) + ".prefab").Replace("\\", "/");

            var gameObject = new GameObject();

            try
            {
                gameObject.AddComponent <ProjectContext>();

#if UNITY_2018_3_OR_NEWER
                var prefabObj = PrefabUtility.SaveAsPrefabAsset(gameObject, prefabPath);
#else
                var prefabObj = PrefabUtility.ReplacePrefab(gameObject, PrefabUtility.CreateEmptyPrefab(prefabPath));
#endif

                Selection.activeObject = prefabObj;
            }
            finally
            {
                GameObject.DestroyImmediate(gameObject);
            }

            Debug.Log("Created new ProjectContext at '{0}'".Fmt(prefabPath));
        }
Esempio n. 3
0
        static LoadedSceneInfo TryCreateLoadedSceneInfo(Scene scene)
        {
            var sceneContext     = UniDiUnityEditorUtil.TryGetSceneContextForScene(scene);
            var decoratorContext = UniDiUnityEditorUtil.TryGetDecoratorContextForScene(scene);

            if (sceneContext == null && decoratorContext == null)
            {
                return(null);
            }

            var info = new LoadedSceneInfo
            {
                Scene = scene
            };

            if (sceneContext != null)
            {
                Assert.IsNull(decoratorContext,
                              "Found both SceneContext and SceneDecoratorContext in scene '{0}'", scene.name);

                info.SceneContext = sceneContext;
            }
            else
            {
                Assert.IsNotNull(decoratorContext);

                info.DecoratorContext = decoratorContext;
            }

            return(info);
        }
Esempio n. 4
0
 public static void ValidateAllActiveScenes()
 {
     UniDiUnityEditorUtil.SaveThenRunPreserveSceneSetup(() =>
     {
         var numValidated = UniDiUnityEditorUtil.ValidateAllActiveScenes();
         Log.Info("Validated all '{0}' active scenes successfully", numValidated);
     });
 }
Esempio n. 5
0
 static bool ValidateCurrentSceneInternal()
 {
     return(UniDiUnityEditorUtil.SaveThenRunPreserveSceneSetup(() =>
     {
         SceneParentAutomaticLoader.ValidateMultiSceneSetupAndLoadDefaultSceneParents();
         UniDiUnityEditorUtil.ValidateCurrentSceneSetup();
         Log.Info("All scenes validated successfully");
     }));
 }
Esempio n. 6
0
        public static void CreateDefaultSceneContractConfig()
        {
            var folderPath = UniDiUnityEditorUtil.GetCurrentDirectoryAssetPathFromSelection();

            if (!folderPath.EndsWith("/Resources"))
            {
                EditorUtility.DisplayDialog("Error",
                                            "UniDiDefaultSceneContractConfig objects must be placed directly underneath a folder named 'Resources'.  Please try again.", "Ok");
                return;
            }

            var config = ScriptableObject.CreateInstance <DefaultSceneContractConfig>();

            UniDiUnityEditorUtil.SaveScriptableObjectAsset(
                Path.Combine(folderPath, DefaultSceneContractConfig.ResourcePath + ".asset"), config);
        }
Esempio n. 7
0
        public static void CreateProjectContext()
        {
            var absoluteDir = UniDiUnityEditorUtil.TryGetSelectedFolderPathInProjectsTab();

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

            var parentFolderName = Path.GetFileName(absoluteDir);

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

            CreateProjectContextInternal(absoluteDir);
        }
Esempio n. 8
0
 public static string AddCSharpClassTemplate(
     string friendlyName, string defaultFileName, string templateStr)
 {
     return(AddCSharpClassTemplate(
                friendlyName, defaultFileName, templateStr, UniDiUnityEditorUtil.GetCurrentDirectoryAssetPathFromSelection()));
 }