Exception cleanup. Code cleanup.

This commit is contained in:
2022-12-23 15:20:16 +08:00
parent ff5928b556
commit 356f4df9a9
13 changed files with 51 additions and 77 deletions

View File

@@ -3,32 +3,18 @@ using UnityEngine;
namespace Cryville.Crtr {
public class SpriteFrame {
#pragma warning disable IDE1006
Rect _frame;
public Rect frame {
get { return _frame; }
set { _frame = value; }
}
public Rect textureRect {
get { return _frame; }
set { _frame = value; }
Rect m_frame;
public Rect Frame {
get { return m_frame; }
set { m_frame = value; }
}
bool _rotated = false;
public bool rotated {
get { return _rotated; }
set { _rotated = value; }
bool m_rotated = false;
public bool Rotated {
get { return m_rotated; }
set { m_rotated = value; }
}
public bool textureRotated {
get { return _rotated; }
set { _rotated = value; }
}
#pragma warning restore IDE1006
public Vector2 offset;
public Rect sourceColorRect;
public Vector2 sourceSize;
private Rect _uv;
private Vector2[] cuv;
public Rect UV {
@@ -41,7 +27,7 @@ namespace Cryville.Crtr {
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
float y1 = Mathf.Max(_uv.yMin, _uv.yMax);
if (_rotated) cuv = new Vector2[]{
if (m_rotated) cuv = new Vector2[]{
new Vector2(x0, y1),
new Vector2(x1, y0),
new Vector2(x0, y0),
@@ -79,28 +65,17 @@ namespace Cryville.Crtr {
public void Init() {
if (Texture == null)
throw new InvalidOperationException("Missing texture");
_frame = new Rect(Vector2.zero, Size);
var w = _frame.width;
var h = _frame.height;
float x = _frame.x / w;
float y = 1 - _frame.y / h;
float tw = (_rotated ? _frame.height : _frame.width) / w;
float th = (_rotated ? _frame.width : _frame.height) / h;
if (_rotated) UV = new Rect(x, y, tw, -th);
m_frame = new Rect(Vector2.zero, Size);
var w = m_frame.width;
var h = m_frame.height;
float x = m_frame.x / w;
float y = 1 - m_frame.y / h;
float tw = (m_rotated ? m_frame.height : m_frame.width) / w;
float th = (m_rotated ? m_frame.width : m_frame.height) / h;
if (m_rotated) UV = new Rect(x, y, tw, -th);
else UV = new Rect(x, y, tw, -th);
}
public void Init(int w, int h, Texture2D _base) {
if (Texture != null)
throw new InvalidOperationException("Missing texture");
Texture = _base;
float x = _frame.x / w;
float y = 1 - _frame.y / h;
float tw = (_rotated ? _frame.height : _frame.width) / w;
float th = (_rotated ? _frame.width : _frame.height) / h;
if (_rotated) UV = new Rect(x, y, tw, -th);
else UV = new Rect(x, y, tw, -th);
}
public SpriteFrame() { }
public SpriteFrame(Texture2D tex) {
Texture = tex;