示例#1
0
        /// <summary>
        /// For the file path, returns a valid location if exists.
        /// If inFilePath is not valid, it uses the file name to search the asset database to
        /// find the actual valid location (in case it was moved).
        /// </summary>
        /// <param name="gameObjectName">Name of the asset for which to find the path.</param>
        /// <param name="inFilePath">Current path of the asset to validate. Could be null or invalid.</param>
        /// <returns>Valid path or null if none found.</returns>
        public static string LocateValidFilePath(string assetName, string inFilePath)
        {
#if UNITY_EDITOR
            // Find asset if its not at given path
            if (!HEU_Platform.DoesFileExist(inFilePath))
            {
                string   fileName = HEU_Platform.GetFileNameWithoutExtension(inFilePath);
                string[] guids    = AssetDatabase.FindAssets(fileName);
                if (guids.Length > 0)
                {
                    foreach (string guid in guids)
                    {
                        string newPath = AssetDatabase.GUIDToAssetPath(guid);
                        if (newPath != null && newPath.Length > 0)
                        {
                            Debug.Log(string.Format("Note: changing asset path for {0} to {1}.", assetName, newPath));
                            return(newPath);
                        }
                    }
                }

                // No valid path
                throw new HEU_HoudiniEngineError(string.Format("Houdini Asset file has moved from last location: {0}", inFilePath));
            }
#endif
            return(inFilePath);
        }
示例#2
0
        /// <summary>
        /// For the file path, returns a valid location if exists.
        /// If inFilePath is not valid, it uses the file name to search the asset database to
        /// find the actual valid location (in case it was moved).
        /// </summary>
        /// <param name="gameObjectName">Name of the asset for which to find the path.</param>
        /// <param name="inFilePath">Current path of the asset to validate. Could be null or invalid.</param>
        /// <returns>Valid path or null if none found.</returns>
        public static string LocateValidFilePath(string assetName, string inFilePath)
        {
#if UNITY_EDITOR
            // Convert in path to real path if it was environment mapped previously (ie. has $key/blah.hda)
            inFilePath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(inFilePath);

            // Find asset if its not at given path
            if (!HEU_Platform.DoesFileExist(inFilePath))
            {
                string   fileName = HEU_Platform.GetFileNameWithoutExtension(inFilePath);
                string[] guids    = AssetDatabase.FindAssets(fileName);
                if (guids.Length > 0)
                {
                    foreach (string guid in guids)
                    {
                        string newPath = AssetDatabase.GUIDToAssetPath(guid);
                        if (newPath != null && newPath.Length > 0)
                        {
                            Debug.Log(string.Format("Note: changing asset path for {0} to {1}.", assetName, newPath));
                            return(newPath);
                        }
                    }
                }

                // No valid path
                throw new HEU_HoudiniEngineError(string.Format("Houdini Asset file has moved from last location: {0}", inFilePath));
            }
#endif
            return(inFilePath);
        }
示例#3
0
	/// <summary>
	/// Create a unique asset cache folder for the given asset path.
	/// The given asset path should be the HDA's path in the project.
	/// </summary>
	/// <param name="suggestedAssetPath">A suggested path to try. Will use default if empty or null./param>
	/// <returns>Unique asset cache folder for given asset path</returns>
	public static string CreateAssetCacheFolder(string suggestedAssetPath, int hash = 0)
	{
#if UNITY_EDITOR
	    // We create a unique folder inside our plugin's asset database cache folder.

	    string assetDBPath = GetAssetCachePath();
	    string assetWorkingPath = HEU_Platform.BuildPath(assetDBPath, HEU_Defines.HEU_WORKING_PATH);
	    if (!AssetDatabase.IsValidFolder(assetWorkingPath))
	    {
		AssetDatabase.CreateFolder(assetDBPath, HEU_Defines.HEU_WORKING_PATH);
	    }

	    string fileName = HEU_Platform.GetFileNameWithoutExtension(suggestedAssetPath);
	    if (string.IsNullOrEmpty(fileName))
	    {
		fileName = "AssetCache";
		HEU_Logger.LogWarningFormat("Unable to get file name from {0}. Using default value: {1}.", suggestedAssetPath, fileName);
	    }

	    if (HEU_PluginSettings.ShortenFolderPaths && fileName.Length >= 3 && hash != 0)
	    {
		fileName = fileName.Substring(0, 3) + hash;
	    }

	    string fullPath = HEU_Platform.BuildPath(assetWorkingPath, fileName);

	    // Gives us the unique folder path, which we then separate out to create this folder
	    fullPath = AssetDatabase.GenerateUniqueAssetPath(fullPath);

	    CreatePathWithFolders(fullPath);
	    if (!AssetDatabase.IsValidFolder(fullPath))
	    {
		HEU_Logger.LogErrorFormat("Unable to create a valid asset cache folder: {0}! Check directory permission or that enough space is available!", fullPath);
		fullPath = null;
	    }

	    return fullPath;
#else
			// TODO RUNTIME: AssetDatabase is not supported at runtime. Do we need to support this for runtime?
			HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
			return null;
#endif
	}