mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-15 07:56:41 +08:00
add AddListener helper for IL2CPP, cleanup some unity extensions
This commit is contained in:
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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>();
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user