コード例 #1
0
        /// <summary>
        /// Changes item scale if item has size variance
        /// </summary>
        /// <param name="tileX">X Position of the item</param>
        /// <param name="tileY">Y Position of the item</param>
        /// <param name="sizeVariance">Allowed size variance of the item</param>
        /// <param name="unitySprite">Sprite which size will be changed</param>
        private void SetupItemScale(int tileX, int tileY, float sizeVariance, SpriteRenderer unitySprite)
        {
            if (sizeVariance == 0f)
            {
                return;
            }

            float scale = MapVariance.GetItemScaleVariance(tileX, tileY, sizeVariance);

            unitySprite.transform.localScale = new Vector3(scale, scale, 1f);
        }
コード例 #2
0
        /// <summary>
        /// Gets item a random frame id if item is a multiframe item
        /// Registers an animation runnter for the item, if it is animated
        /// </summary>
        /// <param name="variantBase">The base item of the specific item</param>
        /// <param name="tileX">X Position of the item</param>
        /// <param name="tileY">Y Position of the item</param>
        /// <param name="unitySprite">Sprite which is animated or multiframed</param>
        /// <returns>Current frame id to be used by the sprite</returns>
        private int SetupMultiFrameItem(VariantObjectBase variantBase, int tileX, int tileY, SpriteRenderer unitySprite)
        {
            if (!variantBase.IsAnimated)
            {
                return(variantBase.GetFrameId(MapVariance.GetItemFrameVariance(tileX, tileY, variantBase.FrameCount)));
            }

            if (!animationRunners.TryGetValue(variantBase, out var animationRunner))
            {
                animationRunner = new AnimationRunner(variantBase, variantBase.InitialId);
                animationRunners.Add(variantBase, animationRunner);
            }

            animationRunner.RegisterAnimatedSprite(unitySprite);

            return(variantBase.InitialId);
        }