using System; using UnityEngine; namespace Game.SpriteDeformerTools { /// /// Point data class /// [System.Serializable] public class SpritePoint { public int countOfOfsset { get { return _countOfOfsset; } set { if (value == _countOfOfsset) return; Array.Resize(ref offsets, value); if (value > countOfOfsset && value > 1) { offsets[value - 1] = offsets[value - 2]; } _countOfOfsset = value; } } [SerializeField] private int _countOfOfsset = 1; public int index { get { return _index; } set { _index = value; } } [SerializeField] private int _index = 0; /// /// Position in sprite where (0,0) is bottom left and (1,1) is top right; /// public Vector2 spritePosition; /// /// Color of the point /// public Color color; /// /// Normal of the point /// public Vector3 normal; /// /// Name of the point /// public string name = "point"; /// /// (X,Y) offset relative to the point. /// if you set (0,1) in mesh the vertex moves right on one width of sprite. /// (Z) offset in local transform. /// public Vector3 offset { get { return offsets[_index]; } set { if (offsets.Length > _index) offsets[_index] = value; } } /// /// (X,Y) offset relative to the point. /// if you set (0,1) in mesh the vertex moves right on one width of sprite. /// public Vector2 offset2d { get { return offsets[_index]; } set { Vector3 v3 = offsets[_index]; v3.x = value.x; v3.y = value.y; offsets[_index] = v3; } } public Vector3[] offsets = new Vector3[1]; /// /// Collider offset. /// public Vector2 colliderOffset = Vector2.zero; /// /// ID of the point. /// public string id; public SpritePoint(Vector2 position, Color? color = null) { this.spritePosition = position; this.color = color != null ? (Color)color : Color.white; id = System.Guid.NewGuid().ToString(); } public SpritePoint(float x, float y) { this.spritePosition = new Vector2(x, y); color = Color.white; id = System.Guid.NewGuid().ToString(); } } }