Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit fa928ea

Browse files
committed
[Sample] Fix bugs & Add annotations
1 parent f0662ba commit fa928ea

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

Samples/UIWidgetSample/DragNDrop/CustomInspectorSample.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ enum ETransfrom {
6969
Scale
7070
}
7171

72+
// make custom control of cursor position in TextField.
7273
int oldCursorPosition = 0;
7374

75+
// The decimal point input-and-parse exists problem.
7476
Widget getCardRow(ETransfrom type, bool hasRef) {
7577
var xValue = hasRef
7678
? type == ETransfrom.Position
@@ -79,15 +81,15 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
7981
? this.transformRef.localEulerAngles.x.ToString()
8082
: this.transformRef.localScale.x.ToString()
8183
: "";
82-
84+
// Using individual TextEditingController to control TextField cursor position.
8385
var xValueController = TextEditingController.fromValue(
8486
new TextEditingValue(xValue, TextSelection.collapsed(this.oldCursorPosition))
8587
);
8688

8789
var yValue = hasRef
8890
? type == ETransfrom.Position
8991
? this.transformRef.position.y.ToString()
90-
: type == ETransfrom.Scale
92+
: type == ETransfrom.Rotation
9193
? this.transformRef.localEulerAngles.y.ToString()
9294
: this.transformRef.localScale.y.ToString()
9395
: "";
@@ -139,10 +141,17 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
139141
controller: xValueController,
140142
onChanged: hasRef
141143
? (str) => {
144+
// While the TextField value changed, try to parse and assign to transformRef.
142145
this.setState(() => {
143146
float result = 0;
144147
float.TryParse(str, out result);
145-
this.oldCursorPosition = xValueController.selection.startPos.offset;
148+
if (str == "" || str[0] == '0') {
149+
this.oldCursorPosition = 1;
150+
}
151+
else {
152+
this.oldCursorPosition =
153+
xValueController.selection.startPos.offset;
154+
}
146155

147156
switch (type) {
148157
case ETransfrom.Position:
@@ -188,7 +197,13 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
188197
this.setState(() => {
189198
float result = 0;
190199
float.TryParse(str, out result);
191-
this.oldCursorPosition = yValueController.selection.startPos.offset;
200+
if (str == "" || str[0] == '0') {
201+
this.oldCursorPosition = 1;
202+
}
203+
else {
204+
this.oldCursorPosition =
205+
yValueController.selection.startPos.offset;
206+
}
192207

193208
switch (type) {
194209
case ETransfrom.Position:
@@ -234,8 +249,13 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
234249
this.setState(() => {
235250
float result = 0;
236251
float.TryParse(str, out result);
237-
this.oldCursorPosition = zValueController.selection.startPos.offset;
238-
Debug.Log(result);
252+
if (str == "" || str[0] == '0') {
253+
this.oldCursorPosition = 1;
254+
}
255+
else {
256+
this.oldCursorPosition =
257+
zValueController.selection.startPos.offset;
258+
}
239259

240260
switch (type) {
241261
case ETransfrom.Position:
@@ -292,11 +312,15 @@ public override Widget build(BuildContext context) {
292312
mainAxisSize: MainAxisSize.min,
293313
children: new List<Widget> {
294314
new UnityObjectDetector(
315+
// When receiving a GameObject, get its transfrom.
295316
onRelease: (details) => {
296317
this.setState(() => {
297-
this.objectRef = details.objectReferences[0] as GameObject;
298-
if (this.objectRef) {
299-
this.transformRef = this.objectRef.transform;
318+
var gameObj = details.objectReferences[0] as GameObject;
319+
if (gameObj) {
320+
this.objectRef = gameObj;
321+
if (this.objectRef) {
322+
this.transformRef = this.objectRef.transform;
323+
}
300324
}
301325
});
302326
},

0 commit comments

Comments
 (0)