Esempio n. 1
0
        /// <summary>
        /// Tries to parse an asset reference in the format "[GUID/]GUID:Location". The first GUID is optional and is used to store the ID of the reference.
        /// </summary>
        /// <param name="assetReferenceText">The asset reference.</param>
        /// <param name="id">The unique identifier of object pointed by this reference.</param>
        /// <param name="location">The location.</param>
        /// <param name="referenceId">The unique identifier of this reference (may be null)</param>
        /// <returns><c>true</c> if parsing was successful, <c>false</c> otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">assetReferenceText</exception>
        /// <remarks>The referenceId is obsolete since Xenko 1.9.</remarks>
        public static bool TryParse(string assetReferenceText, out AssetId id, out UFile location, out Guid referenceId)
        {
            if (assetReferenceText == null)
            {
                throw new ArgumentNullException(nameof(assetReferenceText));
            }

            id          = AssetId.Empty;
            referenceId = Guid.Empty;
            location    = null;
            int indexFirstSlash     = assetReferenceText.IndexOf('/');
            int indexBeforelocation = assetReferenceText.IndexOf(':');

            if (indexBeforelocation < 0)
            {
                return(false);
            }
            int startNextGuid = 0;

            if (indexFirstSlash > 0 && indexFirstSlash < indexBeforelocation)
            {
                if (!Guid.TryParse(assetReferenceText.Substring(0, indexFirstSlash), out referenceId))
                {
                    return(false);
                }
                startNextGuid = indexFirstSlash + 1;
            }

            if (!AssetId.TryParse(assetReferenceText.Substring(startNextGuid, indexBeforelocation - startNextGuid), out id))
            {
                return(false);
            }

            location = new UFile(assetReferenceText.Substring(indexBeforelocation + 1));

            return(true);
        }
        /// <summary>
        /// Finds an asset from all the packages by its id.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="assetId">The assetId of the asset.</param>
        /// <returns>An <see cref="AssetItem" /> or <c>null</c> if not found.</returns>
        public static AssetItem FindAsset(this PackageSession session, AssetId assetId)
        {
            var packages = session.Packages;

            return(packages.Select(packageItem => packageItem.Assets.Find(assetId)).FirstOrDefault(asset => asset != null));
        }
Esempio n. 3
0
 /// <summary>
 /// Determines whether the specified packages contains an asset by its guid.
 /// </summary>
 /// <param name="packages">The packages.</param>
 /// <param name="assetId">The asset unique identifier.</param>
 /// <returns><c>true</c> if the specified packages contains asset; otherwise, <c>false</c>.</returns>
 public static bool ContainsAsset(this IEnumerable <Package> packages, AssetId assetId)
 {
     return(packages.Any(package => package.Assets.ContainsById(assetId)));
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetReference"/> class.
 /// </summary>
 /// <param name="id">The unique identifier of the asset.</param>
 /// <param name="location">The location.</param>
 public AssetReference(AssetId id, UFile location)
 {
     this.location = location;
     Id            = id;
 }
Esempio n. 5
0
 /// <summary>
 /// Tries to parse an asset reference in the format "GUID:Location".
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="location">The location.</param>
 /// <returns><c>true</c> if parsing was successful, <c>false</c> otherwise.</returns>
 public static AssetReference New(AssetId id, UFile location)
 {
     return(new AssetReference(id, location));
 }
Esempio n. 6
0
        /// <summary>
        /// Tries to parse an asset reference in the format "[GUID/]GUID:Location". The first GUID is optional and is used to store the ID of the reference.
        /// </summary>
        /// <param name="assetReferenceText">The asset reference.</param>
        /// <param name="id">The unique identifier of asset pointed by this reference.</param>
        /// <param name="location">The location.</param>
        /// <returns><c>true</c> if parsing was successful, <c>false</c> otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">assetReferenceText</exception>
        public static bool TryParse(string assetReferenceText, out AssetId id, out UFile location)
        {
            Guid referenceId;

            return(TryParse(assetReferenceText, out id, out location, out referenceId));
        }
 /// <summary>
 /// Determines whether this instance contains an asset with the specified identifier.
 /// </summary>
 /// <param name="assetId">The asset identifier.</param>
 /// <returns><c>true</c> if this instance contains an asset with the specified identifier; otherwise, <c>false</c>.</returns>
 public bool ContainsById(AssetId assetId)
 {
     return(mapIdToAsset.ContainsKey(assetId));
 }
Esempio n. 8
0
        /// <summary>
        /// Finds an asset from all the packages by its id.
        /// </summary>
        /// <param name="package">The package.</param>
        /// <param name="assetId">The assetId of the asset.</param>
        /// <returns>An <see cref="AssetItem" /> or <c>null</c> if not found.</returns>
        public static AssetItem FindAsset(this Package package, AssetId assetId)
        {
            var packages = package.GetPackagesWithDependencies();

            return(packages.Select(packageItem => packageItem.Assets.Find(assetId)).FirstOrDefault(asset => asset != null));
        }