Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit cd7b260

Browse files
committed
Fix in issue where the Behaviour Enabled toggle doesn't work in IL2CPP
1 parent ba98627 commit cd7b260

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/Inspectors/GameObjects/ComponentList.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ internal void RefreshComponentList()
8080
text.text = UISyntaxHighlight.ParseFullSyntax(ReflectionHelpers.GetActualType(comp), true);
8181

8282
var toggle = s_compToggles[i];
83+
#if CPP
84+
if (comp.TryCast<Behaviour>() is Behaviour behaviour)
85+
#else
8386
if (comp is Behaviour behaviour)
87+
#endif
8488
{
8589
if (!toggle.gameObject.activeSelf)
8690
toggle.gameObject.SetActive(true);
@@ -130,7 +134,7 @@ internal static void OnCompListPageTurn()
130134
}
131135

132136

133-
#region UI CONSTRUCTION
137+
#region UI CONSTRUCTION
134138

135139
internal void ConstructCompList(GameObject parent)
136140
{
@@ -168,34 +172,34 @@ internal void AddCompListButton()
168172
{
169173
int thisIndex = s_compListTexts.Count;
170174

171-
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_compListContent, new Color(0.07f, 0.07f, 0.07f));
172-
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
173-
btnGroup.childForceExpandWidth = true;
174-
btnGroup.childControlWidth = true;
175-
btnGroup.childForceExpandHeight = false;
176-
btnGroup.childControlHeight = true;
177-
btnGroup.childAlignment = TextAnchor.MiddleLeft;
178-
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
179-
btnLayout.minWidth = 25;
180-
btnLayout.flexibleWidth = 999;
181-
btnLayout.minHeight = 25;
182-
btnLayout.flexibleHeight = 0;
183-
btnGroupObj.AddComponent<Mask>();
175+
GameObject groupObj = UIFactory.CreateHorizontalGroup(s_compListContent, new Color(0.07f, 0.07f, 0.07f));
176+
HorizontalLayoutGroup group = groupObj.GetComponent<HorizontalLayoutGroup>();
177+
group.childForceExpandWidth = true;
178+
group.childControlWidth = true;
179+
group.childForceExpandHeight = false;
180+
group.childControlHeight = true;
181+
group.childAlignment = TextAnchor.MiddleLeft;
182+
LayoutElement groupLayout = groupObj.AddComponent<LayoutElement>();
183+
groupLayout.minWidth = 25;
184+
groupLayout.flexibleWidth = 999;
185+
groupLayout.minHeight = 25;
186+
groupLayout.flexibleHeight = 0;
187+
groupObj.AddComponent<Mask>();
184188

185189
// Behaviour enabled toggle
186190

187-
var toggleObj = UIFactory.CreateToggle(btnGroupObj, out Toggle toggle, out Text toggleText, new Color(0.3f, 0.3f, 0.3f));
191+
var toggleObj = UIFactory.CreateToggle(groupObj, out Toggle toggle, out Text toggleText, new Color(0.3f, 0.3f, 0.3f));
188192
var toggleLayout = toggleObj.AddComponent<LayoutElement>();
189193
toggleLayout.minHeight = 25;
190194
toggleLayout.minWidth = 25;
191195
toggleText.text = "";
192-
toggle.isOn = false;
196+
toggle.isOn = true;
193197
s_compToggles.Add(toggle);
194198
toggle.onValueChanged.AddListener((bool val) => { OnCompToggleClicked(thisIndex, val); });
195199

196200
// Main component button
197201

198-
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
202+
GameObject mainButtonObj = UIFactory.CreateButton(groupObj);
199203
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
200204
mainBtnLayout.minHeight = 25;
201205
mainBtnLayout.flexibleHeight = 0;
@@ -224,6 +228,6 @@ internal void AddCompListButton()
224228
}
225229

226230

227-
#endregion
231+
#endregion
228232
}
229233
}

0 commit comments

Comments
 (0)