Ejemplo n.º 1
0
		/// <summary>
		/// Returns the path to the given asset, with subasset tagging if it is
		/// a subasset. Unity doesn't have a way to query subasset paths directly
		/// nor load them directly. Instead have to load the main asset first then
		/// traverse through all assets to find the subasset.
		/// </summary>
		/// <param name="asset">Asset to get path for</param>
		/// <returns>Path of given asset</returns>
		public static string GetAssetPathWithSubAssetSupport(Object asset)
		{
#if UNITY_EDITOR
			string assetPath = AssetDatabase.GetAssetPath(asset);

			bool isSubAsset = HEU_AssetDatabase.IsSubAsset(asset);
			if (isSubAsset)
			{
				Object[] subAssets = HEU_AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
				int numSubAssets = subAssets.Length;
				for(int i = 0; i < numSubAssets; ++i)
				{
					if(subAssets[i] == asset)
					{
						assetPath = string.Format("{0}{1}/{2}", HEU_Defines.HEU_SUBASSET, assetPath, subAssets[i].name);
						break;
					}
				}
			}

			return assetPath;
#else
			Debug.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
			return null;
#endif
		}