/// <summary> /// Create folder/s based on path if they do not exist. /// </summary> /// <param name="path">Relative path to "**/MyProject/Assets/", may start with "Assets/".</param> /// <code><para>CreateFolder("newFolder/newFolder") </para> /// <para>CreateFolder("Assets/newFolder/newFolder") </para></code> public static string CreateFolder(string path) { if (path.StartsWith("/")) { path = path.Remove(0, 1); } string[] sep = path.Split('/'); string p = "Assets"; int i = 0; if (path.StartsWith("Assets/")) { i = 1; } string lastValidPath = p; for (; i < sep.Length; i++) { if (i == sep.Length - 1 && sep[i].Equals("")) { continue; } p = String.Concat(p, '/', sep[i]); if (!AssetDatabase.IsValidFolder(p)) { AssetDatabase.CreateFolder(lastValidPath, sep[i]); } lastValidPath = p; } return(p); }
public static ProfileData CreateProfile(ProfileTypes type, string name) { string path = string.Format("Assets/ImportProfiles/Editor/Profiles/{0}/{1}{2}", type.ToString() + 's', name, profileExtensions[type]); if (!AssetDatabase.IsValidFolder(Path.GetDirectoryName(path)?.Replace('\\', '/'))) { AssetDatabase.CreateFolder("Assets/ImportProfiles/Editor/Profiles", type.ToString() + 's'); } if (AssetDatabase.LoadAssetAtPath <Object>(path) != null) { path = AssetDatabase.GenerateUniqueAssetPath(path); } Func <string, Object> value; if (!assetCreationfunctions.TryGetValue(type, out value)) { return(null); } value.Invoke(path); AssetDatabase.ImportAsset(path); AssetDatabase.SaveAssets(); var importer = AssetImporter.GetAtPath(path); if (importer != null) { var profile = new ProfileData(path, type); AddProfile(importer); return(profile); } return(null); }
public static void CreateOrGetGlobalBlackboard() { if (Application.isPlaying) { // Get object Selection.activeObject = GlobalBlackboard.Instance.gameObject; } else { var prefab = Resources.Load("GlobalBlackboard") as GameObject; // Create GlobalBlackboard if (prefab == null) { // The target folder address string folder = "Assets/Resources"; // Does Resources folder exist? if (!FileUtility.DirectoryExists(folder)) { AssetDatabase.CreateFolder("Assets", "Resources"); } // Create the prefab var go = new GameObject("GlobalBlackboard", typeof(GlobalBlackboard)); Selection.activeObject = PrefabUtility.CreatePrefab(folder + "/GlobalBlackboard.prefab", go); GameObject.DestroyImmediate(go); } else { if (prefab.GetComponent <GlobalBlackboard>() == null) { prefab.AddComponent <GlobalBlackboard>(); } Selection.activeObject = prefab; } } }
public static Material Material2Unity(string[] textureSearchDirs, string mshObjName, MATD from, Material baseMat, string[] additionalTextureSearchPaths = null) { Material material = new Material(baseMat); //material.EnableKeyword("_METALLICGLOSSMAP"); //material.EnableKeyword("_SPECGLOSSMAP"); material.name = from.Name; material.SetColor("_Color", Color2Unity(from.Diffuse)); if (!string.IsNullOrEmpty(from.Texture) && IMPORT_TEXTURES) { Texture2D albedo = ImportTexture(textureSearchDirs, from.Texture); //Texture2D normal = ImportTexture(mshSourceDir, from.Texture); if (albedo != null) { material.SetTexture(DEFAULT_MATERIAL_ALBEDO, albedo); } //if (normal != null) //{ // material.EnableKeyword("_NORMALMAP"); // material.SetTexture(DEFAULT_MATERIAL_NORMAL, normal); //} } if (CREATE_ASSETS) { if (!AssetDatabase.IsValidFolder("Assets" + MODELS_FOLDER + "/" + mshObjName + "/Materials")) { AssetDatabase.CreateFolder("Assets" + MODELS_FOLDER + "/" + mshObjName, "Materials"); } AssetDatabase.CreateAsset(material, "Assets" + MODELS_FOLDER + "/" + mshObjName + "/Materials/" + material.name + ".mat"); } return(material); }
void CreateTrain(){ #if UNITY_EDITOR AssetDatabase.DeleteAsset(pathFolder+"/"+"Train"); AssetDatabase.CreateFolder(pathFolder, "Train"); int longTrain = minLongTrain; while(longTrain <= maxLongTrain){ float trainWidth; GameObject realTrainInstance = new GameObject("TrainLong_"+longTrain.ToString()); GameObject trainDummy = Instantiate(carriage, new Vector3(-300, -300, -300), Quaternion.identity) as GameObject; trainWidth = trainDummy.transform.GetChild(0).GetComponent<MeshRenderer>().bounds.size.x; Destroy(trainDummy); GameObject headTr = Instantiate(headTrain, transform.position, Quaternion.identity) as GameObject; int i =0; while(i < longTrain){ GameObject trainInstance = Instantiate(carriage, new Vector3(transform.position.x - (i * trainWidth), transform.position.y, transform.position.z), Quaternion.identity) as GameObject; trainInstance.transform.SetParent(headTr.transform); i++; } realTrainInstance.transform.position = transform.position; headTr.transform.SetParent(realTrainInstance.transform); MeshCombine.CreatePrefab(realTrainInstance, pathFolder, "Train", "Train"); // //This so heavy // UnityEngine.Object dummyPrefab = EditorUtility.CreateEmptyPrefab("Assets/CrossyWay/Prefabs/Train/TrainComplete/RealTrain_"+longTrain.ToString()+".prefab"); // GameObject prefabTrain = PrefabUtility.ReplacePrefab(realTrainInstance, dummyPrefab, ReplacePrefabOptions.ConnectToPrefab) as GameObject; // prefabTrain.tag = "Train"; // //Heavy part end Destroy(realTrainInstance); longTrain++; } #endif }
// 剛体の生成 GameObject[] CreateRigids(GameObject[] bones) { PMDFormat.RigidbodyList list = format_.rigidbody_list; if (!System.IO.Directory.Exists(System.IO.Path.Combine(format_.folder, "Physics"))) { AssetDatabase.CreateFolder(format_.folder, "Physics"); } // 剛体の登録 GameObject[] rigid = new GameObject[list.rigidbody_count]; for (int i = 0; i < list.rigidbody_count; i++) { rigid[i] = new GameObject("r" + list.rigidbody[i].rigidbody_name); //rigid[i].AddComponent<Rigidbody>(); // 剛体本体にはrigidbodyは適用しない // 各種Colliderの設定 Collider collider = null; switch (list.rigidbody[i].shape_type) { case 0: collider = EntrySphereCollider(list.rigidbody[i], rigid[i]); break; case 1: collider = EntryBoxCollider(list.rigidbody[i], rigid[i]); break; case 2: collider = EntryCapsuleCollider(list.rigidbody[i], rigid[i]); break; } // マテリアルの設定 collider.material = CreatePhysicMaterial(list.rigidbody[i]); } return(rigid); }
[MenuItem("Assets/Create Editor Script %#a", false, 20)] // guesswork required for priorities (or reflector to look at source) static void AttachSelectedScriptsToNewEmptyObject() { Type[] selectedMonoBehaviourTypes = GetSelectedMonoBehaviourTypes(); if (selectedMonoBehaviourTypes.Length > 0) { if (!AssetDatabase.IsValidFolder("Assets/Editor")) { AssetDatabase.CreateFolder("Assets", "Editor"); } foreach (Type scriptType in selectedMonoBehaviourTypes) { string targetScriptName = scriptType.ToString(); string targetVariableName = Char.ToLower(targetScriptName[0]) + targetScriptName.Substring(1); string editorScriptName = targetScriptName + "Editor"; string path = "Assets/Editor/" + editorScriptName + ".cs"; if (!File.Exists(path)) { string templateGUID = AssetDatabase.FindAssets("EditorTemplate t:textasset")[0]; TextAsset templateFile = AssetDatabase.LoadAssetAtPath <TextAsset>(AssetDatabase.GUIDToAssetPath(templateGUID)); string templateText = templateFile.text; string editorScriptContents = templateText; editorScriptContents = editorScriptContents.Replace("@TargetScriptName", targetScriptName); editorScriptContents = editorScriptContents.Replace("@targetVariableName", targetVariableName); editorScriptContents = editorScriptContents.Replace("@EditorScriptName", editorScriptName); StreamWriter writer = new StreamWriter(path); writer.Write(editorScriptContents); writer.Close(); AssetDatabase.Refresh(); } } } }
public override void DrawWindow() { List <string> dirs = new List <string>(); string path = Application.dataPath + "/Resources/Prefabs/NodeEditorObjects/"; DirectoryInfo info = new DirectoryInfo(path); DirectoryInfo[] dirInfo = info.GetDirectories(); //DirectoryInfo[] fileInfo = info.GetDirectories (); dirs.Add("."); foreach (DirectoryInfo dir in dirInfo) { dirs.Add(dir.Name); } newFolder = EditorGUILayout.TextField(newFolder); if (GUILayout.Button("Create new folder")) { if (!newFolder.Equals("")) { AssetDatabase.CreateFolder("Assets/Resources/Prefabs/NodeEditorObjects", newFolder); newFolder = ""; } } int selection2 = EditorGUILayout.Popup(selection, dirs.ToArray()); if (selection2 != selection) { nodeEditor.updateFolder(dirs[selection2]); } selection = selection2; }
private static void SettingAssetPage() { GUILayout.Label("Creating a Settings Asset", Styles.title); GUILayout.Space(12); GUILayout.Label(@"GameplayIngredients는 다양한 기능을 제공하는 프레임 워크입니다. 이 에셋은 Resources 폴더에 저장해야합니다. 필수 사항은 아니지만 프로젝트 요구에 맞게 수정할 수 있도록 생성하는 것이 좋습니다. ", Styles.body); GUILayout.Space(16); using (new GUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("GameplayIngredientsSettings 에셋 생성")) { bool create = true; if (System.IO.File.Exists(Application.dataPath + "/../" + kSettingsAssetPath)) { if (!EditorUtility.DisplayDialog("GameplayIngredientsSettings Asset Overwrite", "A GameplayIngredientsSettings Asset already exists, do you want to overwrite it?", "Yes", "No")) { create = false; } } if (create) { if (!System.IO.Directory.Exists(Application.dataPath + "/Resources")) { AssetDatabase.CreateFolder("Assets", "Resources"); } GameplayIngredientsSettings asset = Instantiate(GameplayIngredientsSettings.defaultSettings); AssetDatabase.CreateAsset(asset, kSettingsAssetPath); Selection.activeObject = asset; } } } }
private void BuildCardDataAsset() { _cardData.Id = Guid.NewGuid().ToString(); Debug.Log($"Generated card with Id: {_cardData.Id}"); var assetDirectory = $@"Assets\GameData\Cards\{_cardData.Type}"; var assetPath = $@"{assetDirectory}\{_cardData.CardName}.asset"; if (!AssetDatabase.IsValidFolder(assetDirectory)) { AssetDatabase.CreateFolder(@"Assets\GameData\Cards", $"{_cardData.Type}"); } AssetDatabase.CreateAsset(_cardData, assetPath); foreach (var attribute in _cardData.Attributes) { AssetDatabase.AddObjectToAsset(attribute, assetPath); if (attribute is Ability ability) { if (ability.TargetSelector != null) { AssetDatabase.AddObjectToAsset(ability.TargetSelector, ability); } } } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(_cardData)); // Reset Global Editor options AbilityEditor.SelectedTargetSelectorName = "None"; // TODO: Encapsulate this? Debug.Log($"Created Card Asset at: {AssetDatabase.GetAssetPath(_cardData)}"); UpdateCardLibrary(); }
void SaveAsset() { //create boss root path if it doesn't exist if (!AssetDatabase.IsValidFolder(rootFolderPath)) { AssetDatabase.CreateFolder("Assets", rootFolderName); } //create the boss folder. if it exists already, return with an error notification string bossName = currentAsset.bossParameters.name; string bossPath = rootFolderPath + "/" + bossName; if (AssetDatabase.IsValidFolder(bossPath)) { ShowNotification(new GUIContent("Error: Assets for boss " + bossName + " already exist!")); return; } AssetDatabase.CreateFolder(rootFolderPath, bossName); //create the boss asset string assetPath = bossPath + "/" + bossName + ".asset"; AssetDatabase.CreateAsset(currentAsset, assetPath); AssetDatabase.SaveAssets(); //create subfolders. if we have any cloned subfolder paths we are supposed to copy, //copy them instead of creating new subfolders if (cloneSource != null) { CloneSubfolders(cloneSource, bossPath); } else { CreateNewSubfolders(bossPath); } AssetDatabase.Refresh(); }
public Converter(UnityEngine.Object asset) { this.email = EditorPrefs.GetString(Settings.STYLY_EMAIL); this.apiKey = EditorPrefs.GetString(Settings.STYLY_API_KEY); isAdministrator = this.email.Equals("*****@*****.**"); if (isAdministrator) { this.unityGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset)); // 管理者はスクリプトをあげることがあるので、親オブジェクトを付けない this.asset = asset; this.assetPath = AssetDatabase.GetAssetPath(this.asset); this.assetTitle = System.IO.Path.GetFileNameWithoutExtension(this.assetPath); this.unityVersion = UnityEngine.Application.unityVersion; } else { this.unityGuid = Guid.NewGuid().ToString("D"); // ユーザー向けにはupload用のオブジェクトを作成して親に空のGameObjectを付ける var copy = PrefabUtility.InstantiateAttachedAsset(asset); ((GameObject)copy).transform.position = Vector3.zero; var uploadPrefab = new GameObject(); ((GameObject)copy).transform.parent = uploadPrefab.transform; if (!AssetDatabase.IsValidFolder("Assets/" + Config.STYLY_TEMP_DIR)) { AssetDatabase.CreateFolder("Assets", Config.STYLY_TEMP_DIR); } this.asset = PrefabUtility.CreatePrefab(string.Format(Config.UploadPrefabName, asset.name), uploadPrefab, ReplacePrefabOptions.ConnectToPrefab); UnityEditor.AssetDatabase.SaveAssets(); Editor.DestroyImmediate(uploadPrefab); this.assetPath = AssetDatabase.GetAssetPath(this.asset); this.assetTitle = System.IO.Path.GetFileNameWithoutExtension(this.assetPath); this.unityVersion = UnityEngine.Application.unityVersion; } }
// Generate new cube mesh and save to asset folder as LevelMesh_1 etc to correct folder (Level Editor/Meshes). Returns the mesh private Mesh GenerateMesh() { // Ensure Level Editor Folder exists and create if not string path = Application.dataPath + "/Level Editor"; if (!Directory.Exists(path)) { AssetDatabase.CreateFolder("Assets", "Level Editor"); } // Ensure Meshes Folder exists and create if not path = path + "/Meshes"; if (!Directory.Exists(path)) { AssetDatabase.CreateFolder("Assets/Level Editor", "Meshes"); } // Check all files in Meshes folder and ensure we have a unique name (so don't overwrite any existing meshes) string[] meshPaths = Directory.GetFiles(path); int meshNumber = 0; for (int i = 0; i < meshPaths.Length; i++) { if (meshPaths[i].Contains("LevelMesh_" + meshNumber.ToString())) { meshNumber += 1; i = 0; } } // Create mesh string fileName = "Assets/Level Editor/Meshes/LevelMesh_" + meshNumber.ToString() + ".asset"; AssetDatabase.CreateAsset(CreatePlane(), fileName); return(AssetDatabase.LoadAssetAtPath(fileName, typeof(Mesh)) as Mesh); }
private static void ExtractMeshes(Object selectedObject) { //Create Folder Hierarchy string selectedObjectPath = AssetDatabase.GetAssetPath(selectedObject); string parentFolderpath = selectedObjectPath.Substring(0, selectedObjectPath.Length - (selectedObject.name.Length + 5)); string objectFolderName = selectedObject.name; string objectFolderPath = parentFolderpath + "/" + objectFolderName; string meshFolderName = "Meshes"; string meshFolderPath = objectFolderPath + "/" + meshFolderName; if (!AssetDatabase.IsValidFolder(objectFolderPath)) { AssetDatabase.CreateFolder(parentFolderpath, objectFolderName); if (!AssetDatabase.IsValidFolder(meshFolderPath)) { AssetDatabase.CreateFolder(objectFolderPath, meshFolderName); } } //Create Meshes Object[] objects = AssetDatabase.LoadAllAssetsAtPath(selectedObjectPath); for (int i = 0; i < objects.Length; i++) { if (objects[i] is Mesh) { EditorUtility.DisplayProgressBar(_progressTitle, selectedObject.name + " : " + objects[i].name, (float)i / (objects.Length - 1)); Mesh mesh = Object.Instantiate(objects[i]) as Mesh; AssetDatabase.CreateAsset(mesh, meshFolderPath + "/" + objects[i].name + _targetExtension); } } //CleanUp AssetDatabase.MoveAsset(selectedObjectPath, objectFolderPath + "/" + selectedObject.name + _sourceExtension); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public void CreateFolder() { if (AssetDatabase.IsValidFolder("Assets/Editor")) { Debug.Log("Your Folders already exists !");; } else { AssetDatabase.CreateFolder("Assets", "Editor"); AssetDatabase.CreateFolder("Assets", "Scripts"); AssetDatabase.CreateFolder("Assets/Editor", "Resources"); AssetDatabase.CreateFolder("Assets/Editor/Resources", "3D"); AssetDatabase.CreateFolder("Assets/Editor/Resources", "2D"); AssetDatabase.CreateFolder("Assets/Editor/Resources", "ANIMATIONS"); AssetDatabase.CreateFolder("Assets/Editor/Resources", "MATERIALS"); AssetDatabase.MoveAsset("Assets/pluginAR.cs", "Assets/Scripts/pluginAR.cs"); AssetDatabase.MoveAsset("Assets/pluginAR.meta", "Assets/Scripts/pluginAR.meta"); AssetDatabase.MoveAsset("Assets/pluginAREditor.cs", "Assets/Scripts/pluginAREditor.cs"); AssetDatabase.MoveAsset("Assets/pluginAREditor.meta", "Assets/Scripts/pluginAREditor.meta"); AssetDatabase.MoveAsset("Assets/PlacementIndicator.cs", "Assets/Scripts/PlacementIndicator.cs"); AssetDatabase.MoveAsset("Assets/PlacementIndicator.meta", "Assets/Scripts/PlacementIndicator.meta"); AssetDatabase.MoveAsset("Assets/TapToPlace.cs", "Assets/Scripts/TapToPlace.cs"); AssetDatabase.MoveAsset("Assets/TapToPlace.meta", "Assets/Scripts/TapToPlace.meta"); AssetDatabase.MoveAsset("Assets/InteractManager.cs", "Assets/Scripts/InteractManager.cs"); AssetDatabase.MoveAsset("Assets/InteractManager.meta", "Assets/Scripts/InteractManager.meta"); AssetDatabase.MoveAsset("Assets/_TapToPlace.png", "Assets/Editor/Resources/2D/_TapToPlace.png"); AssetDatabase.MoveAsset("Assets/_Particle.png", "Assets/Editor/Resources/2D/_Particle.png"); AssetDatabase.MoveAsset("Assets/_Background.png", "Assets/Editor/Resources/2D/_Background.png"); AssetDatabase.MoveAsset("Assets/_Icon.png", "Assets/Editor/Resources/2D/_Icon.png"); AssetDatabase.MoveAsset("Assets/_3DModel.obj", "Assets/Editor/Resources/3D/_3DModel.obj"); AssetDatabase.Refresh(); } }
/// <summary> /// アニメーションクリップを作成する /// </summary> /// <param name='assign_pmd'>使用するPMDのGameObject</param> /// <param name='create_asset'>Prefab外に作成するか(true:Prefab外に作成, false:Prefab内蔵)</param> /// <param name='interpolationQuality'>補完曲線品質</param> public void CreateAnimationClip(GameObject assign_pmd, bool create_asset, int interpolationQuality) { //VMDファイルのインポート if (null == format_) { //まだ読み込んでいないなら読むこむ format_ = VMDLoaderScript.Import(file_path_); //VMD読み込み header_ = format_.header; } //アニメーションクリップの作成 AnimationClip animation_clip = VMDConverter.CreateAnimationClip(format_, assign_pmd, interpolationQuality); // ここで登録 //anim.AddClip(animation_clip, animation_clip.name); if (create_asset) { // フォルダを生成してアニメーションのファイルを書き出す string prefab_folder = AssetDatabase.GetAssetPath(assign_pmd); prefab_folder = Path.GetDirectoryName(prefab_folder); if (!Directory.Exists(prefab_folder + "/Animation")) { AssetDatabase.CreateFolder(prefab_folder, "Animation"); } AssetDatabase.CreateAsset(animation_clip, prefab_folder + "/Animation/" + animation_clip.name + ".anim"); } else { // こちらはPrefabの中に入れるタイプ AssetDatabase.AddObjectToAsset(animation_clip, AssetDatabase.GetAssetPath(assign_pmd)); } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(animation_clip)); }
public static void Save() { if (_easer == null) { Debug.LogWarning("Easer data has not been loaded, not saving."); return; } // Check/Create directories string[] directories = Easer.DATA_PATH.Split('/'); string currentPath = ""; for (int i = 0; i < directories.Length; i++) { string dir = directories[i]; Debug.Log(dir); string checkDir = Application.dataPath + "/" + currentPath + dir; string parentDir = "Assets" + ((i > 0) ? '/' + currentPath.Remove(currentPath.Length - 1) : ""); if (!System.IO.Directory.Exists(checkDir)) { AssetDatabase.CreateFolder(parentDir, dir); } currentPath += dir + '/'; } currentPath += Easer.DATA_FILENAME; Debug.Log(currentPath); if (!System.IO.File.Exists(Application.dataPath + "/" + currentPath)) { AssetDatabase.CreateAsset(_easer, "Assets/" + currentPath); } EditorUtility.SetDirty(_easer); AssetDatabase.Refresh(); }
//Create the neccesary folders public static void CheckAndCreateFolders() { #if UNITY_EDITOR if (!System.IO.Directory.Exists("Assets/" + StaticValues.voxelizerRootFolder)) { AssetDatabase.CreateFolder("Assets", StaticValues.voxelizerRootFolder); } if (!System.IO.Directory.Exists("Assets/" + StaticValues.voxelizerRootFolder + "/" + StaticValues.constructedContentFolder)) { AssetDatabase.CreateFolder("Assets/" + StaticValues.voxelizerRootFolder, StaticValues.constructedContentFolder); } if (!System.IO.Directory.Exists("Assets/" + StaticValues.voxelizerRootFolder + "/" + StaticValues.animationPrefabsFolder)) { AssetDatabase.CreateFolder("Assets/" + StaticValues.voxelizerRootFolder, StaticValues.animationPrefabsFolder); } if (!System.IO.Directory.Exists("Assets/" + StaticValues.voxelizerRootFolder + "/" + StaticValues.explodedModels)) { AssetDatabase.CreateFolder("Assets/" + StaticValues.voxelizerRootFolder, StaticValues.explodedModels); } #endif }
void OnEnable() { _data = (BiologData)AssetDatabase.LoadAssetAtPath(kBIOLOG_DATA_PATH, typeof(BiologData)); if (_data == null) { _data = ScriptableObject.CreateInstance <BiologData>(); if (!Directory.Exists("Assets/Biolog")) { AssetDatabase.CreateFolder("Assets", "Biolog"); } if (!Directory.Exists("Assets/Biolog/Data")) { AssetDatabase.CreateFolder("Assets/Biolog", "Data"); } AssetDatabase.CreateAsset(_data, kBIOLOG_DATA_PATH); } HashSet <string> allTags = new HashSet <string>(); foreach (var entry in _data.Entries) { foreach (string tag in entry.Tags) { if (!allTags.Contains(tag)) { allTags.Add(tag); } } } minSize = new UnityEngine.Vector2(1000, 600); _model = new BiologEditorModel(this, allTags); _detailView = new BiologEntryDetailView(_model, _data); _listView = new BiologEntryListView(_model, _data); }
public static void exportSub(Transform inTransform) { if (inTransform == null) { return; } MeshFilter mf = inTransform.GetComponent <MeshFilter>(); if (mf != null) { Mesh m = mf.sharedMesh; if (m != null) { if (m.name.IndexOf("road_") == 0 && m.name.IndexOf(".") > 0) { string GUID = AssetDatabase.CreateFolder("Assets", "pack_roads"); string newFolderPath = AssetDatabase.GUIDToAssetPath(GUID); if (AssetDatabase.Contains(m)) { Debug.LogWarning("Asset Database already contains " + m.name); } else { AssetDatabase.CreateAsset(m, "Assets/pack_roads/" + m.name + ".asset"); AssetDatabase.SaveAssets(); } } } } foreach (Transform t in inTransform) { exportSub(t); } }
// Used to initialize the database used in various parts of our plugin public U GetDatabase <U>(string dbPath, string dbName) where U : ScriptableObject { string dbFullPath = @"Assets/" + dbPath + "/" + dbName; U database = AssetDatabase.LoadAssetAtPath(dbFullPath, typeof(U)) as U; if (database == null) { Debug.Log("Could not find Quality Database. Creating it now."); // Create our folder if it does not exist yet. if (!(AssetDatabase.IsValidFolder(@"Assets/" + dbPath))) { Debug.Log("Could not find Database Path. Creating it now."); AssetDatabase.CreateFolder(@"Assets/", dbPath); } database = ScriptableObject.CreateInstance <U>() as U; AssetDatabase.CreateAsset(database, dbFullPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } return(database); }
static void Init() { soundSettings = (SoundSettings)AssetDatabase.LoadAssetAtPath(@"Assets\Resources\SoundSettings.asset", typeof(SoundSettings)); if (soundSettings == null) { if (!Directory.Exists(@"Assets\Resources")) { Debug.Log("Create \"resource\" folder"); AssetDatabase.CreateFolder(@"Assets", "Resources"); } Debug.Log("new SoundSettings created"); soundSettings = ScriptableObject.CreateInstance <SoundSettings>(); AssetDatabase.CreateAsset(soundSettings, @"Assets\Resources\SoundSettings.asset"); } if (!AssetDatabase.Contains(soundSettings)) { AssetDatabase.CreateAsset(soundSettings, @"Assets\Resources\SoundSettings.asset"); } AssetDatabase.SaveAssets(); Selection.objects = new Object[] { soundSettings }; }
internal static ACEditorPrefs GetOrCreateSettings() { string fullPath = Resource.MainFolderPath + settingsPath; var settings = AssetDatabase.LoadAssetAtPath <ACEditorPrefs> (fullPath); if (settings == null) { bool isValid = AssetDatabase.IsValidFolder(Resource.MainFolderPath + "/Editor"); if (!isValid) { AssetDatabase.CreateFolder(Resource.MainFolderPath, "Editor"); isValid = AssetDatabase.IsValidFolder(Resource.MainFolderPath + "/Editor"); } if (isValid) { settings = ScriptableObject.CreateInstance <ACEditorPrefs> (); settings.hierarchyIconOffset = DefaultHierarchyIconOffset; settings.hotspotGizmoColor = DefaultHotspotGizmoColor; settings.triggerGizmoColor = DefaultTriggerGizmoColor; settings.collisionGizmoColor = DefaultCollisionGizmoColor; settings.pathGizmoColor = DefaultPathGizmoColor; settings.menuItemsBeforeScroll = DefaultMenuItemsBeforeScroll; settings.csvFormat = DefaultCSVFormat; AssetDatabase.CreateAsset(settings, fullPath); AssetDatabase.SaveAssets(); } else { Debug.LogWarning("Cannot create AC editor prefs - does the folder '" + Resource.MainFolderPath + "/Editor' exist?"); return(null); } } return(settings); }
public static void EnsureFolderExists(string folder) { if (!folder.StartsWith("Assets/")) { folder = "Assets/" + folder; } var segments = folder.Split('/'); var path = segments.FirstOrDefault(); bool isFirst = true; foreach (var f in segments) { if (f != "Assets" && !AssetDatabase.IsValidFolder(path + "/" + f)) { AssetDatabase.CreateFolder(path, f); } if (!isFirst) { path += "/" + f; } isFirst = false; } }
public bool ValidateAssets(List <string> errors) { errors.Clear(); if (ServiceTemplate == null) { if (!ReadTemplate(ServiceTemplatePath, ref ServiceTemplate)) { errors.Add("Script template not found in " + ServiceTemplatePath); } } if (InterfaceTemplate == null) { if (!ReadTemplate(InterfaceTemplatePath, ref InterfaceTemplate)) { errors.Add("Interface template not found in " + InterfaceTemplatePath); } } if (ProfileTemplate == null) { if (!ReadTemplate(ProfileTemplatePath, ref ProfileTemplate)) { errors.Add("Profile template not found in " + ProfileTemplatePath); } } if (!AssetDatabase.IsValidFolder(DefaultExtensionsFolder)) { AssetDatabase.CreateFolder("Assets", DefaultExtensionsFolderName); AssetDatabase.Refresh(); } return(errors.Count == 0); }
private static char pathSpliter = '/'; // Char that splits path strings. /// <summary> Takes a given path and creates the folders to generate that path if it doesn't already exist. </summary> /// <param name="path"> The path with the folders to be created. </param> public static void CreateFolders(string path) { if (AssetDatabase.IsValidFolder(path)) // Returns if the path already exists. { return; } string[] folders = path.Split(pathSpliter); // Splits the path of the folders that need to be created. string tempPath = folders[0]; for (int index1 = 1; index1 < folders.Length; index1++) // Loops through folder names to adjust the value of the tempPath. { for (int index2 = 1; index2 <= index1; index2++) // Adds to the tempPath to be checked. { tempPath += "/" + folders[index2]; } if (!AssetDatabase.IsValidFolder(tempPath)) // Checks to see if the tempPath does not exist. { AssetDatabase.CreateFolder(folders[index1 - 1], folders[index1]); } } }
private static AnimationClip GenerateEmptyClipAsset() { var emptyClip = new AnimationClip(); var settings = AnimationUtility.GetAnimationClipSettings(emptyClip); settings.loopTime = false; Keyframe[] keyframes = { new Keyframe(0, 0), new Keyframe(1 / 60f, 0) }; var curve = new AnimationCurve(keyframes); emptyClip.SetCurve("_ignored", typeof(GameObject), "m_IsActive", curve); if (!AssetDatabase.IsValidFolder("Assets/Hai")) { AssetDatabase.CreateFolder("Assets", "Hai"); } if (!AssetDatabase.IsValidFolder("Assets/Hai/ComboGesture")) { AssetDatabase.CreateFolder("Assets/Hai", "ComboGesture"); } AssetDatabase.CreateAsset(emptyClip, EmptyClipPath); return(emptyClip); }
private void HandleLinkResult(LinkResult linkResult) { switch (linkResult.ResultType) { case LinkResultType.Success: EditorUtility.SetDirty(linkResult.ObjectToLink); Debug.Log(linkResult.Details, linkResult.ObjectToLink); break; case LinkResultType.MoreThanOneInstance: Debug.LogWarning(linkResult.Details, linkResult.ObjectToLink); break; case LinkResultType.NoExistingObject: Debug.LogWarning(linkResult.Details, linkResult.ObjectToLink); if (shouldAutoCreateMissingInstance) { var newInstance = CreateInstance(linkResult.FieldInfo.FieldType); if (!AssetDatabase.IsValidFolder(AutoGenerateDirectory)) { AssetDatabase.CreateFolder(DefaultDirectory, AutoGenerateFolderName); } AssetDatabase.CreateAsset(newInstance, $"{AutoGenerateDirectory}/{linkResult.FieldInfo.FieldType.Name}.asset"); _autoLinker.Refresh(); ReInjectToObject(linkResult.ObjectToLink); } break; default: throw new ArgumentOutOfRangeException(); } }
void AddStep() { StepSO asset = ScriptableObject.CreateInstance <StepSO>(); int questlineId = 0; questlineId = _currentSelectedQuestLine.IdQuestline; int questId = 0; questId = _currentSeletedQuest.IdQuest; int stepId = 0; stepId = _currentSeletedQuest.Steps.Count + 1; if (!AssetDatabase.IsValidFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Step" + stepId)) { AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId, "Step" + stepId); } AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Step" + stepId + "/S" + stepId + "-Q" + questId + "-QL" + questlineId + ".asset"); _currentSeletedQuest.Steps.Add(asset); EditorUtility.SetDirty(asset); EditorUtility.SetDirty(_currentSeletedQuest); AssetDatabase.SaveAssets(); //refresh rootVisualElement.Q <VisualElement>("quests-list").Q <ListView>().SetSelection(_idQuestSelected); }
void AddQuest() { QuestSO asset = CreateInstance <QuestSO>(); int questlineId = 0; questlineId = _currentSelectedQuestLine.IdQuestline; int questId = 0; questId = _currentSelectedQuestLine.Quests.Count + 1; if (!AssetDatabase.IsValidFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId)) { AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId, "Quest" + questId); } AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Q" + questId + "-QL" + questlineId + ".asset"); asset.SetQuestId(questId); _currentSelectedQuestLine.Quests.Add(asset); EditorUtility.SetDirty(asset); EditorUtility.SetDirty(_currentSelectedQuestLine); AssetDatabase.SaveAssets(); //refresh rootVisualElement.Q <VisualElement>("questlines-list").Q <ListView>().SetSelection(_idQuestlineSelected); }