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 = ZenUnityEditorUtil.ConvertFullAbsolutePathToAssetPath(absolutePath); EditorUtility.FocusProjectWindow(); Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetPath); return(assetPath); }
public static void ValidateAllActiveScenes() { ZenUnityEditorUtil.SaveThenRunPreserveSceneSetup(() => { var numValidated = ZenUnityEditorUtil.ValidateAllActiveScenes(); Log.Info("Validated all '{0}' active scenes successfully", numValidated); }); }
static bool ValidateCurrentSceneInternal() { return(ZenUnityEditorUtil.SaveThenRunPreserveSceneSetup(() => { SceneParentAutomaticLoader.ValidateMultiSceneSetupAndLoadDefaultSceneParents(); ZenUnityEditorUtil.ValidateCurrentSceneSetup(); Log.Info("All scenes validated successfully"); })); }
public static void CreateDefaultSceneContractConfig() { var folderPath = ZenUnityEditorUtil.GetCurrentDirectoryAssetPathFromSelection(); if (!folderPath.EndsWith("/Resources")) { EditorUtility.DisplayDialog("Error", "ZenjectDefaultSceneContractConfig objects must be placed directly underneath a folder named 'Resources'. Please try again.", "Ok"); return; } var config = ScriptableObject.CreateInstance <DefaultSceneContractConfig>(); ZenUnityEditorUtil.SaveScriptableObjectAsset( Path.Combine(folderPath, DefaultSceneContractConfig.ResourcePath + ".asset"), config); }
static void CreateProjectContextInternal(string absoluteDir) { var assetPath = ZenUnityEditorUtil.ConvertFullAbsolutePathToAssetPath(absoluteDir); var prefabPath = (Path.Combine(assetPath, ProjectContext.ProjectContextResourcePath) + ".prefab").Replace("\\", "/"); var emptyPrefab = PrefabUtility.CreateEmptyPrefab(prefabPath); var gameObject = new GameObject(); try { gameObject.AddComponent <ProjectContext>(); var prefabObj = PrefabUtility.ReplacePrefab(gameObject, emptyPrefab); Selection.activeObject = prefabObj; } finally { GameObject.DestroyImmediate(gameObject); } Debug.Log("Created new ProjectContext at '{0}'".Fmt(prefabPath)); }
public static void CreateProjectContext() { var absoluteDir = ZenUnityEditorUtil.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); }
public static string AddCSharpClassTemplate( string friendlyName, string defaultFileName, string templateStr) { return(AddCSharpClassTemplate( friendlyName, defaultFileName, templateStr, ZenUnityEditorUtil.GetCurrentDirectoryAssetPathFromSelection())); }