public static StickyNotesDatabase LoadOrCreateDatabase() { var dbInstance = Resources.Load <StickyNotesDatabase>("StickyNotes/Database"); if (dbInstance != null) { return(dbInstance); } var soInstance = ScriptableObject.CreateInstance <StickyNotesDatabase>(); if (!Directory.Exists("Assets/Resources")) { Directory.CreateDirectory("Assets/Resources"); } if (!Directory.Exists("Assets/Resources/StickyNotes")) { Directory.CreateDirectory("Assets/Resources/StickyNotes"); } AssetDatabase.CreateAsset(soInstance, "Assets/Resources/StickyNotes/Database.asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(soInstance); }
void OnEnable() { var nameForGlog = Path.Combine(Application.dataPath, "MediapipePlugin"); var logDir = Path.Combine(Application.dataPath.Replace("/Assets", ""), "Logs", "Mediapipe"); if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } UnsafeNativeMethods.InitGoogleLogging(nameForGlog, logDir); }
private static void WriteIntoFile(string fullPath, CodeCompileUnit code) { Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); using (var stream = new StreamWriter(fullPath, append: false)) { var writer = new IndentedTextWriter(stream); using (var codeProvider = new CSharpCodeProvider()) { codeProvider.GenerateCodeFromCompileUnit(code, writer, new CodeGeneratorOptions()); } } }
void OnGUI() { // Sample move data moves.Clear(); foreach (var selected in Selection.objects) { var path = AssetDatabase.GetAssetPath(selected); if (!AssetDatabase.IsValidFolder(path)) { continue; } var moveData = new MoveData(); moveData.assetFolderStartPath = path; moveData.assetFolderEndPath = targetAssetFolder + "/" + Path.GetFileName(moveData.assetFolderStartPath); moveData.sourceFolderStartPath = path.Replace("Assets", sourceFolderRoot); moveData.sourceFolderEndPath = targetAssetFolder + "/" + Path.GetFileName(moveData.sourceFolderStartPath); var projectFolder = Application.dataPath.Replace("/Assets", ""); var sourceFullPath = projectFolder + "/" + moveData.sourceFolderStartPath; moveData.sourceExists = Directory.Exists(sourceFullPath); moves.Add(moveData); } GUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Target asset folder:", GUILayout.Width(120)); if (GUILayout.Button(targetAssetFolder, EditorStyles.textField)) { var newFolder = EditorUtility.OpenFolderPanel("Select target folder", targetAssetFolder, ""); if (newFolder.Contains(Application.dataPath)) { targetAssetFolder = newFolder.Replace(Application.dataPath, "Assets"); } else { GameDebug.LogError("Target folder must be below the project Asset folder "); } } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Move")) { var result = EditorUtility.DisplayDialog("Move", "Are you sure you want to move", "Ok"); } var defaultColor = GUI.color; GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(100)); foreach (var move in moves) { GUILayout.Label("Asset folder:"); GUILayout.Label("Source folder:"); } GUILayout.EndVertical(); GUILayout.BeginVertical(); foreach (var move in moves) { GUILayout.Label(move.assetFolderStartPath); GUI.color = move.sourceExists ? defaultColor : Color.red; GUILayout.Label(move.sourceFolderStartPath); GUI.color = defaultColor; } GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Width(40)); foreach (var move in moves) { GUILayout.Label("=>"); GUILayout.Label("=>"); } GUILayout.EndVertical(); GUILayout.BeginVertical(); foreach (var move in moves) { GUILayout.Label(move.assetFolderEndPath); GUILayout.Label(move.sourceFolderEndPath); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }