回答編集履歴

4

文言追加

2019/07/25 02:50

投稿

SISUME
SISUME

スコア12

test CHANGED
@@ -1,4 +1,8 @@
1
1
  調査したところ変換中の最初の一回のバックスペースはUnityに読み込まれていないようです。
2
+
3
+
4
+
5
+ 以下のようにキャレットを強制更新するとなおるようです。
2
6
 
3
7
  ```
4
8
 

3

複数で使えるよう変更

2019/07/25 02:50

投稿

SISUME
SISUME

スコア12

test CHANGED
@@ -60,18 +60,22 @@
60
60
 
61
61
 
62
62
 
63
- //Update is called once per frame
64
-
65
- void Update()
63
+ void LateUpdate()
66
64
 
67
65
  {
68
66
 
69
- //強制的ラベルを即時更新します。キャレットと表示されてい文字列位置再計算します。
67
+ //他のinputfield変換中の文字が表示されるのを防ぐため選択中のみ
70
68
 
69
+ if (T1.GetComponent<InputField>().isFocused == true)
70
+
71
+ {
72
+
73
+ //強制的にラベルを即時更新します。キャレットと表示されている文字列の位置を再計算します。
74
+
71
- T1.ForceLabelUpdate();
75
+ T1.ForceLabelUpdate();
76
+
77
+ }
72
78
 
73
79
  }
74
80
 
75
- }
76
-
77
81
  ```

2

コード編集

2019/03/27 05:30

投稿

SISUME
SISUME

スコア12

test CHANGED
@@ -1,8 +1,10 @@
1
- 調査したところ変換中の最初の一回のバックスペースはUnityに反映されていないようです。
1
+ 調査したところ変換中の最初の一回のバックスペースはUnityに読み込まれていないようです。
2
+
3
+ ```
2
4
 
3
5
 
4
6
 
5
- ```using System.Collections;
7
+ using System.Collections;
6
8
 
7
9
  using System.Reflection;
8
10
 
@@ -36,11 +38,7 @@
36
38
 
37
39
  InputField T1;
38
40
 
39
- string S = "";
41
+
40
-
41
- int pos = 0;
42
-
43
- int Tpos = 0;
44
42
 
45
43
 
46
44
 
@@ -68,292 +66,12 @@
68
66
 
