void DrawSpBase() { var sp = (Sprite)EditorGUI.ObjectField(rectArea, sprite, typeof(Sprite), true); if (sprite != sp) { //step 1 :record for undo Object[] objs = { this, SWWindowMain.Instance }; SWUndo.Record(objs); if (sp != null) { sprite = sp; InitForSp(); Texture2D t2d = SWCommon.SpriteGetTexture2D(sprite); float x = sprite.rect.x / (float)t2d.width; float y = sprite.rect.y / (float)t2d.height; float width = sprite.rect.width / t2d.width; float height = sprite.rect.height / t2d.height; SWWindowMain.Instance.data.spriteRect = new Rect(x, y, width, height); } else { sprite = sp; SWWindowMain.Instance.data.spriteRect = new Rect(0, 0, 1, 1); } } }
void InitForSp() { if (sprite != null) { InitForSpSub(); Texture2D t2d = SWCommon.SpriteGetTexture2D(sprite); float x = sprite.rect.x / (float)t2d.width; float y = sprite.rect.y / (float)t2d.height; float width = sprite.rect.width / t2d.width; float height = sprite.rect.height / t2d.height; SWWindowMain.Instance.data.spriteRect = new Rect(x, y, width, height); } else { SWWindowMain.Instance.data.spriteRect = new Rect(0, 0, 1, 1); } }