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

@ -8,6 +8,7 @@ using UnityExplorer.Config;
using UnityExplorer.UI.Shared;
using System.IO;
using System.Linq;
using UnityExplorer.Helpers;
namespace UnityExplorer.UI.Modules
{
@ -184,11 +185,8 @@ namespace UnityExplorer.UI.Modules
hideBtnText.text = "Hide";
var hideButton = hideButtonObj.GetComponent<Button>();
#if CPP
hideButton.onClick.AddListener(new Action(HideCallback));
#else
hideButton.onClick.AddListener(HideCallback);
#endif
void HideCallback()
{
if (logAreaObj.activeSelf)
@ -221,12 +219,8 @@ namespace UnityExplorer.UI.Modules
clearBtnText.text = "Clear";
var clearButton = clearButtonObj.GetComponent<Button>();
#if CPP
clearButton.onClick.AddListener(new Action(ClearCallback));
#else
clearButton.onClick.AddListener(ClearCallback);
#endif
clearButton.onClick.AddListener(ClearCallback);
void ClearCallback()
{
m_textInput.text = "";
@ -244,11 +238,9 @@ namespace UnityExplorer.UI.Modules
// Unity log toggle
var unityToggleObj = UIFactory.CreateToggle(bottomBarObj, out Toggle unityToggle, out Text unityToggleText);
#if CPP
unityToggle.onValueChanged.AddListener(new Action<bool>(ToggleLogUnity));
#else
unityToggle.onValueChanged.AddListener(ToggleLogUnity);
#endif
unityToggle.isOn = LogUnity;
unityToggleText.text = "Print Unity Debug?";
unityToggleText.alignment = TextAnchor.MiddleLeft;
@ -269,33 +261,31 @@ namespace UnityExplorer.UI.Modules
pos.y = -8;
unityToggleRect.localPosition = pos;
// // Save to disk button
// // Save to disk button
// var saveToDiskObj = UIFactory.CreateToggle(bottomBarObj, out Toggle diskToggle, out Text diskToggleText);
//#if CPP
// diskToggle.onValueChanged.AddListener(new Action<bool>(ToggleDisk));
//#else
// diskToggle.onValueChanged.AddListener(ToggleDisk);
//#endif
// diskToggle.isOn = SaveToDisk;
// diskToggleText.text = "Save logs to 'Mods\\UnityExplorer\\Logs'?";
// diskToggleText.alignment = TextAnchor.MiddleLeft;
// var saveToDiskObj = UIFactory.CreateToggle(bottomBarObj, out Toggle diskToggle, out Text diskToggleText);
// void ToggleDisk(bool val)
// {
// SaveToDisk = val;
// ModConfig.Instance.Save_Logs_To_Disk = val;
// ModConfig.SaveSettings();
// }
// diskToggle.onValueChanged.AddListener(ToggleDisk);
// var diskToggleLayout = saveToDiskObj.AddComponent<LayoutElement>();
// diskToggleLayout.minWidth = 340;
// diskToggleLayout.flexibleWidth = 0;
// diskToggle.isOn = SaveToDisk;
// diskToggleText.text = "Save logs to 'Mods\\UnityExplorer\\Logs'?";
// diskToggleText.alignment = TextAnchor.MiddleLeft;
// var saveToDiskRect = saveToDiskObj.transform.Find("Background").GetComponent<RectTransform>();
// pos = unityToggleRect.localPosition;
// pos.y = -8;
// saveToDiskRect.localPosition = pos;
// void ToggleDisk(bool val)
// {
// SaveToDisk = val;
// ModConfig.Instance.Save_Logs_To_Disk = val;
// ModConfig.SaveSettings();
// }
// var diskToggleLayout = saveToDiskObj.AddComponent<LayoutElement>();
// diskToggleLayout.minWidth = 340;
// diskToggleLayout.flexibleWidth = 0;
// var saveToDiskRect = saveToDiskObj.transform.Find("Background").GetComponent<RectTransform>();
// pos = unityToggleRect.localPosition;
// pos.y = -8;
// saveToDiskRect.localPosition = pos;
#endregion
}

View File

@ -5,6 +5,7 @@ using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
using UnityExplorer.Helpers;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip;
@ -108,11 +109,8 @@ namespace UnityExplorer.UI.Modules
var applyColors = applyBtn.colors;
applyColors.normalColor = new Color(0.3f, 0.7f, 0.3f);
applyBtn.colors = applyColors;
#if MONO
applyBtn.onClick.AddListener(OnApply);
#else
applyBtn.onClick.AddListener(new Action(OnApply));
#endif
}
internal void ConstructKeycodeOpt(GameObject parent)

View File

@ -492,12 +492,6 @@ namespace UnityExplorer.UI.Modules
customTypeLayout.flexibleHeight = 0;
m_customTypeInput = customTypeObj.GetComponent<InputField>();
m_customTypeInput.placeholder.gameObject.GetComponent<Text>().text = "eg. UnityEngine.Texture2D, etc...";
//m_customTypeInput.onFocusSelectAll = true;
//#if MONO
// m_customTypeInput.onSelect.AddListener((string val) => { OnContextButtonClicked(SearchContext.Custom); });
//#else
// m_customTypeInput.onSelect.AddListener(new Action<string>((string val) => { OnContextButtonClicked(SearchContext.Custom); }));
//#endif
// search input
@ -558,11 +552,7 @@ namespace UnityExplorer.UI.Modules
sceneDropLayout.minWidth = 220;
sceneDropLayout.minHeight = 25;
#if MONO
m_sceneDropdown.onValueChanged.AddListener(OnSceneDropdownChanged);
#else
m_sceneDropdown.onValueChanged.AddListener(new Action<int>(OnSceneDropdownChanged));
#endif
void OnSceneDropdownChanged(int value)
{
if (value < 4)
@ -598,11 +588,7 @@ namespace UnityExplorer.UI.Modules
childDrop.options.Add(new Dropdown.OptionData { text = "Root Objects Only" });
childDrop.options.Add(new Dropdown.OptionData { text = "Children Only" });
#if MONO
childDrop.onValueChanged.AddListener(OnChildDropdownChanged);
#else
childDrop.onValueChanged.AddListener(new Action<int>(OnChildDropdownChanged));
#endif
void OnChildDropdownChanged(int value)
{
m_childFilter = (ChildFilter)value;
@ -617,11 +603,8 @@ namespace UnityExplorer.UI.Modules
searchBtnLayout.minHeight = 30;
searchBtnLayout.flexibleHeight = 0;
var searchBtn = searchBtnObj.GetComponent<Button>();
#if MONO
searchBtn.onClick.AddListener(OnUnitySearchClicked);
#else
searchBtn.onClick.AddListener(new Action(OnUnitySearchClicked));
#endif
}
internal void AddContextButton(GameObject parent, string label, SearchContext context, float width = 110)
@ -632,11 +615,7 @@ namespace UnityExplorer.UI.Modules
m_contextButtons.Add(context, btn);
#if MONO
btn.onClick.AddListener(() => { OnContextButtonClicked(context); });
#else
btn.onClick.AddListener(new Action(() => { OnContextButtonClicked(context); }));
#endif
var btnLayout = btnObj.AddComponent<LayoutElement>();
btnLayout.minHeight = 25;
@ -719,11 +698,8 @@ namespace UnityExplorer.UI.Modules
mainColors.normalColor = new Color(0.1f, 0.1f, 0.1f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { OnResultClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { OnResultClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft;