|
| 1 | +using System.Collections; |
| 2 | +using System.Collections.Generic; |
| 3 | +using UnityEngine; |
| 4 | +using UnityEngine.UI; |
| 5 | +using System; |
| 6 | + |
| 7 | +namespace EmojiUI |
| 8 | +{ |
| 9 | + public class UnitMeshInfo : IEquatable<UnitMeshInfo> |
| 10 | + { |
| 11 | + private SpriteAsset atlas; |
| 12 | + private List<Vector3> _Vertices = new List<Vector3>(); |
| 13 | + private List<Vector2> _UV = new List<Vector2>(); |
| 14 | + |
| 15 | + public Texture getTexture() |
| 16 | + { |
| 17 | + if (atlas != null) |
| 18 | + return atlas.texSource; |
| 19 | + return null; |
| 20 | + } |
| 21 | + |
| 22 | + public SpriteAsset GetAtlas() |
| 23 | + { |
| 24 | + return atlas; |
| 25 | + } |
| 26 | + |
| 27 | + public void SetAtlas(SpriteAsset data) |
| 28 | + { |
| 29 | + atlas = data; |
| 30 | + } |
| 31 | + |
| 32 | + public void Clear() |
| 33 | + { |
| 34 | + atlas = null; |
| 35 | + _Vertices.Clear(); |
| 36 | + _UV.Clear(); |
| 37 | + } |
| 38 | + |
| 39 | + public void AddCopy(UnitMeshInfo mesh) |
| 40 | + { |
| 41 | + if (atlas != null && atlas != mesh.atlas) |
| 42 | + { |
| 43 | + throw new ArgumentException(); |
| 44 | + } |
| 45 | + atlas = mesh.atlas; |
| 46 | + |
| 47 | + for (int i = 0; i < mesh._Vertices.Count; ++i) |
| 48 | + _Vertices.Add(mesh._Vertices[i]); |
| 49 | + |
| 50 | + for (int i = 0; i < mesh._UV.Count; ++i) |
| 51 | + _UV.Add(mesh._UV[i]); |
| 52 | + } |
| 53 | + |
| 54 | + public void Copy(UnitMeshInfo mesh) |
| 55 | + { |
| 56 | + atlas = mesh.atlas; |
| 57 | + |
| 58 | + if (_Vertices.Count < mesh._Vertices.Count) |
| 59 | + { |
| 60 | + for (int i = 0; i < _Vertices.Count; ++i) |
| 61 | + _Vertices[i] = mesh._Vertices[i]; |
| 62 | + |
| 63 | + for (int i = _Vertices.Count; i < mesh._Vertices.Count; ++i) |
| 64 | + _Vertices.Add(mesh._Vertices[i]); |
| 65 | + } |
| 66 | + else |
| 67 | + { |
| 68 | + for (int i = 0; i < mesh._Vertices.Count; ++i) |
| 69 | + _Vertices[i] = mesh._Vertices[i]; |
| 70 | + |
| 71 | + for (int i = _Vertices.Count - 1; i >= mesh._Vertices.Count; --i) |
| 72 | + _Vertices.RemoveAt(i); |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | + if (_UV.Count < mesh._UV.Count) |
| 77 | + { |
| 78 | + for (int i = 0; i < _UV.Count; ++i) |
| 79 | + _UV[i] = mesh._UV[i]; |
| 80 | + |
| 81 | + for (int i = _UV.Count; i < mesh._UV.Count; ++i) |
| 82 | + _UV.Add(mesh._UV[i]); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + for (int i = 0; i < mesh._UV.Count; ++i) |
| 87 | + _UV[i] = mesh._UV[i]; |
| 88 | + |
| 89 | + for (int i = _UV.Count - 1; i >= mesh._UV.Count; --i) |
| 90 | + _UV.RemoveAt(i); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + public int VertCnt() |
| 95 | + { |
| 96 | + return _Vertices.Count; |
| 97 | + } |
| 98 | + |
| 99 | + public int UVCnt() |
| 100 | + { |
| 101 | + return _UV.Count; |
| 102 | + } |
| 103 | + |
| 104 | + public void AddVert(Vector3 v) |
| 105 | + { |
| 106 | + _Vertices.Add(v); |
| 107 | + } |
| 108 | + |
| 109 | + public void AddUV(Vector2 uv) |
| 110 | + { |
| 111 | + _UV.Add(uv); |
| 112 | + } |
| 113 | + |
| 114 | + public void SetVertLen(int l) |
| 115 | + { |
| 116 | + if (l > _Vertices.Count) |
| 117 | + { |
| 118 | + for (int i = _Vertices.Count; i < l; ++i) |
| 119 | + { |
| 120 | + _Vertices.Add(Vector3.zero); |
| 121 | + } |
| 122 | + } |
| 123 | + else |
| 124 | + { |
| 125 | + for (int i = _Vertices.Count - 1; i >= l; --i) |
| 126 | + { |
| 127 | + _Vertices.RemoveAt(i); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + public void SetUVLen(int l) |
| 133 | + { |
| 134 | + if (l > _UV.Count) |
| 135 | + { |
| 136 | + for (int i = _UV.Count; i < l; ++i) |
| 137 | + { |
| 138 | + _UV.Add(Vector2.zero); |
| 139 | + } |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + for (int i = _UV.Count - 1; i >= l; --i) |
| 144 | + { |
| 145 | + _UV.RemoveAt(i); |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + public void SetVert(int index, Vector3 v) |
| 151 | + { |
| 152 | + if (index < _Vertices.Count) |
| 153 | + { |
| 154 | + _Vertices[index] = v; |
| 155 | + } |
| 156 | + else |
| 157 | + throw new System.IndexOutOfRangeException(); |
| 158 | + } |
| 159 | + |
| 160 | + public void SetUV(int index, Vector2 v) |
| 161 | + { |
| 162 | + if (index < _UV.Count) |
| 163 | + { |
| 164 | + _UV[index] = v; |
| 165 | + } |
| 166 | + else |
| 167 | + throw new System.IndexOutOfRangeException(); |
| 168 | + } |
| 169 | + |
| 170 | + public Vector3 GetVert(int index) |
| 171 | + { |
| 172 | + if (index < _Vertices.Count) |
| 173 | + { |
| 174 | + return _Vertices[index]; |
| 175 | + } |
| 176 | + throw new System.IndexOutOfRangeException(); |
| 177 | + } |
| 178 | + |
| 179 | + public Vector2 GetUV(int index) |
| 180 | + { |
| 181 | + if (index < _UV.Count) |
| 182 | + { |
| 183 | + return _UV[index]; |
| 184 | + } |
| 185 | + throw new System.IndexOutOfRangeException(); |
| 186 | + } |
| 187 | + |
| 188 | + public bool Equals(UnitMeshInfo other) |
| 189 | + { |
| 190 | + if (atlas != other.atlas || _Vertices.Count != other._Vertices.Count) |
| 191 | + return false; |
| 192 | + |
| 193 | + for (int i = 0; i < _Vertices.Count; i++) |
| 194 | + if (_Vertices[i] != other._Vertices[i]) |
| 195 | + return false; |
| 196 | + |
| 197 | + for (int i = 0; i < _UV.Count; i++) |
| 198 | + if (_UV[i] != other._UV[i]) |
| 199 | + return false; |
| 200 | + return true; |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + public class MeshInfo |
| 205 | + { |
| 206 | + public List<string> _Tag = new List<string>(); |
| 207 | + public List<Vector3> _Vertices = new List<Vector3>(); |
| 208 | + public List<Vector2> _UV = new List<Vector2>(); |
| 209 | + |
| 210 | + public void Clear() |
| 211 | + { |
| 212 | + _Tag.Clear(); |
| 213 | + _Vertices.Clear(); |
| 214 | + _UV.Clear(); |
| 215 | + } |
| 216 | + |
| 217 | + public void Copy(MeshInfo other) |
| 218 | + { |
| 219 | + Clear(); |
| 220 | + _Tag.AddRange(other._Tag); |
| 221 | + _Vertices.AddRange(other._Vertices); |
| 222 | + _UV.AddRange(other._UV); |
| 223 | + } |
| 224 | + |
| 225 | + //比较数据是否一样 |
| 226 | + public bool Equals(MeshInfo _value) |
| 227 | + { |
| 228 | + if (_Tag.Count != _value._Tag.Count || _Vertices.Count != _value._Vertices.Count) |
| 229 | + return false; |
| 230 | + |
| 231 | + for (int i = 0; i < _Tag.Count; i++) |
| 232 | + if (_Tag[i] != _value._Tag[i]) |
| 233 | + return false; |
| 234 | + for (int i = 0; i < _Vertices.Count; i++) |
| 235 | + if (_Vertices[i] != _value._Vertices[i]) |
| 236 | + return false; |
| 237 | + return true; |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | +} |
0 commit comments