// =================================================================================== // PUBLIC METHODS -------------------------------------------------------------------- /// <summary> /// Connects to a <see cref="ScriptableObject"/> asset. /// If the asset already exists at the given path, loads it and returns it. /// Otherwise, either returns NULL or automatically creates it before loading and returning it /// (depending on the given parameters). /// </summary> /// <typeparam name="T">Asset type</typeparam> /// <param name="adbFilePath">File path (relative to Unity's project folder)</param> /// <param name="createIfMissing">If TRUE and the requested asset doesn't exist, forces its creation</param> public static T ConnectToSourceAsset <T>(string adbFilePath, bool createIfMissing = false) where T : ScriptableObject { if (!HOFileUtils.AssetExists(adbFilePath)) { if (createIfMissing) { CreateScriptableAsset <T>(adbFilePath); } else { return(null); } } T source = (T)Resources.LoadAssetAtPath(adbFilePath, typeof(T)); if (source == null) { // Source changed (or editor file was moved from outside of Unity): overwrite it CreateScriptableAsset <T>(adbFilePath); source = (T)Resources.LoadAssetAtPath(adbFilePath, typeof(T)); } return(source); }
static void CreateMenuItem <T>(string directoryPath, string name, bool isDockableWindow, bool useShortcut, bool useCtrl, bool useShift, string letter) { directoryPath = directoryPath.Replace(HOFileUtils.pathSlashToReplace, HOFileUtils.pathSlash); Type type = typeof(T); string nameSpace = type.Namespace; string className = type.Name; string fileClassName = className + "MenuItem"; string filePath = directoryPath + HOFileUtils.pathSlash + fileClassName + ".cs"; string dockable = (isDockableWindow ? "false" : "true"); string shortcut = ""; if (useShortcut) { shortcut += " "; if (useCtrl) { shortcut += "%"; } if (useShift) { shortcut += "#"; } shortcut += letter; } string fileContent = _ClassString.Replace(_ReplaceUsingStr, nameSpace == null ? "" : "using " + nameSpace + ";\n"); fileContent = fileContent.Replace(_ReplaceFileClassStr, fileClassName); fileContent = fileContent.Replace(_ReplaceClassStr, className); fileContent = fileContent.Replace(_ReplaceNameStr, name); fileContent = fileContent.Replace(_ReplaceDockableStr, dockable); fileContent = fileContent.Replace(_ReplaceShortcutStr, shortcut); File.WriteAllText(filePath, fileContent); AssetDatabase.ImportAsset(HOFileUtils.FullPathToADBPath(filePath), ImportAssetOptions.TryFastReimportFromMetaData); }