public CharacterData(char character, UICharInfo charInfo, float fontSize, float scale) { this.character = character; worldSize = new Vector2(charInfo.charWidth, fontSize); localPos = new Vector2(charInfo.cursorPos.x + worldSize.x / 2, charInfo.cursorPos.y - worldSize.y / 2) * scale; worldSize *= scale; }
public Vector2 GetLocalCaretPosition() { TextGenerator gen = m_TextComponent.cachedTextGenerator; int mCaretPosition = caretPosition; if (mCaretPosition >= gen.characters.Count - 1) { mCaretPosition = gen.characters.Count - 1; } else if (mCaretPosition < 0) { mCaretPosition = 0; } if (isFocused) { UICharInfo charInfo = gen.characters[mCaretPosition]; float x = (charInfo.cursorPos.x + charInfo.charWidth) / m_TextComponent.pixelsPerUnit; float y = (charInfo.cursorPos.y) / m_TextComponent.pixelsPerUnit; return(new Vector2(x, y)); } else { return(new Vector2(-465.0f, 95.0f)); } }
private int LineDownCharacterPosition(int originalPos, bool goToLastChar) { if (originalPos >= this.get_cachedInputTextGenerator().get_characterCountVisible()) { return(this.get_text().Length); } UICharInfo character = this.get_cachedInputTextGenerator().get_characters()[originalPos]; int characterLineForWin = this.DetermineCharacterLineForWin(originalPos, this.get_cachedInputTextGenerator()); if (characterLineForWin + 1 >= this.get_cachedInputTextGenerator().get_lineCount()) { if (goToLastChar) { return(this.get_text().Length); } return(originalPos); } int endPositionForWin = SRPG_InputField.GetLineEndPositionForWin(this.get_cachedInputTextGenerator(), characterLineForWin + 1); for (int startCharIdx = (int)this.get_cachedInputTextGenerator().get_lines()[characterLineForWin + 1].startCharIdx; startCharIdx < endPositionForWin; ++startCharIdx) { // ISSUE: explicit reference operation // ISSUE: cast to a reference type // ISSUE: explicit reference operation // ISSUE: explicit reference operation // ISSUE: cast to a reference type // ISSUE: explicit reference operation if ((^ (Vector2&)@this.get_cachedInputTextGenerator().get_characters()[startCharIdx].cursorPos).x >= (^ (Vector2&)@character.cursorPos).x) { return(startCharIdx); } } return(endPositionForWin); }
/// <summary> /// 初始化 角色选择菜单中的角色列表 /// </summary> public void InitCharacterSelect(bool init) { Debug.Log("刷新角色列表"); //删除上一个用户的角色列表 if (init) { foreach (var oldCharUi in uiChars) { Destroy(oldCharUi); } uiChars.Clear(); } //更新现在登入用户的角色列表 for (int i = 0; i < User.Instance.Info.Player.Characters.Count; i++) { GameObject go = Instantiate(uiCharInfo, uicahrListPos); UICharInfo charInfo = go.GetComponent <UICharInfo>(); charInfo.characterInfo = User.Instance.Info.Player.Characters[i];//更新角色ui的信息 Button button = go.GetComponent <Button>(); int idx = i; button.onClick.AddListener(() => OnSelectcharacter(idx)); uiChars.Add(go); go.SetActive(true); } }
void Update() { UICharInfo[] charactersInfo = m_textGenerator.GetCharactersArray(); UILineInfo[] linesInfo = m_textGenerator.GetLinesArray(); Canvas canvas = m_textComp.canvas; if (charactersInfo.Length > 0 && linesInfo.Length > 0 && canvas) { m_underlineGameObject.SetActive(true); UICharInfo firstCharInfo = charactersInfo[0]; UICharInfo lastCharInfo = charactersInfo[charactersInfo.Length - 1]; float height = linesInfo[0].height; // NOTE not so sure about this float factor = 1.0f / canvas.scaleFactor; m_underlineRectTransform.anchoredPosition = new Vector2( factor * (firstCharInfo.cursorPos.x + lastCharInfo.cursorPos.x) / 2.0f, factor * (firstCharInfo.cursorPos.y - height) ); m_underlineRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, factor * Mathf.Abs(firstCharInfo.cursorPos.x - lastCharInfo.cursorPos.x)); m_underlineRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, factor * height / 10.0f); } else { // just hide underline when text is empty m_underlineGameObject.SetActive(false); } }
public Vector2 CursorPositionAt(int relativeIndex) { relativeIndex = Mathf.Clamp(relativeIndex, 0, DisplayedTextGenerator.characterCount - 1); UICharInfo cursorChar = DisplayedTextGenerator.characters[relativeIndex]; return(cursorChar.cursorPos); }
public Vector2 GetLocalCaretPosition() { if (isFocused) { TextGenerator gen = m_TextComponent.cachedTextGenerator; int pos = caretPosition; if (caretPosition > gen.characterCount - 1) { pos = gen.characterCount - 1; } if (caretPosition <= 0) { pos = 1; } try { UICharInfo charInfo = gen.characters[pos]; float x = (charInfo.cursorPos.x + charInfo.charWidth) / m_TextComponent.pixelsPerUnit; float y = (charInfo.cursorPos.y) / m_TextComponent.pixelsPerUnit; return(new Vector2(x, y)); } catch { return(Vector2.zero); } } else { return(Vector2.zero); } }
private int LineUpCharacterPosition(int originalPos, bool goToFirstChar) { if (originalPos > this.get_cachedInputTextGenerator().get_characterCountVisible()) { return(0); } UICharInfo character = this.get_cachedInputTextGenerator().get_characters()[originalPos]; int characterLineForWin = this.DetermineCharacterLineForWin(originalPos, this.get_cachedInputTextGenerator()); if (characterLineForWin <= 0) { if (goToFirstChar) { return(0); } return(originalPos); } int num = this.get_cachedInputTextGenerator().get_lines()[characterLineForWin].startCharIdx - 1; for (int startCharIdx = (int)this.get_cachedInputTextGenerator().get_lines()[characterLineForWin - 1].startCharIdx; startCharIdx < num; ++startCharIdx) { // ISSUE: explicit reference operation // ISSUE: cast to a reference type // ISSUE: explicit reference operation // ISSUE: explicit reference operation // ISSUE: cast to a reference type // ISSUE: explicit reference operation if ((^ (Vector2&)@this.get_cachedInputTextGenerator().get_characters()[startCharIdx].cursorPos).x >= (^ (Vector2&)@character.cursorPos).x) { return(startCharIdx); } } return(num); }
private int GetCharacterIndexFromPosition(Vector2 pos, TextGenerator gen, Text textComponent) { if (gen.lineCount == 0) { return(0); } int startCharIndex = gen.lines[0].startCharIdx; int endCharIndex = GetLineEndPosition(gen, 0); for (int i = startCharIndex; i < endCharIndex; i++) { if (i >= gen.characterCountVisible) { break; } UICharInfo charInfo = gen.characters[i]; Vector2 charPos = charInfo.cursorPos / textComponent.pixelsPerUnit; float distToCharStart = pos.x - charPos.x; float distToCharEnd = charPos.x + (charInfo.charWidth / textComponent.pixelsPerUnit) - pos.x; if (distToCharStart < distToCharEnd) { return(i); } } return(endCharIndex); }
public void InitCharacterSelect(bool init) { panelCreate.SetActive(false); panelSelect.SetActive(true); if (init) { foreach (var old in uiChars) { Destroy(old); } uiChars.Clear(); for (int i = 0; i < User.Instance.Info.Player.Characters.Count; i++) { GameObject go = Instantiate(uiCharInfo, this.uiCharList); UICharInfo chrInfo = go.GetComponent <UICharInfo>(); chrInfo.info = User.Instance.Info.Player.Characters[i]; Button button = go.GetComponent <Button>(); int idx = i; button.onClick.AddListener(() => { OnSelectCharacter(idx); }); uiChars.Add(go); go.SetActive(true); } } }
private Vector2 CursorPosition(TextGenerator gen, int index) { index = Mathf.Clamp(index, 0, gen.characterCount - 1); UICharInfo cursorChar = gen.characters[index]; return(new Vector2(cursorChar.cursorPos.x, cursorChar.cursorPos.y)); }
/// <summary> /// Returns the position in inputfield's rectransform local space, based on character position in text. Pretty neat actually. /// </summary> /// <param name="charNo"></param> /// <returns></returns> Vector2 GetLocalPositionInText(int charNo) { if (myField.isFocused) { TextGenerator gen = myField.textComponent.cachedTextGenerator; if (charNo > gen.characterCount - 1) //do not go over the text length. { charNo = gen.characterCount - 1; } if (charNo > 0) { UICharInfo charInfo = gen.characters[charNo - 1]; float x = (charInfo.cursorPos.x + charInfo.charWidth) / myField.textComponent.pixelsPerUnit + lastCharDist; float y = (charInfo.cursorPos.y) / myField.textComponent.pixelsPerUnit; return(new Vector2(x, y)); } else { UICharInfo charInfo = gen.characters[charNo]; float x = (charInfo.cursorPos.x) / myField.textComponent.pixelsPerUnit; float y = (charInfo.cursorPos.y) / myField.textComponent.pixelsPerUnit; return(new Vector2(x, y)); } } else { return(Vector2.zero); // field not focused, return 0,0 } }
void UpdateImagePosition() { if (!gameObject.activeInHierarchy) { return; } if (images.Count == 0) { return; } Vector2 extents = m_Text.rectTransform.rect.size; var settings = m_Text.GetGenerationSettings(extents); m_Text.cachedTextGeneratorForLayout.PopulateWithErrors(m_Text.text, settings, gameObject); //Debug.Log("EmojiField UpdateImagePosition " + m_Text.alignment.ToString() + " " + m_Text.text); for (int i = 0; i < images.Count; i++) { ImageItem item = images[i]; if (m_Text.cachedTextGeneratorForLayout.characterCount > item.charIndex) { UICharInfo info = m_Text.cachedTextGeneratorForLayout.characters[item.charIndex]; float width = info.charWidth / m_Text.pixelsPerUnit; temp.x = width; temp.y = width; images[i].transform.sizeDelta = temp; //images[i].transform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, width); images[i].transform.localPosition = info.cursorPos / m_Text.pixelsPerUnit; } } }
void MoveChars(int start, int end, Vector2 offest) { for (int index = start; index < end; index++) { UICharInfo charInfo = characters[index]; charInfo.cursorPos += offest; characters[index] = charInfo; int i = index * 6; UIVertex v1 = output[i]; UIVertex v2 = output[i + 1]; UIVertex v3 = output[i + 2]; UIVertex v4 = output[i + 3]; UIVertex v5 = output[i + 4]; UIVertex v6 = output[i + 5]; v1.position += (Vector3)offest; v2.position += (Vector3)offest; v3.position += (Vector3)offest; v4.position += (Vector3)offest; v5.position += (Vector3)offest; v6.position += (Vector3)offest; output[i] = v1; output[i + 1] = v2; output[i + 2] = v3; output[i + 3] = v4; output[i + 4] = v5; output[i + 5] = v6; } }
static int _CreateUICharInfo(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 0); UICharInfo obj = new UICharInfo(); LuaScriptMgr.PushValue(L, obj); return(1); }
protected void GenerateCaret(VertexHelper vbo, Vector2 roundingOffset) { if (!this.m_CaretVisible) { return; } if (this.m_CursorVerts == null) { this.CreateCursorVerts(); } float caretWidth = (float)this.caretWidth; int charPos = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart); TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator; if (cachedTextGenerator == null || cachedTextGenerator.lineCount == 0) { return; } Vector2 zero = Vector2.zero; if (charPos < cachedTextGenerator.characters.Count) { UICharInfo character = cachedTextGenerator.characters[charPos]; zero.x = character.cursorPos.x; } zero.x /= this.m_TextComponent.pixelsPerUnit; if ((double)zero.x > (double)this.m_TextComponent.rectTransform.rect.xMax) { zero.x = this.m_TextComponent.rectTransform.rect.xMax; } int characterLine = this.DetermineCharacterLine(charPos, cachedTextGenerator); zero.y = cachedTextGenerator.lines[characterLine].topY / this.m_TextComponent.pixelsPerUnit; float num = (float)cachedTextGenerator.lines[characterLine].height / this.m_TextComponent.pixelsPerUnit; for (int index = 0; index < this.m_CursorVerts.Length; ++index) { this.m_CursorVerts[index].color = (Color32)this.caretColor; } this.m_CursorVerts[0].position = new Vector3(zero.x, zero.y - num, 0.0f); this.m_CursorVerts[1].position = new Vector3(zero.x + caretWidth, zero.y - num, 0.0f); this.m_CursorVerts[2].position = new Vector3(zero.x + caretWidth, zero.y, 0.0f); this.m_CursorVerts[3].position = new Vector3(zero.x, zero.y, 0.0f); if (roundingOffset != Vector2.zero) { for (int index = 0; index < this.m_CursorVerts.Length; ++index) { UIVertex cursorVert = this.m_CursorVerts[index]; cursorVert.position.x += roundingOffset.x; cursorVert.position.y += roundingOffset.y; } } vbo.AddUIVertexQuad(this.m_CursorVerts); int height = Screen.height; zero.y = (float)height - zero.y; input.compositionCursorPos = zero; }
private Vector2 GetLocalCaretPosition() { TextGenerator gen = m_inputField.textComponent.cachedTextGenerator; UICharInfo charInfo = gen.characters[m_inputField.caretPosition]; float x = (charInfo.cursorPos.x + charInfo.charWidth) / m_inputField.textComponent.pixelsPerUnit; float y = (charInfo.cursorPos.y) / m_inputField.textComponent.pixelsPerUnit; return(new Vector2(x, y)); }
/// <summary> /// 点击选择角色时 角色模型、当前角色更改,选中标记处理 /// </summary> /// <param name="idx"></param> public void OnSelectcharacter(int idx) { this.selectCharacterIdx = idx; var cha = User.Instance.Info.Player.Characters[idx]; Debug.LogFormat("Select Char :[{0}]{1}[{2}]", cha.Id, cha.Name, cha.Class); characterView.CurrentCharacter = (int)cha.Class - 1; for (int i = 0; i < uiChars.Count; i++) { UICharInfo uiCharInfo = uiChars[i].GetComponent <UICharInfo>(); uiCharInfo.IsSelect = idx == i; } }
public void OnSelectCharacter(int idx) { this.selectCharacterIdx = idx; var cha = User.Instance.Info.Player.Characters[idx]; Debug.LogFormat("Select Char:[{0}]{1}[{2}]", cha.Id, cha.Name, cha.Class); //User.Instance.CurrentCharacterInfo = cha; characterView.CurrectCharacter = ((int)cha.Class - 1); for (int i = 0; i < User.Instance.Info.Player.Characters.Count; i++) { UICharInfo ci = this.uiChars[i].GetComponent <UICharInfo>(); ci.Selected = idx == i; } SoundManager.Instance.PlaySound(SoundDefine.SFX_UI_Click); }
public Line(Text text, LineType type, int index) { var characters = text.cachedTextGenerator.characters; var lines = text.cachedTextGenerator.lines[index]; UICharInfo charInfo = characters[lines.startCharIdx]; CanvasScaler cs = text.GetComponentInParent <CanvasScaler>(); float scaleFactor = (Screen.width * cs.referenceResolution[1] / (Screen.height * cs.referenceResolution[0])) >= 1 ? cs.referenceResolution[1] / Screen.height : cs.referenceResolution[0] / Screen.width; position = CalculatePosition(text.alignment, text.rectTransform.rect.width, (charInfo.cursorPos.y - text.cachedTextGenerator.lines[index].height * GetTypeWeight(type)) * scaleFactor); size = new Vector2(GetWidth(characters, lines.startCharIdx, characters.Count - 1, text.rectTransform.rect.width), text.fontSize * 0.1f == 0 ? float.Epsilon : text.fontSize * 0.1f) * scaleFactor; color = text.color; pivot = Text.GetTextAnchorPivot(text.alignment); }
public Vector2 GetLocalCaretPosition() { // if (isFocused) // { TextGenerator gen = m_TextComponent.cachedTextGenerator; UICharInfo charInfo = gen.characters[caretPosition]; float x = (charInfo.cursorPos.x + charInfo.charWidth) / m_TextComponent.pixelsPerUnit; float y = (charInfo.cursorPos.y) / m_TextComponent.pixelsPerUnit; Debug.Log("x=" + x + "y=" + y); return(new Vector2(x, y)); // } // else // return new Vector2(0f, 0f); }
public static int constructor(IntPtr l) { int result; try { UICharInfo uicharInfo = default(UICharInfo); LuaObject.pushValue(l, true); LuaObject.pushValue(l, uicharInfo); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public int RelativeIndexFromPosition(Vector2 pos) { if (DisplayedTextGenerator.lineCount == 0) { return(0); } int line = LineFromPosition(pos, DisplayedTextGenerator); if (line < 0) { return(0); } if (line >= DisplayedTextGenerator.lineCount) { return(DisplayedTextGenerator.characterCountVisible); } int startCharIndex = DisplayedTextGenerator.lines[line].startCharIdx; int endCharIndex = DisplayedTextGenerator.characterCountVisible; for (int i = startCharIndex; i < endCharIndex; i++) { if (i >= DisplayedTextGenerator.characterCountVisible) { break; } UICharInfo charInfo = DisplayedTextGenerator.characters[i]; Vector2 charPos = charInfo.cursorPos / _textComponent.pixelsPerUnit; float distToCharStart = pos.x - charPos.x; float distToCharEnd = charPos.x + (charInfo.charWidth / _textComponent.pixelsPerUnit) - pos.x; if (distToCharStart < distToCharEnd) { return(i); } } return(endCharIndex); }
private Vector2 GetLocalPositionInText(int charNo) { if (!this.myField.isFocused) { return(Vector2.zero); } TextGenerator cachedTextGenerator = this.myField.textComponent.cachedTextGenerator; if (charNo > (cachedTextGenerator.characterCount - 1)) { charNo = cachedTextGenerator.characterCount - 1; } if (charNo > 0) { UICharInfo info = cachedTextGenerator.characters[charNo - 1]; return(new Vector2(((info.cursorPos.x + info.charWidth) / this.myField.textComponent.pixelsPerUnit) + this.lastCharDist, info.cursorPos.y / this.myField.textComponent.pixelsPerUnit)); } UICharInfo info2 = cachedTextGenerator.characters[charNo]; return(new Vector2(info2.cursorPos.x / this.myField.textComponent.pixelsPerUnit, info2.cursorPos.y / this.myField.textComponent.pixelsPerUnit)); }
private int GetCharacterIndexFromPosition(Vector2 pos) { TextGenerator gen = m_TextComponent.cachedTextGenerator; if (gen.lineCount == 0) { return(0); } int line = GetUnclampedCharacterLineFromPosition(pos, gen); if (line < 0) { return(0); } if (line >= gen.lineCount) { return(gen.characterCountVisible); } int startCharIndex = gen.lines[line].startCharIdx; int endCharIndex = GetLineEndPosition(gen, line); for (int i = startCharIndex; i < endCharIndex; i++) { if (i >= gen.characterCountVisible) { break; } UICharInfo charInfo = gen.characters[i]; Vector2 charPos = charInfo.cursorPos / m_TextComponent.pixelsPerUnit; float distToCharStart = pos.x - charPos.x; float distToCharEnd = charPos.x + (charInfo.charWidth / m_TextComponent.pixelsPerUnit) - pos.x; if (distToCharStart < distToCharEnd) { return(i); } } return(endCharIndex); }
static int get_charWidth(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name charWidth"); } else { LuaDLL.luaL_error(L, "attempt to index charWidth on a nil value"); } } UICharInfo obj = (UICharInfo)o; LuaScriptMgr.Push(L, obj.charWidth); return(1); }
static int set_cursorPos(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name cursorPos"); } else { LuaDLL.luaL_error(L, "attempt to index cursorPos on a nil value"); } } UICharInfo obj = (UICharInfo)o; obj.cursorPos = LuaScriptMgr.GetNetObject <Vector2>(L, 3); LuaScriptMgr.SetValueObject(L, 1, obj); return(0); }
static int set_charWidth(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name charWidth"); } else { LuaDLL.luaL_error(L, "attempt to index charWidth on a nil value"); } } UICharInfo obj = (UICharInfo)o; obj.charWidth = (float)LuaScriptMgr.GetNumber(L, 3); LuaScriptMgr.SetValueObject(L, 1, obj); return(0); }
private void RichTextAlignDataSupport(VertexHelper toFill) { if (!supportRichText) { base.OnPopulateMesh(toFill); return; } string changedText = ""; var orignText = m_Text; m_Text = DealWithTextContent(m_Text); changedText = m_Text; base.OnPopulateMesh(toFill); m_Text = orignText; IList <UILineInfo> lines = cachedTextGenerator.lines; IList <UICharInfo> characters = cachedTextGenerator.characters; Rect rectExtents = cachedTextGenerator.rectExtents; //Debug.Log("cachedTextGenerator.characterCountVisible :"+cachedTextGenerator.characterCountVisible); List <UIVertex> stream = new List <UIVertex>(); toFill.GetUIVertexStream(stream); List <AlignData> removeAlignDatas = new List <AlignData>(); for (int i = 0; i < alignDatas.Count; i++) { AlignData alignData = alignDatas[i]; for (int j = 0; j < lines.Count; j++) { UILineInfo lInfo = lines[j]; if (lInfo.startCharIdx <= alignData.startCharIndex) { alignData.lineIndex = j; alignData.lineStartCharIndex = lInfo.startCharIdx; if (j == lines.Count - 1) { if (alignData.startCharIndex > cachedTextGenerator.characterCountVisible) { removeAlignDatas.Add(alignData); } else { alignData.lineEndCharIndex = cachedTextGenerator.characterCountVisible; } } } else { alignData.lineEndCharIndex = lInfo.startCharIdx - 1; break; } } alignDatas[i] = alignData; } List <int> lineList = new List <int>(); for (int i = 0; i < alignDatas.Count; i++) { AlignData alignData = alignDatas[i]; //Debug.Log("alignData.lineIndex :" + alignData.lineIndex); if (lineList.Contains(alignData.lineIndex)) { removeAlignDatas.Add(alignData); continue; } else { lineList.Add(alignData.lineIndex); } } for (int i = 0; i < removeAlignDatas.Count; i++) { alignDatas.Remove(removeAlignDatas[i]); } //Debug.Log("alignDatas :" + alignDatas.Count); for (int i = 0; i < alignDatas.Count; i++) { AlignData alignData = alignDatas[i]; //Debug.Log("characters.Count :" + characters.Count + " stream.Count:" + stream.Count + " alignData.lineEndCharIndex:" + alignData.lineEndCharIndex); if (alignData.lineEndCharIndex >= characters.Count) { continue; } if (alignData.lineStartCharIndex >= characters.Count) { continue; } if ((alignData.lineEndCharIndex * 6) > stream.Count) { continue; } if (alignData.lineStartCharIndex * 6 >= stream.Count) { continue; } if (alignData.alignType == AlignType.Right) { UICharInfo uiChar = characters[alignData.lineEndCharIndex]; float detaMove = rectExtents.width / 2 - uiChar.cursorPos.x - uiChar.charWidth; for (int v = alignData.lineStartCharIndex * 6; v < alignData.lineEndCharIndex * 6; v++) { UIVertex ver = stream[v]; ver.position += new Vector3(detaMove, 0, 0); //ver.color = Color.red; stream[v] = ver; } } else if (alignData.alignType == AlignType.Left) { UICharInfo uiChar = characters[alignData.lineStartCharIndex]; float detaMove = (-rectExtents.width / 2) - uiChar.cursorPos.x; //Debug.Log("LLeft alignData.lineStartCharIndex:" + alignData.lineStartCharIndex + " alignData.lineEndCharIndex:" + alignData.lineEndCharIndex); for (int v = alignData.lineStartCharIndex * 6; v < alignData.lineEndCharIndex * 6; v++) { UIVertex ver = stream[v]; ver.position += new Vector3(detaMove, 0, 0); //ver.color = Color.green; stream[v] = ver; } } else if (alignData.alignType == AlignType.Center) { float lineCharLenth = 0; for (int j = alignData.lineStartCharIndex; j < alignData.lineEndCharIndex; j++) { lineCharLenth += characters[j].charWidth; } float detaMove = -lineCharLenth / 2 - characters[alignData.lineStartCharIndex].cursorPos.x; for (int v = alignData.lineStartCharIndex * 6; v < alignData.lineEndCharIndex * 6; v++) { UIVertex ver = stream[v]; ver.position += new Vector3(detaMove, 0, 0); //ver.color = Color.blue; stream[v] = ver; } } } toFill.AddUIVertexTriangleStream(stream); }
void Update() { if (!AInputField.isFocused) { // m_CachedInputRenderer.SetVertices(null, 0); Caret.gameObject.SetActive(false); return; } else { Caret.gameObject.SetActive(true); } Vector3 tr = Caret.transform.localPosition; // Rect inputRect = AText.rectTransform.rect; // Vector2 extents = inputRect.size; // // // get the text alignment anchor point for the text in local space // Vector2 textAnchorPivot = Text.GetTextAnchorPivot(AText.alignment); // Vector2 refPoint = Vector2.zero; // refPoint.x = Mathf.Lerp(inputRect.xMin, inputRect.xMax, textAnchorPivot.x); // refPoint.y = Mathf.Lerp(inputRect.yMin, inputRect.yMax, textAnchorPivot.y); // // // Ajust the anchor point in screen space // Vector2 roundedRefPoint = AText.PixelAdjustPoint(refPoint); // // // Determine fraction of pixel to offset text mesh. // // This is the rounding in screen space, plus the fraction of a pixel the text anchor pivot is from the corner of the text mesh. // Vector2 roundingOffset = roundedRefPoint - refPoint + Vector2.Scale(extents, textAnchorPivot); // roundingOffset.x = roundingOffset.x - Mathf.Floor(0.5f + roundingOffset.x); // roundingOffset.y = roundingOffset.y - Mathf.Floor(0.5f + roundingOffset.y); TextGenerator gen = AText.cachedTextGenerator; float x = AText.rectTransform.rect.xMin; int count = Mathf.Min(AInputField.caretPosition, gen.characters.Count); //Debug.Log ("AInputField.caretPosition " + count); if (count > 0) { UICharInfo cursorChar = gen.characters[count - 1]; x = (cursorChar.cursorPos.x + cursorChar.charWidth) / AText.pixelsPerUnit; //Caret.localPosition = new Vector3(x, tr.y, tr.z); //Debug.Log ("============ " + (x * XCorrection + Dx)); } else { //Caret.localPosition = new Vector3(x, tr.y, tr.z); } //x /= AText.pixelsPerUnit; // x += roundingOffset.x; Caret.localPosition = new Vector3(x, tr.y, tr.z); // m_CursorVerts[0].position = new Vector3(x, -AHeight, 0.0f); // m_CursorVerts[1].position = new Vector3(x + AWidth, -AHeight, 0.0f); // m_CursorVerts[2].position = new Vector3(x + AWidth, AHeight, 0.0f); // m_CursorVerts[3].position = new Vector3(x, AHeight, 0.0f); // List<UIVertex> vbo = new List<UIVertex>(); // if (roundingOffset != Vector2.zero) // { // for (int i = 0; i < m_CursorVerts.Length; i++) // { // UIVertex uiv = m_CursorVerts[i]; // uiv.position.x += roundingOffset.x; // uiv.position.y += roundingOffset.y; // vbo.Add(uiv); // } // } // m_CachedInputRenderer.SetVertices(vbo.ToArray(), vbo.Count); }