add AddListener helper for IL2CPP, cleanup some unity extensions

This commit is contained in:
sinaioutlander
2020-11-13 23:14:57 +11:00
parent eedb7dd76f
commit eb693eceb5
23 changed files with 136 additions and 282 deletions

View File

@ -177,11 +177,7 @@ namespace UnityExplorer.Inspectors.GameObjects
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { OnChildListObjectClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { OnChildListObjectClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft;

View File

@ -194,11 +194,7 @@ namespace UnityExplorer.Inspectors.GameObjects
var checkImg = toggleObj.transform.Find("Background/Checkmark").GetComponent<Image>();
checkImg.color = UISyntaxHighlight.Class_Instance.ToColor();
checkImg.color *= 0.66f;
#if CPP
toggle.onValueChanged.AddListener(new Action<bool>((bool val) => { OnCompToggleClicked(thisIndex, val); }));
#else
toggle.onValueChanged.AddListener((bool val) => { OnCompToggleClicked(thisIndex, val); });
#endif
toggleText.text = "";
s_compToggles.Add(toggle);
@ -215,11 +211,7 @@ namespace UnityExplorer.Inspectors.GameObjects
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { OnCompListObjectClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { OnCompListObjectClicked(thisIndex); });
#endif
// Component button text

View File

@ -299,11 +299,7 @@ namespace UnityExplorer.Inspectors.GameObjects
contentGroup.childControlWidth = true;
// ~~ add hide button callback now that we have scroll reference ~~
#if CPP
hideButton.onClick.AddListener(new Action(OnHideClicked));
#else
hideButton.onClick.AddListener(OnHideClicked);
#endif
void OnHideClicked()
{
if (hideText.text == "Show")
@ -368,11 +364,7 @@ namespace UnityExplorer.Inspectors.GameObjects
var applyButtonObj = UIFactory.CreateButton(setParentGroupObj);
var applyButton = applyButtonObj.GetComponent<Button>();
#if CPP
applyButton.onClick.AddListener(new Action(OnSetParentClicked));
#else
applyButton.onClick.AddListener(OnSetParentClicked);
#endif
var applyText = applyButtonObj.GetComponentInChildren<Text>();
applyText.text = "Apply";
var applyLayout = applyButtonObj.AddComponent<LayoutElement>();
@ -446,11 +438,7 @@ namespace UnityExplorer.Inspectors.GameObjects
zRow.SetActive(false);
// add expand callback now that we have group reference
#if CPP
expandButton.onClick.AddListener(new Action(ToggleExpand));
#else
expandButton.onClick.AddListener(ToggleExpand);
#endif
void ToggleExpand()
{
if (xRow.activeSelf)
@ -524,11 +512,7 @@ namespace UnityExplorer.Inspectors.GameObjects
slider.minValue = -2;
slider.maxValue = 2;
slider.value = 0;
#if CPP
slider.onValueChanged.AddListener(new Action<float>((float val) => { OnSliderControlChanged(val, slider, type, vectorValue); }));
#else
slider.onValueChanged.AddListener((float val) => { OnSliderControlChanged(val, slider, type, vectorValue); });
#endif
editor.sliders[(int)vectorValue] = slider;
// input field
@ -563,11 +547,7 @@ namespace UnityExplorer.Inspectors.GameObjects
applyLayout.minWidth = 60;
applyLayout.minHeight = 25;
#if MONO
applyBtn.onClick.AddListener(() => { OnVectorControlInputApplied(type, vectorValue); });
#else
applyBtn.onClick.AddListener(new Action(() => { OnVectorControlInputApplied(type, vectorValue); }));
#endif
return rowObject;
}
@ -584,11 +564,9 @@ namespace UnityExplorer.Inspectors.GameObjects
var instantiateBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
var instantiateBtn = instantiateBtnObj.GetComponent<Button>();
#if MONO
instantiateBtn.onClick.AddListener(InstantiateBtn);
#else
instantiateBtn.onClick.AddListener(new Action(InstantiateBtn));
#endif
var instantiateText = instantiateBtnObj.GetComponentInChildren<Text>();
instantiateText.text = "Instantiate";
instantiateText.fontSize = 14;
@ -607,11 +585,9 @@ namespace UnityExplorer.Inspectors.GameObjects
var dontDestroyBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
var dontDestroyBtn = dontDestroyBtnObj.GetComponent<Button>();
#if MONO
dontDestroyBtn.onClick.AddListener(DontDestroyOnLoadBtn);
#else
dontDestroyBtn.onClick.AddListener(new Action(DontDestroyOnLoadBtn));
#endif
var dontDestroyText = dontDestroyBtnObj.GetComponentInChildren<Text>();
dontDestroyText.text = "Set DontDestroyOnLoad";
dontDestroyText.fontSize = 14;
@ -629,11 +605,9 @@ namespace UnityExplorer.Inspectors.GameObjects
var destroyBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
var destroyBtn = destroyBtnObj.GetComponent<Button>();
#if MONO
destroyBtn.onClick.AddListener(DestroyBtn);
#else
destroyBtn.onClick.AddListener(new Action(DestroyBtn));
#endif
var destroyText = destroyBtnObj.GetComponentInChildren<Text>();
destroyText.text = "Destroy";
destroyText.fontSize = 14;

View File

@ -251,11 +251,9 @@ namespace UnityExplorer.Inspectors
var backButtonObj = UIFactory.CreateButton(m_pathGroupObj);
var backButton = backButtonObj.GetComponent<Button>();
#if CPP
backButton.onClick.AddListener(new Action(OnBackButtonClicked));
#else
backButton.onClick.AddListener(OnBackButtonClicked);
#endif
var backColors = backButton.colors;
backColors.normalColor = new Color(0.15f, 0.15f, 0.15f);
backButton.colors = backColors;
@ -341,11 +339,9 @@ namespace UnityExplorer.Inspectors
var applyNameBtnObj = UIFactory.CreateButton(nameRowObj);
var applyNameBtn = applyNameBtnObj.GetComponent<Button>();
#if CPP
applyNameBtn.onClick.AddListener(new Action(OnApplyNameClicked));
#else
applyNameBtn.onClick.AddListener(OnApplyNameClicked);
#endif
var applyNameText = applyNameBtnObj.GetComponentInChildren<Text>();
applyNameText.text = "Apply";
applyNameText.fontSize = 14;
@ -372,11 +368,8 @@ namespace UnityExplorer.Inspectors
toggleLayout.flexibleWidth = 0;
m_enabledText.text = "Enabled";
m_enabledText.color = Color.green;
#if CPP
m_enabledToggle.onValueChanged.AddListener(new Action<bool>(OnEnableToggled));
#else
m_enabledToggle.onValueChanged.AddListener(OnEnableToggled);
#endif
// layer and scene row
@ -408,11 +401,8 @@ namespace UnityExplorer.Inspectors
layerDropdownLayout.minWidth = 120;
layerDropdownLayout.flexibleWidth = 2000;
layerDropdownLayout.minHeight = 25;
#if CPP
m_layerDropdown.onValueChanged.AddListener(new Action<int>(OnLayerSelected));
#else
m_layerDropdown.onValueChanged.AddListener(OnLayerSelected);
#endif
var scenelabelObj = UIFactory.CreateLabel(sceneLayerRow, TextAnchor.MiddleCenter);
var sceneLabel = scenelabelObj.GetComponent<Text>();