Elem8100 / MapleNecrocer

MapleStory Client Emulator
MIT License
156 stars 21 forks source link

我如何修改DrawEx函数来适配unity #25

Open Amyas opened 6 months ago

Amyas commented 6 months ago
public void DrawEx(Texture2D Texture, float X, float Y, int OriginX, int OriginY, float ScaleX, float ScaleY, float Rotation,
    bool FlipX, bool FlipY, byte Red, byte Green, byte Blue, byte Alpha, bool DoCenter, BlendMode BlendMode = BlendMode.Normal)
{
    SetBlendMode(BlendMode);
    SpriteEffects Flip = SetFlip(FlipX, FlipY);
    if (DoCenter)
    {
        OriginX = Texture.Width / 2;
        OriginY = Texture.Height / 2;
    }

    SpriteBatch.Draw(Texture,
                  new Vector2(X, Y),
                  null,
                  new Microsoft.Xna.Framework.Color(Red, Green, Blue, Alpha),
                  Rotation,
                  new Vector2(OriginX, OriginY),
                  new Vector2(ScaleX, ScaleY),
                  Flip,
                  0);

    SpriteBatch.End();
}
请问我如何使用unity 创建里面的内容坐标
            if (DoCenter)
        {
            originX = texture.width / 2;
            originY = texture.height / 2;
        }

        UnityEngine.Sprite newSprite = UnityEngine.Sprite.Create(
            texture,
            new UnityEngine.Rect(0, 0, texture.width, texture.height),
            Vector2.zero,
            100f,
            0U,
            SpriteMeshType.FullRect
        );
        Transform transform = Utils.CreateImageNode(this.transform, "bs_" + index++).transform;
        RectTransform rectTransform = transform as RectTransform;
        rectTransform.anchoredPosition = new Vector2(x, y);
        Image image = transform.GetComponent<Image>();
        image.sprite = newSprite;
        image.SetNativeSize();

        我这样写,坐标对不上ui
Elem8100 commented 6 months ago

我沒用unity , 無法幫你