我目前正在将Vectrosity用于我的团结应用程序。我用触摸手势绘制线条。现在我想在创建的行的中间插入一个文本输入字段。这是我的代码:
using UnityEngine.UI;
public class DrawLinesTouch : MonoBehaviour {
public Text _Console;
public Texture2D lineTex;
public float lineWidth = 4.0f;
public Texture2D capTex;
private VectorLine newLine;
private Vector2 previousPosition;
private int sqrMinPixelMove;
//private bool canDraw = false;
private Touch touch;
private int _lineIndex;
public Transform _monCanvas;
public Transform textfieldPrefab;
void Start () {
VectorLine.SetEndCap ("flech", EndCap.Mirror, -1.0f, -1.0f, 1.0f, 1.0f, lineTex, capTex);
_lineIndex = 0;
SetLine ();
}
void SetLine() {
newLine = new VectorLine("line_"+_lineIndex.ToString(), new List<Vector2>(),lineTex, lineWidth, LineType.Discrete, Joins.None);
newLine.endCap = "flech";
_lineIndex++;
}
void Update () {
if (Input.touchCount > 0) {
touch = Input.GetTouch (0);
if (touch.phase == TouchPhase.Began) {
SetLine ();
newLine.points2.Add (touch.position);
if (newLine.points2.Count == 1) {
newLine.points2.Add (Vector2.zero);
_Console.text = newLine.points2.Count.ToString();
}
}
if (newLine.points2.Count >= 2 && touch.phase == TouchPhase.Moved) {
_Console.text = "Moved ?";
newLine.points2[newLine.points2.Count-1] = touch.position;
newLine.Draw();
}
if (touch.phase == TouchPhase.Ended) {
_Console.text = "Fin de la ligne " + newLine.name;
Transform dimValue = (Transform) Instantiate(textfieldPrefab, new Vector2(?????), Quaternion.Euler(0, 0, 0));
dimValue.transform.SetParent (_monCanvas, false);
}
}
}
}
我创建了一个预制件,它是Instantiate(第66行),但不知道如何在行的中间设置文本输入。我想我需要得到绘制线的位置和长度。
有什么想法吗?谢谢!