/// <summary>
        /// Retrieves the value of an import parameter for the specified <see cref="Resource"/>.
        /// If the parameter was undefined, it will be (persistently) initialized with the specified default value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="env"></param>
        /// <param name="resource">A reference to the <see cref="Duality.Resource"/> that is parameterized.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="defaultValue">If the value wasn't defined for the given Resource, the default value will be used instead.</param>
        /// <returns>The retrieved value, or the default value that was specified.</returns>
        public static T GetOrInitParameter <T>(this IAssetImportEnvironment env, IContentRef resource, string parameterName, T defaultValue)
        {
            T value;

            if (env.GetParameter <T>(resource, parameterName, out value))
            {
                return(value);
            }

            env.SetParameter <T>(resource, parameterName, defaultValue);
            return(defaultValue);
        }
示例#2
0
        protected override void ImportResource(ContentRef <Pixmap> resourceRef, AssetImportInput input, IAssetImportEnvironment env)
        {
            Pixmap resource = resourceRef.Res;

            // Retrieve import parameters
            int sheetCols   = env.GetOrInitParameter(resourceRef, "SpriteSheetColumns", 0);
            int sheetRows   = env.GetOrInitParameter(resourceRef, "SpriteSheetRows", 0);
            int frameBorder = env.GetOrInitParameter(resourceRef, "SpriteFrameBorder", 0);

            // Clamp import parameters
            if (sheetCols < 0)
            {
                sheetCols = 0;
            }
            if (sheetRows < 0)
            {
                sheetRows = 0;
            }
            if (frameBorder < 0)
            {
                frameBorder = 0;
            }
            env.SetParameter(resourceRef, "SpriteSheetColumns", sheetCols);
            env.SetParameter(resourceRef, "SpriteSheetRows", sheetRows);
            env.SetParameter(resourceRef, "SpriteFrameBorder", frameBorder);

            // Update pixel data from the input file
            PixelData pixelData = this.LoadPixelData(input.Path);

            resource.MainLayer = pixelData;

            // Generate a sprite sheet atlas
            if (sheetCols > 0 && sheetRows > 0)
            {
                this.GenerateSpriteSheetAtlas(resource, sheetCols, sheetRows, frameBorder);
            }
        }