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));
        }
Beispiel #2
0
        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));
        }
Beispiel #4
0
        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);
        }