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

@ -4,6 +4,7 @@ using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
using UnityExplorer.UI.Modules;
@ -292,12 +293,7 @@ namespace UnityExplorer.Console
hiddenChild.SetActive(false);
var hiddenText = hiddenChild.AddComponent<Text>();
m_hiddenSuggestionTexts.Add(hiddenText);
#if CPP
btn.onClick.AddListener(new Action(UseAutocompleteButton));
#else
btn.onClick.AddListener(UseAutocompleteButton);
#endif
void UseAutocompleteButton()
{

View File

@ -11,6 +11,7 @@ using UnityExplorer.UI.Modules;
using System.Collections.Generic;
using System.Reflection;
using UnityExplorer.UI.Shared;
using UnityExplorer.Helpers;
namespace UnityExplorer.Console
{
@ -72,11 +73,7 @@ The following helper methods are available:
ConstructUI();
#if CPP
InputField.onValueChanged.AddListener(new Action<string>((string s) => { OnInputChanged(s); }));
#else
this.InputField.onValueChanged.AddListener((string s) => { OnInputChanged(s); });
#endif
InputField.onValueChanged.AddListener((string s) => { OnInputChanged(s); });
}
public void Update()
@ -354,11 +351,7 @@ The following helper methods are available:
// Enable Ctrl+R toggle
var ctrlRToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle ctrlRToggle, out Text ctrlRToggleText);
#if CPP
ctrlRToggle.onValueChanged.AddListener(new Action<bool>(CtrlRToggleCallback));
#else
ctrlRToggle.onValueChanged.AddListener(CtrlRToggleCallback);
#endif
void CtrlRToggleCallback(bool val)
{
EnableCtrlRShortcut = val;
@ -374,11 +367,7 @@ The following helper methods are available:
// Enable Suggestions toggle
var suggestToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle suggestToggle, out Text suggestToggleText);
#if CPP
suggestToggle.onValueChanged.AddListener(new Action<bool>(SuggestToggleCallback));
#else
suggestToggle.onValueChanged.AddListener(SuggestToggleCallback);
#endif
void SuggestToggleCallback(bool val)
{
EnableAutocompletes = val;
@ -395,11 +384,7 @@ The following helper methods are available:
// Enable Auto-indent toggle
var autoIndentToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle autoIndentToggle, out Text autoIndentToggleText);
#if CPP
autoIndentToggle.onValueChanged.AddListener(new Action<bool>(OnIndentChanged));
#else
autoIndentToggle.onValueChanged.AddListener(OnIndentChanged);
#endif
void OnIndentChanged(bool val) => EnableAutoIndent = val;
autoIndentToggleText.text = "Auto-indent";
@ -461,11 +446,7 @@ The following helper methods are available:
btnText.color = Color.white;
// Set compile button callback now that we have the Input Field reference
#if CPP
compileButton.onClick.AddListener(new Action(CompileCallback));
#else
compileButton.onClick.AddListener(CompileCallback);
#endif
void CompileCallback()
{
if (!string.IsNullOrEmpty(inputField.text))

View File

@ -0,0 +1,33 @@
#if CPP
using System;
using UnityEngine.Events;
namespace UnityExplorer.Helpers
{
// Possibly temporary, just so Il2Cpp can do the same style "AddListener" as Mono.
// Just saves me having a preprocessor directive for every single AddListener.
public static class EventHelper
{
public static void AddListener(this UnityEvent action, Action listener)
{
action.AddListener(listener);
}
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
{
action.AddListener(listener);
}
public static void AddListener<T0, T1>(this UnityEvent<T0, T1> action, Action<T0, T1> listener)
{
action.AddListener(listener);
}
public static void AddListener<T0, T1, T2>(this UnityEvent<T0, T1, T2> action, Action<T0, T1, T2> listener)
{
action.AddListener(listener);
}
}
}
#endif

View File

@ -18,12 +18,27 @@ namespace UnityExplorer.Helpers
}
}
public static string ActiveSceneName
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = false)
{
get
var unityObj = obj as Object;
if (obj == null)
{
return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
if (!suppressWarning)
ExplorerCore.LogWarning("The target instance is null!");
return true;
}
else if (obj is Object)
{
if (!unityObj)
{
if (!suppressWarning)
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
return true;
}
}
return false;
}
public static string ToStringLong(this Vector3 vec)

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>();

View File

