mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-04 12:32:23 +08:00
add AddListener helper for IL2CPP, cleanup some unity extensions
This commit is contained in:
@ -5,6 +5,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
{
|
||||
@ -210,11 +211,7 @@ namespace UnityExplorer.UI
|
||||
GameObject hideBtnObj = UIFactory.CreateButton(titleBar);
|
||||
|
||||
Button hideBtn = hideBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
hideBtn.onClick.AddListener(new Action(() => { ExplorerCore.ShowMenu = false; }));
|
||||
#else
|
||||
hideBtn.onClick.AddListener(() => { ExplorerCore.ShowMenu = false; });
|
||||
#endif
|
||||
ColorBlock colorBlock = hideBtn.colors;
|
||||
colorBlock.normalColor = new Color(65f / 255f, 23f / 255f, 23f / 255f);
|
||||
colorBlock.pressedColor = new Color(35f / 255f, 10f / 255f, 10f / 255f);
|
||||
@ -266,11 +263,7 @@ namespace UnityExplorer.UI
|
||||
|
||||
page.RefNavbarButton = btn;
|
||||
|
||||
#if CPP
|
||||
btn.onClick.AddListener(new Action(() => { SetPage(page); }));
|
||||
#else
|
||||
btn.onClick.AddListener(() => { SetPage(page); });
|
||||
#endif
|
||||
|
||||
Text text = btnObj.GetComponentInChildren<Text>();
|
||||
text.text = page.Name;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -33,11 +33,7 @@ namespace UnityExplorer.UI.Shared
|
||||
this.sliderScroller = sliderScroller;
|
||||
this.inputField = inputField;
|
||||
|
||||
#if MONO
|
||||
inputField.onValueChanged.AddListener(OnTextChanged);
|
||||
#else
|
||||
inputField.onValueChanged.AddListener(new Action<string>(OnTextChanged));
|
||||
#endif
|
||||
|
||||
inputRect = inputField.GetComponent<RectTransform>();
|
||||
layoutElement = inputField.gameObject.AddComponent<LayoutElement>();
|
||||
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using UnityExplorer.Config;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
|
||||
namespace UnityExplorer.UI.Shared
|
||||
{
|
||||
@ -184,11 +185,9 @@ namespace UnityExplorer.UI.Shared
|
||||
|
||||
GameObject leftBtnObj = UIFactory.CreateButton(m_pageUIHolder, new Color(0.15f, 0.15f, 0.15f));
|
||||
Button leftBtn = leftBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
leftBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Left); }));
|
||||
#else
|
||||
|
||||
leftBtn.onClick.AddListener(() => { TurnPage(Turn.Left); });
|
||||
#endif
|
||||
|
||||
Text leftBtnText = leftBtnObj.GetComponentInChildren<Text>();
|
||||
leftBtnText.text = "◄";
|
||||
LayoutElement leftBtnLayout = leftBtnObj.AddComponent<LayoutElement>();
|
||||
@ -206,11 +205,9 @@ namespace UnityExplorer.UI.Shared
|
||||
|
||||
GameObject rightBtnObj = UIFactory.CreateButton(m_pageUIHolder, new Color(0.15f, 0.15f, 0.15f));
|
||||
Button rightBtn = rightBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
rightBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Right); }));
|
||||
#else
|
||||
|
||||
rightBtn.onClick.AddListener(() => { TurnPage(Turn.Right); });
|
||||
#endif
|
||||
|
||||
Text rightBtnText = rightBtnObj.GetComponentInChildren<Text>();
|
||||
rightBtnText.text = "►";
|
||||
LayoutElement rightBtnLayout = rightBtnObj.AddComponent<LayoutElement>();
|
||||
|
@ -25,15 +25,10 @@ public class SliderScrollbar
|
||||
this.m_slider = slider;
|
||||
this.m_scrollRect = scrollbar.transform.parent.GetComponent<RectTransform>();
|
||||
|
||||
#if MONO
|
||||
this.m_scrollbar.onValueChanged.AddListener(this.OnScrollbarValueChanged);
|
||||
this.m_slider.onValueChanged.AddListener(this.OnSliderValueChanged);
|
||||
#else
|
||||
this.m_scrollbar.onValueChanged.AddListener(new Action<float>(this.OnScrollbarValueChanged));
|
||||
this.m_slider.onValueChanged.AddListener(new Action<float>(this.OnSliderValueChanged));
|
||||
#endif
|
||||
this.m_scrollbar.onValueChanged.AddListener(this.OnScrollbarValueChanged);
|
||||
this.m_slider.onValueChanged.AddListener(this.OnSliderValueChanged);
|
||||
|
||||
this.RefreshVisibility();
|
||||
this.RefreshVisibility();
|
||||
this.m_slider.Set(1f, false);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
//using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI.Shared;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
@ -71,11 +72,7 @@ namespace UnityExplorer.UI
|
||||
// this is because i'm not setting any ColorBlock.selectedColor, because it is commonly stripped.
|
||||
if (selectable is Button button)
|
||||
{
|
||||
#if CPP
|
||||
button.onClick.AddListener(new Action(Deselect));
|
||||
#else
|
||||
button.onClick.AddListener(Deselect);
|
||||
#endif
|
||||
button.onClick.AddListener(Deselect);
|
||||
void Deselect()
|
||||
{
|
||||
button.OnDeselect(null);
|
||||
@ -347,19 +344,12 @@ namespace UnityExplorer.UI
|
||||
toggle = toggleObj.AddComponent<Toggle>();
|
||||
toggle.isOn = true;
|
||||
Toggle toggleComp = toggle;
|
||||
#if CPP
|
||||
toggle.onValueChanged.AddListener(new Action<bool>((bool val) =>
|
||||
|
||||
toggle.onValueChanged.AddListener(Deselect);
|
||||
void Deselect(bool _)
|
||||
{
|
||||
toggleComp.OnDeselect(null);
|
||||
}));
|
||||
#else
|
||||
toggle.onValueChanged.AddListener(Deselect);
|
||||
|
||||
void Deselect(bool _)
|
||||
{
|
||||
toggleComp.OnDeselect(null);
|
||||
}
|
||||
#endif
|
||||
|
||||
Image bgImage = bgObj.AddComponent<Image>();
|
||||
bgImage.type = Image.Type.Sliced;
|
||||
@ -549,11 +539,7 @@ namespace UnityExplorer.UI
|
||||
colors.highlightedColor = new Color(0.25f, 0.45f, 0.25f, 1.0f);
|
||||
itemToggle.colors = colors;
|
||||
|
||||
#if CPP
|
||||
itemToggle.onValueChanged.AddListener(new Action<bool>((bool val) => { itemToggle.OnDeselect(null); }));
|
||||
#else
|
||||
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
|
||||
#endif
|
||||
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
|
||||
Image templateImage = templateObj.AddComponent<Image>();
|
||||
templateImage.type = Image.Type.Sliced;
|
||||
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
|
Reference in New Issue
Block a user