Beispiel #1
0
    void OnGUI()
    {
        // Draw sprites from SpriteBatch.Draw()
        for (int i = 0; i < drawQueue.LastSpriteQueue.Length; i++)
        {
            DrawSpriteCall call = drawQueue.LastSpriteQueue[i];
            float          x    = call.Position.X;
            float          y    = call.Position.Y;
            x -= call.Origin.X;
            y -= call.Origin.Y;
            float width  = call.Texture2D.UnityTexture.width;
            float height = call.Texture2D.UnityTexture.height;
            GUI.color = new Color(call.Color.X, call.Color.Y, call.Color.Z, call.Color.W);

            Rect sourceRect = new Rect(0, 0, 1, 1);

            if (call.Source != null)
            {
                sourceRect.x      = call.Source.Value.X / width;
                sourceRect.y      = call.Source.Value.Y / height;
                sourceRect.width  = call.Source.Value.Width / width;
                sourceRect.height = call.Source.Value.Height / height;
            }

            if (call.SpriteEffects == Microsoft.Xna.Framework.Graphics.SpriteEffects.FlipHorizontally)
            {
                sourceRect.x      = 1 - sourceRect.x;
                sourceRect.width *= -1;
            }
            else if (call.SpriteEffects == Microsoft.Xna.Framework.Graphics.SpriteEffects.FlipVertically)
            {
                sourceRect.y       = 1 - sourceRect.y;
                sourceRect.height *= -1;
            }

            GUI.DrawTextureWithTexCoords(new Rect(x, y, width * Mathf.Abs(sourceRect.width), height * Mathf.Abs(sourceRect.height)), call.Texture2D.UnityTexture, sourceRect);
        }

        // Draw strings from SpriteBatch.DrawString()
        for (int i = 0; i < drawQueue.LastStringQueue.Length; i++)
        {
            DrawStringCall call = drawQueue.LastStringQueue[i];

            GUI.color = new Color(call.Color.X, call.Color.Y, call.Color.Z, call.Color.W);

            Vector2 size = GUI.skin.label.CalcSize(new GUIContent(call.Value));
            GUI.Label(new Rect(call.Position.X, call.Position.Y, size.x, size.y), call.Value);
        }

        //GUIStyle style = new GUIStyle();
        //style.font = Font.

        //GUILayout.Label()
        //GUI.color = Color.black;
        //GUILayout.Label(string.Format("{0} fps, {1} sprite draw calls", fps, drawQueue.LastSpriteQueue.Length));
    }
Beispiel #2
0
 internal void EnqueueSprite(DrawSpriteCall drawSpriteCall)
 {
     spriteQueue.Add(drawSpriteCall);
 }
 internal void EnqueueSprite(DrawSpriteCall drawSpriteCall)
 {
     spriteQueue.Add(drawSpriteCall);
 }