@ -1,6 +1,7 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
namespace UnityExplorer.Inspectors
@ -22,7 +23,7 @@ namespace UnityExplorer.Inspectors
{
Target = target;
if (IsNullOrDestroyed(Target))
if (Target.IsNullOrDestroyed())
{
Destroy();
return;
@ -45,7 +46,7 @@ namespace UnityExplorer.Inspectors
public virtual void Update()
{
if (IsNullOrDestroyed(Target))
if (Target.IsNullOrDestroyed())
{
Destroy();
return;
@ -84,28 +85,7 @@ namespace UnityExplorer.Inspectors
}
}
public static bool IsNullOrDestroyed(object obj, bool suppressWarning = false)
{
var unityObj = obj as UnityEngine.Object;
if (obj == null)
{
if (!suppressWarning)
ExplorerCore.LogWarning("The target instance is null!");
return true;
}
else if (obj is UnityEngine.Object)
{
if (!unityObj)
{
if (!suppressWarning)
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
return true;
}
}
return false;
}
#region UI CONSTRUCTION
@ -133,11 +113,9 @@ namespace UnityExplorer.Inspectors
tabText.alignment = TextAnchor.MiddleLeft;
tabButton = targetButtonObj.GetComponent<Button>();
#if CPP
tabButton.onClick.AddListener(new Action(() => { InspectorManager.Instance.SetInspectorTab(this); }));
#else
tabButton.onClick.AddListener(() => { InspectorManager.Instance.SetInspectorTab(this); });
#endif
var closeBtnObj = UIFactory.CreateButton(tabGroupObj);
var closeBtnLayout = closeBtnObj.AddComponent<LayoutElement>();
closeBtnLayout.minWidth = 20;
@ -147,11 +125,8 @@ namespace UnityExplorer.Inspectors
closeBtnText.color = new Color(1, 0, 0, 1);
var closeBtn = closeBtnObj.GetComponent<Button>();
#if CPP
closeBtn.onClick.AddListener(new Action(() => { Destroy(); }));
#else
closeBtn.onClick.AddListener(() => { Destroy(); });
#endif
closeBtn.onClick.AddListener(Destroy);
var closeColors = closeBtn.colors;
closeColors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);

View File

@ -45,7 +45,7 @@ namespace UnityExplorer.Inspectors
#endif
UnityEngine.Object unityObj = obj as UnityEngine.Object;
if (InspectorBase.IsNullOrDestroyed(obj))
if (obj.IsNullOrDestroyed())
{
return;
}
@ -289,11 +289,9 @@ namespace UnityExplorer.Inspectors
// var applyBtnObj = UIFactory.CreateButton(timeGroupObj);
// var applyBtn = applyBtnObj.GetComponent<Button>();
//#if MONO
// applyBtn.onClick.AddListener(SetTimeScale);
//#else
// applyBtn.onClick.AddListener(new Action(SetTimeScale));
//#endif
// var applyText = applyBtnObj.GetComponentInChildren<Text>();
// applyText.text = "Apply";
// applyText.fontSize = 14;
@ -323,11 +321,8 @@ namespace UnityExplorer.Inspectors
var inspectText = inspectObj.GetComponentInChildren<Text>();
inspectText.text = "Mouse Inspect";
inspectText.fontSize = 13;
#if MONO
inspectBtn.onClick.AddListener(OnInspectMouseClicked);
#else
inspectBtn.onClick.AddListener(new Action(OnInspectMouseClicked));
#endif
void OnInspectMouseClicked()
{

View File

@ -319,12 +319,8 @@ namespace UnityExplorer.Inspectors.Reflection
var colors = evalButton.colors;
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
evalButton.colors = colors;
#if CPP
evalButton.onClick.AddListener(new Action(OnMainEvaluateButton));
#else
evalButton.onClick.AddListener(OnMainEvaluateButton);
#endif
evalButton.onClick.AddListener(OnMainEvaluateButton);
void OnMainEvaluateButton()
{
if (HasParameters)

View File

@ -48,7 +48,7 @@ namespace UnityExplorer.Inspectors.Reflection
GetLabelForValue();
m_text.text = RichTextValue;
bool shouldShowInspect = !InspectorBase.IsNullOrDestroyed(this.Value, true);
bool shouldShowInspect = !Value.IsNullOrDestroyed(true);
if (m_inspectButton.activeSelf != shouldShowInspect)
m_inspectButton.SetActive(shouldShowInspect);
}
@ -164,14 +164,11 @@ namespace UnityExplorer.Inspectors.Reflection
var inspectText = m_inspectButton.GetComponentInChildren<Text>();
inspectText.text = "Inspect";
var inspectBtn = m_inspectButton.GetComponent<Button>();
#if CPP
inspectBtn.onClick.AddListener(new Action(OnInspectClicked));
#else
inspectBtn.onClick.AddListener(OnInspectClicked);
#endif
void OnInspectClicked()
{
if (!InspectorBase.IsNullOrDestroyed(this.Value))
if (!Value.IsNullOrDestroyed())
InspectorManager.Instance.Inspect(this.Value);
}

View File

@ -472,7 +472,7 @@ namespace UnityExplorer.Inspectors
nameInputLayout.minWidth = 100;
nameInputLayout.minHeight = 25;
var nameInput = nameInputObj.GetComponent<InputField>();
nameInput.onValueChanged.AddListener(new Action<string>((string val) => { FilterMembers(val); }));
nameInput.onValueChanged.AddListener((string val) => { FilterMembers(val); });
m_nameFilterText = nameInput.textComponent;
// membertype filter

View File

@ -8,6 +8,7 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityExplorer.Unstrip;
using UnityExplorer.Helpers;
namespace UnityExplorer.Inspectors
{
@ -319,12 +320,8 @@ namespace UnityExplorer.Inspectors
dropdownLayout.flexibleWidth = 2;
m_sceneDropdownText = m_sceneDropdown.transform.Find("Label").GetComponent<Text>();
#if CPP
m_sceneDropdown.onValueChanged.AddListener(new Action<int>((int val) => { SetSceneFromDropdown(val); }));
#else
m_sceneDropdown.onValueChanged.AddListener((int val) => { SetSceneFromDropdown(val); });
#endif
void SetSceneFromDropdown(int val)
{
string scene = m_sceneDropdown.options[val].text;
@ -353,11 +350,8 @@ namespace UnityExplorer.Inspectors
var colors = backButton.colors;
colors.normalColor = new Color(0.12f, 0.12f, 0.12f);
backButton.colors = colors;
#if CPP
backButton.onClick.AddListener(new Action(() => { SetSceneObjectParent(); }));
#else
backButton.onClick.AddListener(() => { SetSceneObjectParent(); });
#endif
void SetSceneObjectParent()
{
@ -403,12 +397,9 @@ namespace UnityExplorer.Inspectors
inspectButtonLayout.minWidth = 65;
inspectButtonLayout.flexibleWidth = 0;
Button inspectButton = m_mainInspectBtn.GetComponent<Button>();
#if CPP
inspectButton.onClick.AddListener(new Action(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); }));
#else
inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); });
#endif
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_sceneListContent, out SliderScrollbar scroller, new Color(0.1f, 0.1f, 0.1f));
m_sceneListPageHandler = new PageHandler(scroller);
@ -429,11 +420,8 @@ namespace UnityExplorer.Inspectors
var hideLayout = hideButtonObj.AddComponent<LayoutElement>();
hideLayout.minWidth = 20;
hideLayout.minHeight = 20;
#if MONO
hideBtn.onClick.AddListener(OnHide);
#else
hideBtn.onClick.AddListener(new Action(OnHide));
#endif
void OnHide()
{
@ -493,11 +481,8 @@ namespace UnityExplorer.Inspectors
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(() => { SceneListObjectClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { SceneListObjectClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft;
@ -519,11 +504,8 @@ namespace UnityExplorer.Inspectors
inspectColors.normalColor = new Color(0.15f, 0.15f, 0.15f);
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 0.5f);
inspectBtn.colors = inspectColors;
#if CPP
inspectBtn.onClick.AddListener(new Action(() => { InspectorManager.Instance.Inspect(m_sceneShortList[thisIndex]); }));
#else
inspectBtn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_sceneShortList[thisIndex]); });
#endif
}
#endregion

View File

@ -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;

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;
@ -272,11 +264,9 @@ namespace UnityExplorer.UI.Modules
// // 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;

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;

View File

@ -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>();

View File

@ -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>();

View File

@ -25,13 +25,8 @@ 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.RefreshVisibility();
this.m_slider.Set(1f, false);

View File

@ -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
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) =>
{
toggleComp.OnDeselect(null);
}));
#else
toggle.onValueChanged.AddListener(Deselect);
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
Image templateImage = templateObj.AddComponent<Image>();
templateImage.type = Image.Type.Sliced;
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);

View File

@ -323,6 +323,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\EventHelper.cs" />
<Compile Include="Inspectors\MouseInspector.cs" />
<Compile Include="Inspectors\Reflection\CacheObject\CacheEnumerated.cs" />
<Compile Include="Inspectors\Reflection\CacheObject\CacheFactory.cs" />