private static string LocateAssetFile <T>(string invalidPath) where T : UnityEngine.Object { string fileExtension = Path.GetExtension(invalidPath)?.Replace(".", ""); string newPath = EditorUtility.OpenFilePanel( "Couldn't find asset at " + invalidPath + ". Select correct file.", UrdfAssetPathHandler.GetAssetRootFolder(), fileExtension); return(UrdfAssetPathHandler.GetRelativeAssetPath(newPath)); }
private static string LocateRootAssetFolder <T>(string urdfFileName) where T : UnityEngine.Object { string newAssetPath = EditorUtility.OpenFolderPanel( "Locate package root folder", Path.Combine(Path.GetDirectoryName(Application.dataPath), "Assets"), ""); UrdfAssetPathHandler.SetAssetRootFolder(UrdfAssetPathHandler.GetRelativeAssetPath(newAssetPath)); return(GetAssetPathFromUrdfPath(urdfFileName)); }
public static void InitializeRobotMaterials(Robot robot) { if (!AssetDatabase.IsValidFolder(Path.Combine(UrdfAssetPathHandler.GetAssetRootFolder(), materialFolderName))) { AssetDatabase.CreateFolder(UrdfAssetPathHandler.GetAssetRootFolder(), materialFolderName); } CreateDefaultMaterialAsset(); foreach (var material in robot.materials) { CreateMaterialAsset(material); } }
private static string GetAssetPathFromUrdfPath(string urdfPath) { if (!urdfPath.StartsWith(@"package://")) { Debug.LogWarning(urdfPath + " is not a valid URDF package file path. Path should start with \"package://\"."); return(null); } var path = urdfPath.Substring(10) .Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (Path.GetExtension(path).ToLowerInvariant() == ".stl") { path = path.Substring(0, path.Length - 3) + "prefab"; } return(Path.Combine(UrdfAssetPathHandler.GetAssetRootFolder(), path)); }
public static GameObject Create(this Robot robot) { if (UrdfAssetPathHandler.IsValidAssetPath(robot.filename)) { Debug.LogError("URDF file and ressources must be placed in Assets Folder:\n" + Application.dataPath); return(null); } UrdfAssetPathHandler.SetAssetRootFolder(robot); UrdfMaterialHandler.InitializeRobotMaterials(robot); GameObject gameObject = new GameObject(robot.name); robot.root.Create(gameObject); GameObjectUtility.SetParentAndAlign(gameObject, Selection.activeObject as GameObject); Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name); Selection.activeObject = gameObject; SetKinematic(gameObject, true); return(gameObject); }
private static string GetMaterialAssetPath(string materialName) { var path = Path.Combine(materialFolderName, Path.GetFileName(materialName) + ".mat"); return(Path.Combine(UrdfAssetPathHandler.GetAssetRootFolder(), path)); }
public static T FindUrdfAsset <T>(string urdfFileName) where T : UnityEngine.Object { string fileAssetPath = GetAssetPathFromUrdfPath(urdfFileName); T assetObject = AssetDatabase.LoadAssetAtPath <T>(fileAssetPath); if (assetObject != null) { return(assetObject); } //If asset was not found, let user choose whether to search for //or ignore the missing asset. string invalidPath = fileAssetPath ?? urdfFileName; int option = EditorUtility.DisplayDialogComplex("Urdf Importer: Asset Not Found", "Current root folder: " + UrdfAssetPathHandler.GetAssetRootFolder() + "\n\nExpected asset path: " + invalidPath, "Locate Asset", "Ignore Missing Asset", "Locate Root Folder"); switch (option) { case 0: fileAssetPath = LocateAssetFile <T>(invalidPath); break; case 1: break; case 2: fileAssetPath = LocateRootAssetFolder <T>(urdfFileName); break; } assetObject = (T)AssetDatabase.LoadAssetAtPath(fileAssetPath, typeof(T)); if (assetObject != null) { return(assetObject); } ChooseFailureOption(urdfFileName); return(null); }