回答編集履歴
3
追記です。
test
CHANGED
@@ -49,3 +49,61 @@
|
|
49
49
|
}
|
50
50
|
|
51
51
|
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
追記です。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```C#
|
62
|
+
|
63
|
+
using UnityEngine;
|
64
|
+
|
65
|
+
using UnityEngine.UI;
|
66
|
+
|
67
|
+
using UnityEngine.EventSystems;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
public class ForceSelector : MonoBehaviour{
|
72
|
+
|
73
|
+
//自動選択されるボタン
|
74
|
+
|
75
|
+
public Selectable firstSelected;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
void Start(){
|
80
|
+
|
81
|
+
if(firstSelected == null){
|
82
|
+
|
83
|
+
firstSelected = GetComponentInChildren<Selectable>();
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
void OnEnable(){
|
92
|
+
|
93
|
+
ForceSelect();
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
public void ForceSelect(){
|
100
|
+
|
101
|
+
//firstSelectedを選択
|
102
|
+
|
103
|
+
EventSystem.current.SetSelectedGameObject(firstSelected.gameObject);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
```
|
2
コメントを入れておきます。
test
CHANGED
@@ -11,6 +11,8 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
public class ForceSelector : MonoBehaviour{
|
14
|
+
|
15
|
+
//自動選択されるボタン
|
14
16
|
|
15
17
|
public Selectable firstSelected;
|
16
18
|
|
@@ -26,9 +28,11 @@
|
|
26
28
|
|
27
29
|
}
|
28
30
|
|
29
|
-
|
31
|
+
|
30
32
|
|
31
33
|
void Update(){
|
34
|
+
|
35
|
+
//EventSystemが何も選択していない場合、firstSelectedを選択
|
32
36
|
|
33
37
|
if (EventSystem.current.currentSelectedGameObject == null){
|
34
38
|
|
1
これいらんわ
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
if(firstSelected == null){
|
22
22
|
|
23
|
-
firstSelected = GetComponentInChildren<Selectable>(
|
23
|
+
firstSelected = GetComponentInChildren<Selectable>();
|
24
24
|
|
25
25
|
}
|
26
26
|
|