69
67
  {
70
68
 
71
- //日本語入力の全角変換中確定させない状態でInputFieldからフォーカスすと変換中の文字が倍加るバグがあり、倍加させない
69
+ //強制的ラベル即時更新しま。キャレット表示されている文字列の位置を再計算しま
72
70
 
73
- if (Input.GetMouseButtonDown(0))
74
-
75
- {
76
-
77
- if (T1.text != "")
78
-
79
- {
80
-
81
- if (S != T1.text)
82
-
83
- {
84
-
85
- if (S == "")
86
-
87
- {
88
-
89
- if (T1.text.Length > 1 && T1.text.Length % 2 == 0)
90
-
91
- {
92
-
93
- int cun = T1.text.Length;
94
-
95
- if (T1.text.Substring(0, cun / 2) == T1.text.Substring(cun / 2, cun / 2))
96
-
97
- {
98
-
99
- //未確定時
100
-
101
- T1.text = T1.text.Substring(0, cun / 2);
102
-
103
- }
104
-
105
- }
106
-
107
- }
108
-
109
- else
110
-
111
- {
112
-
113
- if (T1.text.Length - Tpos > 1)
114
-
115
- {
116
-
117
-
118
-
119
- if (Tpos + (pos - Tpos) * 2 == T1.text.Length)
120
-
121
- {
122
-
123
-
124
-
125
- string hantei = T1.text.Substring(Tpos);
126
-
127
-
128
-
129
- if (hantei.Length > 1 && hantei.Length % 2 == 0)
130
-
131
- {
132
-
133
- int cun = hantei.Length;
134
-
135
- if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
136
-
137
- {
138
-
139
- //未確定時
140
-
141
- T1.text = T1.text.Substring(0, Tpos) + hantei.Substring(0, cun / 2);
142
-
143
- }
144
-
145
- }
146
-
147
- }
148
-
149
- else
150
-
151
- {
152
-
153
- Debug.Log((T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2);
154
-
155
- int usiro = (T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2;
156
-
157
- int mae = Tpos - usiro;
158
-
159
- string hantei = T1.text.Remove(T1.text.Length - usiro).Substring(mae);
160
-
161
- if (hantei.Length > 1 && hantei.Length % 2 == 0)
162
-
163
- {
164
-
165
- int cun = hantei.Length;
166
-
167
- if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
168
-
169
- {
170
-
171
-
172
-
173
- T1.text = T1.text.Substring(0, mae) + hantei.Substring(0, cun / 2) + T1.text.Substring(T1.text.Length - usiro, usiro);
174
-
175
- }
176
-
177
- }
178
-
179
- }
180
-
181
- }
182
-
183
-
184
-
185
- }
186
-
187
-
188
-
189
- }
190
-
191
- }
192
-
193
- }
194
-
195
- S = T1.text;
196
-
197
- Tpos = T1.text.Length;
198
-
199
- pos = T1.selectionAnchorPosition;
200
-
201
-
202
-
203
- BackspaceRemove();
71
+ T1.ForceLabelUpdate();
204
72
 
205
73
  }
206
74
 
207
-
208
-
209
- //日本語入力の全角変換中に確定させない状態でバックスペース押すと最初の一回読み込まれないバグ対策ベータコード
210
-
211
- void BackspaceRemove()
212
-
213
- {
214
-
215
- if (Input.GetKey(KeyCode.Backspace))
216
-
217
- {
218
-
219
- if (T1.text != "")
220
-
221
- {
222
-
223
- if (S != T1.text)
224
-
225
- {
226
-
227
- if (S == "")
228
-
229
- {
230
-
231
- if (T1.text.Length > 1 && T1.text.Length % 2 == 0)
232
-
233
- {
234
-
235
- int cun = T1.text.Length;
236
-
237
- if (T1.text.Substring(0, cun / 2) == T1.text.Substring(cun / 2, cun / 2))
238
-
239
- {
240
-
241
- //未確定時最後の文字消す
242
-
243
- T1.text = T1.text.Replace(T1.text.Substring(1),"");
244
-
245
- }
246
-
247
- }
248
-
249
- }
250
-
251
- else
252
-
253
- {
254
-
255
- if (T1.text.Length - Tpos > 1)
256
-
257
- {
258
-
259
-
260
-
261
- if (Tpos + (pos - Tpos) * 2 == T1.text.Length)
262
-
263
- {
264
-
265
-
266
-
267
- string hantei = T1.text.Substring(Tpos);
268
-
269
-
270
-
271
- if (hantei.Length > 1 && hantei.Length % 2 == 0)
272
-
273
- {
274
-
275
- int cun = hantei.Length;
276
-
277
- if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
278
-
279
- {
280
-
281
- //未確定時最後の文字消す
282
-
283
- T1.text = T1.text.Replace(T1.text.Substring(1), "");
284
-
285
- }
286
-
287
- }
288
-
289
- }
290
-
291
- else
292
-
293
- {
294
-
295
- Debug.Log((T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2);
296
-
297
- int usiro = (T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2;
298
-
299
- int mae = Tpos - usiro;
300
-
301
- string hantei = T1.text.Remove(T1.text.Length - usiro).Substring(mae);
302
-
303
- if (hantei.Length > 1 && hantei.Length % 2 == 0)
304
-
305
- {
306
-
307
- int cun = hantei.Length;
308
-
309
- if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
310
-
311
- {
312
-
313
-
314
-
315
- //未確定時最後の文字消す
316
-
317
- T1.text = T1.text.Replace(T1.text.Substring(1), "");
318
-
319
- }
320
-
321
- }
322
-
323
- }
324
-
325
- }
326
-
327
-
328
-
329
- }
330
-
331
-
332
-
333
- }
334
-
335
- }
336
-
337
- }
338
-
339
- S = T1.text;
340
-
341
- Tpos = T1.text.Length;
342
-
343
- pos = T1.selectionAnchorPosition;
344
-
345
-
346
-
347
- }
348
-
349
-
350
-
351
-
352
-
353
75
  }
354
76
 
355
-
356
-
357
- コード
358
-
359
77
  ```

1

こーど追加

2019/03/27 02:28

投稿

SISUME
SISUME

スコア12

test CHANGED
@@ -1 +1,359 @@
1
1
  調査したところ変換中の最初の一回のバックスペースはUnityに反映されていないようです。
2
+
3
+
4
+
5
+ ```using System.Collections;
6
+
7
+ using System.Reflection;
8
+
9
+ using UnityEngine;
10
+
11
+ using UnityEngine.UI;
12
+
13
+
14
+
15
+ [RequireComponent(typeof(InputField))]
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ /// <summary>
24
+
25
+ /// inputfieldの文字入力バグ対応
26
+
27
+ ///
28
+
29
+ /// </summary>
30
+
31
+
32
+
33
+ public class Textzenkaku : MonoBehaviour
34
+
35
+ {
36
+
37
+ InputField T1;
38
+
39
+ string S = "";
40
+
41
+ int pos = 0;
42
+
43
+ int Tpos = 0;
44
+
45
+
46
+
47
+
48
+
49
+ void Start()
50
+
51
+ {
52
+
53
+ T1 = gameObject.GetComponent<InputField>();
54
+
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ //Update is called once per frame
66
+
67
+ void Update()
68
+
69
+ {
70
+
71
+ //日本語入力の全角変換中に確定させない状態でInputFieldからフォーカスを外すと変換中の文字が倍加するバグがあり、倍加させない
72
+
73
+ if (Input.GetMouseButtonDown(0))
74
+
75
+ {
76
+
77
+ if (T1.text != "")
78
+
79
+ {
80
+
81
+ if (S != T1.text)
82
+
83
+ {
84
+
85
+ if (S == "")
86
+
87
+ {
88
+
89
+ if (T1.text.Length > 1 && T1.text.Length % 2 == 0)
90
+
91
+ {
92
+
93
+ int cun = T1.text.Length;
94
+
95
+ if (T1.text.Substring(0, cun / 2) == T1.text.Substring(cun / 2, cun / 2))
96
+
97
+ {
98
+
99
+ //未確定時
100
+
101
+ T1.text = T1.text.Substring(0, cun / 2);
102
+
103
+ }
104
+
105
+ }
106
+
107
+ }
108
+
109
+ else
110
+
111
+ {
112
+
113
+ if (T1.text.Length - Tpos > 1)
114
+
115
+ {
116
+
117
+
118
+
119
+ if (Tpos + (pos - Tpos) * 2 == T1.text.Length)
120
+
121
+ {
122
+
123
+
124
+
125
+ string hantei = T1.text.Substring(Tpos);
126
+
127
+
128
+
129
+ if (hantei.Length > 1 && hantei.Length % 2 == 0)
130
+
131
+ {
132
+
133
+ int cun = hantei.Length;
134
+
135
+ if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
136
+
137
+ {
138
+
139
+ //未確定時
140
+
141
+ T1.text = T1.text.Substring(0, Tpos) + hantei.Substring(0, cun / 2);
142
+
143
+ }
144
+
145
+ }
146
+
147
+ }
148
+
149
+ else
150
+
151
+ {
152
+
153
+ Debug.Log((T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2);
154
+
155
+ int usiro = (T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2;
156
+
157
+ int mae = Tpos - usiro;
158
+
159
+ string hantei = T1.text.Remove(T1.text.Length - usiro).Substring(mae);
160
+
161
+ if (hantei.Length > 1 && hantei.Length % 2 == 0)
162
+
163
+ {
164
+
165
+ int cun = hantei.Length;
166
+
167
+ if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
168
+
169
+ {
170
+
171
+
172
+
173
+ T1.text = T1.text.Substring(0, mae) + hantei.Substring(0, cun / 2) + T1.text.Substring(T1.text.Length - usiro, usiro);
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ }
182
+
183
+
184
+
185
+ }
186
+
187
+
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+ S = T1.text;
196
+
197
+ Tpos = T1.text.Length;
198
+
199
+ pos = T1.selectionAnchorPosition;
200
+
201
+
202
+
203
+ BackspaceRemove();
204
+
205
+ }
206
+
207
+
208
+
209
+ //日本語入力の全角変換中に確定させない状態でバックスペース押すと最初の一回読み込まれないバグ対策ベータコード
210
+
211
+ void BackspaceRemove()
212
+
213
+ {
214
+
215
+ if (Input.GetKey(KeyCode.Backspace))
216
+
217
+ {
218
+
219
+ if (T1.text != "")
220
+
221
+ {
222
+
223
+ if (S != T1.text)
224
+
225
+ {
226
+
227
+ if (S == "")
228
+
229
+ {
230
+
231
+ if (T1.text.Length > 1 && T1.text.Length % 2 == 0)
232
+
233
+ {
234
+
235
+ int cun = T1.text.Length;
236
+
237
+ if (T1.text.Substring(0, cun / 2) == T1.text.Substring(cun / 2, cun / 2))
238
+
239
+ {
240
+
241
+ //未確定時最後の文字消す
242
+
243
+ T1.text = T1.text.Replace(T1.text.Substring(1),"");
244
+
245
+ }
246
+
247
+ }
248
+
249
+ }
250
+
251
+ else
252
+
253
+ {
254
+
255
+ if (T1.text.Length - Tpos > 1)
256
+
257
+ {
258
+
259
+
260
+
261
+ if (Tpos + (pos - Tpos) * 2 == T1.text.Length)
262
+
263
+ {
264
+
265
+
266
+
267
+ string hantei = T1.text.Substring(Tpos);
268
+
269
+
270
+
271
+ if (hantei.Length > 1 && hantei.Length % 2 == 0)
272
+
273
+ {
274
+
275
+ int cun = hantei.Length;
276
+
277
+ if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
278
+
279
+ {
280
+
281
+ //未確定時最後の文字消す
282
+
283
+ T1.text = T1.text.Replace(T1.text.Substring(1), "");
284
+
285
+ }
286
+
287
+ }
288
+
289
+ }
290
+
291
+ else
292
+
293
+ {
294
+
295
+ Debug.Log((T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2);
296
+
297
+ int usiro = (T1.text.Length - (Tpos + (pos - Tpos) * 2)) / 2;
298
+
299
+ int mae = Tpos - usiro;
300
+
301
+ string hantei = T1.text.Remove(T1.text.Length - usiro).Substring(mae);
302
+
303
+ if (hantei.Length > 1 && hantei.Length % 2 == 0)
304
+
305
+ {
306
+
307
+ int cun = hantei.Length;
308
+
309
+ if (hantei.Substring(0, cun / 2) == hantei.Substring(cun / 2, cun / 2))
310
+
311
+ {
312
+
313
+
314
+
315
+ //未確定時最後の文字消す
316
+
317
+ T1.text = T1.text.Replace(T1.text.Substring(1), "");
318
+
319
+ }
320
+
321
+ }
322
+
323
+ }
324
+
325
+ }
326
+
327
+
328
+
329
+ }
330
+
331
+
332
+
333
+ }
334
+
335
+ }
336
+
337
+ }
338
+
339
+ S = T1.text;
340
+
341
+ Tpos = T1.text.Length;
342
+
343
+ pos = T1.selectionAnchorPosition;
344
+
345
+
346
+
347
+ }
348
+
349
+
350
+
351
+
352
+
353
+ }
354
+
355
+
356
+
357
+ コード
358
+
359
+ ```