public void AddSpriteMap(string givenAnimation, Color givenColor)
    {
        SpriteMap tempSpriteMap = TextureController.GetSpriteMap(givenAnimation, givenColor);

        if (m_animationList.ContainsKey(tempSpriteMap.GetName()))
        {
            m_animationList[tempSpriteMap.GetName()].AddAnimation(tempSpriteMap.GetAnimations());
        }
        else
        {
            m_animationList.Add(tempSpriteMap.GetName(), tempSpriteMap);
        }
    }
    public static void SetAnimations(Sprite givenSprite, ref Dictionary <string, SpriteMap> givenDictionary)
    {
        Color     animationColour        = transparent;
        Rect      currentAnimationBorder = new Rect(new Vector2(0, 0), new Vector2(givenSprite.rect.size.x, 0));
        SpriteMap currentSpriteMap       = new SpriteMap();
        string    currentSpriteMapId;

        for (int i = 0; i < givenSprite.rect.size.y; i++)
        {
            Color pixelColour = givenSprite.texture.GetPixel(0, i);
            if (animationColour != pixelColour)
            {
                if (pixelColour != transparent)
                {
                    if (animationColour != transparent)
                    {
                        currentSpriteMapId = currentSpriteMap.GetName() + ColourToString(currentSpriteMap.GetColour());
                        givenDictionary.Add(currentSpriteMapId, currentSpriteMap);
                    }
                    animationColour          = pixelColour;
                    currentAnimationBorder.y = i;
                    currentSpriteMap.Initialise(givenSprite.name, animationColour);
                }
                else
                {
                    currentAnimationBorder.size = new Vector2(currentAnimationBorder.size.x, i - currentAnimationBorder.y);
                    PlayAnimation currentAnimation = SetAnimation(currentAnimationBorder, animationColour, givenSprite.texture);
                    currentSpriteMap.AddAnimation(currentAnimation);
                    i += YGAP - 1;
                    currentAnimationBorder.y = i + 1;
                }
            }
            else if (i == givenSprite.rect.size.y - 1)
            {
                if (pixelColour == transparent)
                {
                    throw new TextureNotfoundException(givenSprite.name + " didn't find any textures to make an animation from");
                }
                currentAnimationBorder.size = new Vector2(currentAnimationBorder.size.x, i - currentAnimationBorder.y);
                Rect          currentFrameBorder = new Rect(currentAnimationBorder.position, new Vector2(0, currentAnimationBorder.size.y));
                PlayAnimation currentAnimation   = SetAnimation(currentAnimationBorder, animationColour, givenSprite.texture);
                currentSpriteMap.AddAnimation(currentAnimation);
                i += YGAP - 1;
            }
        }
        currentSpriteMapId = currentSpriteMap.GetName() + ColourToString(currentSpriteMap.GetColour());
        givenDictionary.Add(currentSpriteMapId, currentSpriteMap);
    }
Exemple #3
0
    public void AddSpriteMap(string givenAnimation)
    {
        SpriteMap tempSpriteMap = TextureController.GetAnimations(givenAnimation, m_colour);

        m_animationList.Add(tempSpriteMap.GetName(), tempSpriteMap);
    }