Esempio n. 1
0
    void Start()
    {
        mLayer = GetComponent <GiraffeLayer>();
        mAtlas = mLayer.atlas;

        mBoxes    = new GiraffeSprite[4];
        mBoxes[0] = mAtlas.GetSprite("Box");
        mBoxes[1] = mAtlas.GetSprite("Box2");
        mBoxes[2] = mAtlas.GetSprite("Box3");
        mBoxes[3] = mAtlas.GetSprite("Box4");

        int count = 50 + UnityEngine.Random.Range(1, 20);

        mLayer.Begin(count);

        for (int i = 0; i < count; i++)
        {
            int x = UnityEngine.Random.Range(0, Screen.width);
            int y = UnityEngine.Random.Range(0, Screen.height);
            int b = UnityEngine.Random.Range(0, mBoxes.Length);
            mLayer.Add(x, y, mBoxes[b]);
        }

        mLayer.End();
    }
Esempio n. 2
0
    void Start()
    {
        mLayer = GetComponent <GiraffeLayer>();
        mAtlas = mLayer.atlas;

        mBoxes    = new GiraffeSprite[4];
        mBoxes[0] = mAtlas.GetSprite("Box");
        mBoxes[1] = mAtlas.GetSprite("Box1");

        mCount        = 50 + UnityEngine.Random.Range(1, 20);
        mTranslations = new Vector2[mCount];
        mRotations    = new float[mCount];
        mScales       = new Vector2[mCount];

        for (int i = 0; i < mCount; i++)
        {
            float time = UnityEngine.Random.Range(0.0f, 8.0f);
            float cx   = UnityEngine.Random.Range(0, Screen.width);
            float cy   = UnityEngine.Random.Range(0, Screen.width);

            GiraffeSprite sprite = mBoxes[i % 2];

            mTranslations[i] = new Vector2(cx, cy);
            mRotations[i]    = time;
            mScales[i]       = new Vector2(sprite.width, sprite.height) * Mathf.Sin(mRotations[i]) * 8.0f;
        }
    }
Esempio n. 3
0
 public void FetchSprites()
 {
     frameSprites = new GiraffeSprite[frames.Count];
     if (atlas == null)
     {
         for (int i = 0; i < frames.Count; i++)
         {
             frameSprites[i] = new GiraffeSprite();
         }
     }
     else
     {
         for (int i = 0; i < frames.Count; i++)
         {
             frameSprites[i] = atlas.GetSprite(frames[i]);
         }
     }
 }
Esempio n. 4
0
    void Initialise()
    {
        sprite = atlas.GetSprite(spriteName);

        float invTexWidth  = 1.0f / atlas.texture.width;
        float invTexHeight = 1.0f / atlas.texture.height;

        characters        = new Dictionary <char, GiraffeFontGlyph>(glyphs.Length);
        characterRangeMin = char.MaxValue;
        characterRangeMax = char.MinValue;

        for (int i = 0; i < glyphs.Length; i++)
        {
            GiraffeFontGlyph glyph = glyphs[i];

            char c = (char)glyph.character;
            characters.Add(c, glyph);

            if (c < characterRangeMin)
            {
                characterRangeMin = c;
            }

            if (c > characterRangeMax)
            {
                characterRangeMax = c;
            }


            GiraffeSprite glyphSprite = new GiraffeSprite();
            glyph.sprite = glyphSprite;

            glyphSprite.left   = glyph.x + sprite.left;
            glyphSprite.top    = glyph.y + sprite.top;
            glyphSprite.width  = glyph.width;
            glyphSprite.height = glyph.height;

            glyphSprite.Refresh(invTexWidth, invTexHeight);
        }
    }
    public override void OnInspectorGUI()
    {
        bool changed = false;

        GUILayout.BeginVertical();
        GUILayout.Label("Sprite", EditorStyles.boldLabel);
        GUILayout.Space(4);
        EditorGUI.indentLevel++;

        if (mLayer != null)
        {
            GUI.changed          = false;
            mCurrentSpriteNameId = EditorGUILayout.Popup("Sprite", mCurrentSpriteNameId, mSpriteNames);
            if (GUI.changed)
            {
                mRenderer.spriteName = mSpriteNames[mCurrentSpriteNameId];
                changed = true;
            }
        }
        else
        {
            GUI.changed          = false;
            mRenderer.spriteName = EditorGUILayout.TextField("Sprite", mRenderer.spriteName);
            if (GUI.changed)
            {
                changed = true;
            }
        }

        GUI.changed     = false;
        mRenderer.scale = EditorGUILayout.FloatField("Scale", mRenderer.scale);
        if (GUI.changed)
        {
            changed = true;
        }

        EditorGUI.indentLevel--;

        GUILayout.EndVertical();


        BoxCollider2D collider2D = mRenderer.GetComponent <BoxCollider2D>();

        if (mLayer != null && collider2D != null && mAtlas != null)
        {
            GUILayout.BeginVertical();
            GUILayout.Label("Collider", EditorStyles.boldLabel);
            GUILayout.Space(4);
            EditorGUI.indentLevel++;

            if (GUILayout.Button("Resize Collider to sprite"))
            {
                GiraffeSprite sprite = mAtlas.GetSprite(mRenderer.spriteName);
                collider2D.size = new Vector2(sprite.width, sprite.height);
                changed         = true;
            }

            EditorGUI.indentLevel--;

            GUILayout.EndVertical();
        }

        if (changed)
        {
            EditorUtility.SetDirty(mRenderer);
        }
    }
Esempio n. 6
0
    public void Add(int x, int y, String spriteName)
    {
        GiraffeSprite sprite = mAtlas.GetSprite(spriteName);

        Add(x, y, sprite.width, sprite.height, sprite);
    }