private void ApplyGradientEffect(GradientL tag, IList <UIVertex> verts) { int start = tag.start * 4; int end = Mathf.Min(tag.end * 4 + 4, verts.Count); float min = float.MaxValue; float max = float.MinValue; Vector2 dir = new Vector2(tag.x, tag.y); for (int i = start; i < end; i++) { float dot = Vector3.Dot(verts[i].position, dir); if (dot > max) { max = dot; } else if (dot < min) { min = dot; } } float h = max - min; UIVertex vt; for (int i = start; i < end; i++) { vt = verts[i]; vt.color = Color32.Lerp(tag.from, tag.to, (Vector3.Dot(vt.position, dir) - min) / h); verts[i] = vt; } }
public Tag ToTag() { Tag tag = null; Match match = TagReg.Match(str); if (match.Success) { string type = match.Groups[1].Value; if (!type.StartsWith("#")) { var values = ItemReg.Matches(match.Groups[2].Value); switch (type) { case "shadow": { tag = new Shadow(); break; } case "outline": { tag = new Outline(); break; } case "gradient": { tag = new GradientL(); break; } case "underline": { tag = new Underline(); break; } } if (tag != null) { tag.start = start; tag.end = end; for (int i = 0; i < values.Count; i++) { string name = values[i].Groups[1].Value; string value = values[i].Groups[2].Value; tag.SetValue(name, value); } } } } return(tag); }