public static int GetPressIndex(TextInfo info, EventCallBack callBack, UserAction action, ref int dock) { dock = 0; if (info == null) { return(0); } if (info.text == "" | info.text == null) { return(0); } IList <UILineInfo> lines = info.lines; if (lines == null) { return(0); } IList <UIVertex> verts = info.vertex; float lx = verts[0].position.x; float ty = verts[0].position.y; float dy = verts[verts.Count - 1].position.y; var pos = callBack.GlobalPosition; var scale = callBack.GlobalScale; float mx = action.CanPosition.x - pos.x; mx *= scale.x; float my = action.CanPosition.y - pos.y; my *= scale.y; int r = 0;//行 if (my < ty) { if (my < dy) { r = lines.Count - 1; } else { for (int i = lines.Count - 1; i >= 0; i--) { if (my < lines[i].topY) { r = i; break; } } } } if (mx > lx) { int s = lines[r].startCharIdx; int index = s * 4; int end = verts.Count - index; float ox = verts[index].position.x; for (int i = 0; i < end; i += 4) { float tx = verts[index].position.x; if (tx <ox | tx> mx) { index -= 4; goto lable; } ox = tx; index += 4; } return(info.visibleCount); lable :; float ax = verts[index].position.x; float bx = verts[index + 2].position.x; float cx = ax + (bx - ax) * 0.5f; index /= 4; if (mx > cx)//靠右 { index++; dock = 1; } return(index); } else { return(lines[r].startCharIdx); } }
static void GetChoiceArea(TextInfo info) { if (info == null) { return; } IList <UILineInfo> lines = info.lines; if (lines == null) { return; } IList <UIVertex> vertex = info.vertex; if (vertex == null) { return; } float top = 0; float down = 0; int end = info.characterCount; int max = lines.Count; int se = max - 1; var vert = info.selectVertex; var color = info.areaColor; var tri = info.selectTri; int s = info.startSelect; int e = info.endSelect; if (e < s) { int t = s; s = e; e = t; } for (int i = 0; i < lines.Count; i++) { int start = lines[i].startCharIdx; if (i < se) { end = lines[i + 1].startCharIdx - 1; } else { end = info.visibleCount; } int state = CommonArea(s, e, ref start, ref end); if (state == 2) { break; } else if (state == 1) { top = lines[i].topY; down = top - lines[i].height; bool warp = end < e ? true : false; var w = GetLineRect(vertex, start, end, warp); int st = vert.Count; var v = new UIVertex(); v.position.x = w.x; v.position.y = down; v.color = color; vert.Add(v); v.position.x = w.x; v.position.y = top; v.color = color; vert.Add(v); v.position.x = w.y; v.position.y = down; v.color = color; vert.Add(v); v.position.x = w.y; v.position.y = top; v.color = color; vert.Add(v); tri.Add(st); tri.Add(st + 1); tri.Add(st + 2); tri.Add(st + 2); tri.Add(st + 1); tri.Add(st + 3); } } }
static void ChangePoint(TextInfo info) { int index = info.startSelect; if (index < 0) { index = 0; } var text = info.buffer.FilterString; if (text == null | text == "") { index = 0; } else if (index > text.Length) { index = text.Length; } Vector3 Point = Vector3.zero; var o = GetIndexPoint(info, index, ref Point); var vert = info.selectVertex; var tri = info.selectTri; vert.Clear(); tri.Clear(); if (o) { float left = Point.x - 0.5f; float right = Point.x + 0.5f; float h = Point.z; h *= 0.4f; float top = Point.y + h; float down = Point.y - h; var v = new UIVertex(); v.position.x = left; v.position.y = down; v.color = info.caretColor; vert.Add(v); v.position.x = left; v.position.y = top; v.color = info.caretColor; vert.Add(v); v.position.x = right; v.position.y = down; v.color = info.caretColor; vert.Add(v); v.position.x = right; v.position.y = top; v.color = info.caretColor; vert.Add(v); } else { var v = new UIVertex(); vert.Add(v); vert.Add(v); vert.Add(v); vert.Add(v); } tri.Add(0); tri.Add(1); tri.Add(2); tri.Add(2); tri.Add(1); tri.Add(3); }