From cd7b260ea76eac2c1619f658e2e224c11c551f92 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Tue, 8 Dec 2020 19:42:44 +1100 Subject: [PATCH] Fix in issue where the Behaviour Enabled toggle doesn't work in IL2CPP --- src/Inspectors/GameObjects/ComponentList.cs | 40 +++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Inspectors/GameObjects/ComponentList.cs b/src/Inspectors/GameObjects/ComponentList.cs index 892e694..1adac26 100644 --- a/src/Inspectors/GameObjects/ComponentList.cs +++ b/src/Inspectors/GameObjects/ComponentList.cs @@ -80,7 +80,11 @@ namespace UnityExplorer.Inspectors.GameObjects text.text = UISyntaxHighlight.ParseFullSyntax(ReflectionHelpers.GetActualType(comp), true); var toggle = s_compToggles[i]; +#if CPP + if (comp.TryCast() is Behaviour behaviour) +#else if (comp is Behaviour behaviour) +#endif { if (!toggle.gameObject.activeSelf) toggle.gameObject.SetActive(true); @@ -130,7 +134,7 @@ namespace UnityExplorer.Inspectors.GameObjects } - #region UI CONSTRUCTION +#region UI CONSTRUCTION internal void ConstructCompList(GameObject parent) { @@ -168,34 +172,34 @@ namespace UnityExplorer.Inspectors.GameObjects { int thisIndex = s_compListTexts.Count; - GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_compListContent, new Color(0.07f, 0.07f, 0.07f)); - HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent(); - btnGroup.childForceExpandWidth = true; - btnGroup.childControlWidth = true; - btnGroup.childForceExpandHeight = false; - btnGroup.childControlHeight = true; - btnGroup.childAlignment = TextAnchor.MiddleLeft; - LayoutElement btnLayout = btnGroupObj.AddComponent(); - btnLayout.minWidth = 25; - btnLayout.flexibleWidth = 999; - btnLayout.minHeight = 25; - btnLayout.flexibleHeight = 0; - btnGroupObj.AddComponent(); + GameObject groupObj = UIFactory.CreateHorizontalGroup(s_compListContent, new Color(0.07f, 0.07f, 0.07f)); + HorizontalLayoutGroup group = groupObj.GetComponent(); + group.childForceExpandWidth = true; + group.childControlWidth = true; + group.childForceExpandHeight = false; + group.childControlHeight = true; + group.childAlignment = TextAnchor.MiddleLeft; + LayoutElement groupLayout = groupObj.AddComponent(); + groupLayout.minWidth = 25; + groupLayout.flexibleWidth = 999; + groupLayout.minHeight = 25; + groupLayout.flexibleHeight = 0; + groupObj.AddComponent(); // Behaviour enabled toggle - var toggleObj = UIFactory.CreateToggle(btnGroupObj, out Toggle toggle, out Text toggleText, new Color(0.3f, 0.3f, 0.3f)); + var toggleObj = UIFactory.CreateToggle(groupObj, out Toggle toggle, out Text toggleText, new Color(0.3f, 0.3f, 0.3f)); var toggleLayout = toggleObj.AddComponent(); toggleLayout.minHeight = 25; toggleLayout.minWidth = 25; toggleText.text = ""; - toggle.isOn = false; + toggle.isOn = true; s_compToggles.Add(toggle); toggle.onValueChanged.AddListener((bool val) => { OnCompToggleClicked(thisIndex, val); }); // Main component button - GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj); + GameObject mainButtonObj = UIFactory.CreateButton(groupObj); LayoutElement mainBtnLayout = mainButtonObj.AddComponent(); mainBtnLayout.minHeight = 25; mainBtnLayout.flexibleHeight = 0; @@ -224,6 +228,6 @@ namespace UnityExplorer.Inspectors.GameObjects } - #endregion +#endregion } }