/// <summary> /// 对象反射 /// </summary> /// <param name="t"></param> /// <param name="reflections"></param> /// <param name="mod"></param> public static void GetObject(TempReflection reflections, ModelElement mod) { for (int i = 0; i < reflections.Top; i++) { var m = reflections.All[i]; if (m.name == mod.name) { if (m.FieldType == typeof(ModelElement)) { m.Value = mod; } else if (typeof(EventCallBack).IsAssignableFrom(m.FieldType)) { m.Value = EventCallBack.RegEvent(mod, m.FieldType); } else if (typeof(ModelInital).IsAssignableFrom(m.FieldType)) { var obj = Activator.CreateInstance(m.FieldType) as ModelInital; obj.Initial(mod); m.Value = obj; } else if (typeof(DataConversion).IsAssignableFrom(m.FieldType)) { m.Value = mod.GetComponent(m.FieldType.Name); } reflections.Top--; var j = reflections.Top; var a = reflections.All[j]; reflections.All[i] = a; reflections.All[j] = m; break; } } }
static bool CheckChanged(ModelElement mod) { var stc = mod.GetComponent <ShareTextChildElement>(); if (stc != null) { if (stc.IsChanged) { return(true); } } for (int i = 0; i < mod.child.Count; i++) { var b = CheckChanged(mod.child[i]); if (b) { return(b); } } return(false); }
static void GetChildUVInfo(ModelElement child, ShareText ori, List <UIVertex> vertices, Vector3 position, Quaternion quate, Vector3 scale) { var pos = child.data.localPosition; Vector3 p = quate * pos; Vector3 o = Vector3.zero; o.x = p.x * scale.x; o.y = p.y * scale.y; o.z = p.z * scale.z; o += position; Vector3 s = child.data.localScale; Quaternion q = quate * child.data.localRotation; s.x *= scale.x; s.y *= scale.y; if (child.activeSelf) { var stc = child.GetComponent <ShareTextChildElement>(); if (stc != null) { if (stc.text != null & stc.text != "") { if (stc.IsChanged) { TextGenerationSettings settings = new TextGenerationSettings(); settings.font = ori.font; settings.pivot = child.data.pivot; settings.generationExtents = child.data.sizeDelta; settings.horizontalOverflow = stc.data.horizontalOverflow; settings.verticalOverflow = stc.data.verticalOverflow; settings.resizeTextMaxSize = stc.data.fontSize; settings.resizeTextMinSize = stc.data.fontSize; settings.generateOutOfBounds = stc.data.generateOutOfBounds; settings.resizeTextForBestFit = false; settings.textAnchor = stc.data.textAnchor; settings.fontStyle = stc.data.fontStyle; settings.scaleFactor = 1; settings.richText = stc.data.richText; settings.lineSpacing = stc.data.lineSpacing; settings.fontSize = stc.data.fontSize; settings.color = stc.data.color; settings.alignByGeometry = stc.data.alignByGeometry; stc.buffer = ShareText.CreateEmojiMesh(ori, stc.emojiString, ref settings); stc.IsChanged = false; } } var buf = stc.buffer; if (buf != null) { UIVertex[] vert = new UIVertex[buf.Length]; Array.Copy(buf, vert, buf.Length); for (int i = 0; i < vert.Length; i++) { vert[i].position.x *= s.x; vert[i].position.y *= s.y; vert[i].position = q * vert[i].position + o; } vertices.AddRange(vert); } } for (int i = 0; i < child.child.Count; i++) { GetChildUVInfo(child.child[i], ori, vertices, o, q, s); } } }
public static void GetUVInfo(ModelElement child, List <UIVertex> vertices, List <int> tri, Vector3 position, Quaternion quate, Vector3 scale) { var pos = child.data.localPosition; Vector3 p = quate * pos; Vector3 o = Vector3.zero; o.x = p.x * scale.x; o.y = p.y * scale.y; o.z = p.z * scale.z; o += position; Vector3 s = child.data.localScale; Quaternion q = quate * child.data.localRotation; s.x *= scale.x; s.y *= scale.y; if (child.activeSelf) { var sic = child.GetComponent <ShareImageChildElement>(); if (sic != null) { UIVertex[] buff = sic.buff; float w = child.data.sizeDelta.x; float h = child.data.sizeDelta.y; float left = -child.data.pivot.x * w; float right = left + w * sic.data.fillAmountX; float down = -child.data.pivot.y * h; float top = down + h; right *= s.x; left *= s.x; down *= s.y; top *= s.y; buff[0].position = q * new Vector3(left, down) + o; buff[1].position = q * new Vector3(left, top) + o; buff[2].position = q * new Vector3(right, top) + o; buff[3].position = q * new Vector3(right, down) + o; float tx = sic.data.txtSize.x; float ty = sic.data.txtSize.y; float l = sic.data.rect.x / tx; float d = sic.data.rect.y / ty; float r = l + sic.data.rect.width / tx * sic.data.fillAmountX; float t = d + sic.data.rect.height / ty; buff[0].uv0.x = l; buff[0].uv0.y = d; buff[1].uv0.x = l; buff[1].uv0.y = t; buff[2].uv0.x = r; buff[2].uv0.y = t; buff[3].uv0.x = r; buff[3].uv0.y = d; buff[0].color = sic.data.color; buff[1].color = sic.data.color; buff[2].color = sic.data.color; buff[3].color = sic.data.color; int c = vertices.Count; vertices.AddRange(buff); tri.Add(c); tri.Add(c + 1); tri.Add(c + 2); tri.Add(c + 2); tri.Add(c + 3); tri.Add(c); } for (int i = 0; i < child.child.Count; i++) { GetUVInfo(child.child[i], vertices, tri, o, q, s); } } }