mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
remove useless .gameObject uses
This commit is contained in:
12 files changed
+47
-38
No files matched your search
@@ -72,18 +72,18 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu<CustomPaginableMenu.
|
||||
nextButton.transform.localScale = new Vector3(0.65f, 0.65f, 1);
|
||||
nextButton.name = "RightArrowButton";
|
||||
nextButton.GetComponent<SpriteRenderer>().sprite = MiraAssets.NextButton.LoadAsset();
|
||||
nextButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
nextButton.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
|
||||
var passiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton = nextButton.GetComponent<PassiveButton>();
|
||||
passiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
passiveButton.OnClick.AddListener((UnityAction)customMenu.NextPage);
|
||||
|
||||
var backButton = Object.Instantiate(nextButton, customMenu.transform).gameObject;
|
||||
backButton.transform.localPosition = new Vector3(-1.85f, -2.185f, customMenu.MenuDepth);
|
||||
backButton.name = "LeftArrowButton";
|
||||
backButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
backButton.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
backButton.GetComponent<SpriteRenderer>().flipX = true;
|
||||
var prevPassive = backButton.gameObject.GetComponent<PassiveButton>();
|
||||
var prevPassive = backButton.GetComponent<PassiveButton>();
|
||||
prevPassive.OnClick.AddListener((UnityAction)customMenu.PreviousPage);
|
||||
|
||||
customMenu.PhoneUI.GetChild(0).GetComponent<SpriteRenderer>().material =
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ModifierUiComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
icon = modBg.transform.GetChild(1).GetComponent<SpriteRenderer>();
|
||||
var nameBg = transform.GetChild(1);
|
||||
nameText = nameBg.GetChild(0).GetComponent<TextMeshPro>();
|
||||
descRect = desc.gameObject.GetComponent<RectTransform>();
|
||||
descRect = desc.GetComponent<RectTransform>();
|
||||
|
||||
nameText.font = desc.font = HudManager.Instance.TaskPanel.taskText.font;
|
||||
nameText.fontMaterial = desc.fontMaterial = HudManager.Instance.TaskPanel.taskText.fontMaterial;
|
||||
|
||||
@@ -313,7 +313,7 @@ internal static class GameOptionsMenuPatch
|
||||
};
|
||||
_modIcon = modIconObj.AddComponent<SpriteRenderer>();
|
||||
_modIcon.sprite = MiraAssets.BlankSprite.LoadAsset();
|
||||
_modIcon.material = gamemodeBg.gameObject.GetComponent<SpriteRenderer>().material;
|
||||
_modIcon.material = gamemodeBg.GetComponent<SpriteRenderer>().material;
|
||||
|
||||
var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, modeInfoHolder);
|
||||
gamemodeTextObj.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||
@@ -739,7 +739,7 @@ internal static class GameOptionsMenuPatch
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = $"<size=70%>({"MiraApi.GameSetting.Global.ClickToClose".Translate()})</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
newText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
var boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(7, 0.7f);
|
||||
|
||||
@@ -164,7 +164,7 @@ internal static class GamePresetsTabPatches
|
||||
return;
|
||||
}
|
||||
|
||||
var tmpTranslator = presetTab.PresetDescriptionText.gameObject.GetComponent<TextTranslatorTMP>();
|
||||
var tmpTranslator = presetTab.PresetDescriptionText.GetComponent<TextTranslatorTMP>();
|
||||
if (tmpTranslator)
|
||||
{
|
||||
tmpTranslator.Destroy();
|
||||
@@ -282,7 +282,7 @@ internal static class GamePresetsTabPatches
|
||||
_folderButton.name = "OpenFolderButton";
|
||||
_folderButton.transform.localPosition = new Vector3(3.55f, 1.1f, -2);
|
||||
|
||||
var folderRend = openFolderButton.transform.FindChild("Sprite").gameObject.GetComponent<SpriteRenderer>();
|
||||
var folderRend = openFolderButton.transform.FindChild("Sprite").GetComponent<SpriteRenderer>();
|
||||
folderRend.sprite = MiraAssets.FolderIcon.LoadAsset();
|
||||
folderRend.transform.localScale = new Vector3(0.4f, 0.4f, 1);
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@ internal static class GameSettingMenuPatches
|
||||
}
|
||||
|
||||
// Add Menu State object
|
||||
if (!__instance.gameObject.GetComponent<MenuState>())
|
||||
__instance.gameObject.GetOrAddComponent<MenuState>(out var existed);
|
||||
|
||||
if (!existed)
|
||||
{
|
||||
__instance.gameObject.AddComponent<MenuState>();
|
||||
Info("MenuState component added to GameSettingMenu.");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -72,7 +72,7 @@ public static class LobbyViewPanePatches
|
||||
|
||||
// create modifiers button
|
||||
modifiersTabButton = Object.Instantiate(__instance.rolesTabButton, __instance.rolesTabButton.transform.parent);
|
||||
modifiersTabButton.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
modifiersTabButton.buttonText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
modifiersTabButton.name = "ModifiersTabButton";
|
||||
var pos = modifiersTabButton.transform.localPosition;
|
||||
pos.x = 2.1f;
|
||||
@@ -101,7 +101,7 @@ public static class LobbyViewPanePatches
|
||||
hover.transform.localPosition = new Vector3(0, 0f, 0.3f);
|
||||
hover.sprite = MiraAssets.NextButtonActive.LoadAsset();
|
||||
|
||||
var passiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton = nextButton.GetComponent<PassiveButton>();
|
||||
passiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
passiveButton.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
@@ -123,7 +123,7 @@ public static class LobbyViewPanePatches
|
||||
= backButton.transform.FindChild("Hover").gameObject.GetComponentInChildren<SpriteRenderer>().flipX
|
||||
= true;
|
||||
|
||||
var passiveButton2 = backButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton2 = backButton.GetComponent<PassiveButton>();
|
||||
passiveButton2.OnClick = new Button.ButtonClickedEvent();
|
||||
passiveButton2.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
|
||||
@@ -121,24 +121,24 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var nextButton = Instantiate(Gsm.BackButton, Gsm.BackButton.transform.parent).gameObject;
|
||||
nextButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f);
|
||||
nextButton.name = "RightArrowButton";
|
||||
nextButton.transform.FindChild("Inactive").gameObject.GetComponent<SpriteRenderer>().sprite =
|
||||
nextButton.transform.FindChild("Inactive").GetComponent<SpriteRenderer>().sprite =
|
||||
MiraAssets.NextButton.LoadAsset();
|
||||
nextButton.transform.FindChild("Active").gameObject.GetComponent<SpriteRenderer>().sprite =
|
||||
nextButton.transform.FindChild("Active").GetComponent<SpriteRenderer>().sprite =
|
||||
MiraAssets.NextButtonActive.LoadAsset();
|
||||
nextButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
nextButton.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
|
||||
var nextPassiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var nextPassiveButton = nextButton.GetComponent<PassiveButton>();
|
||||
nextPassiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
nextPassiveButton.OnClick.AddListener((UnityAction)NextMod);
|
||||
|
||||
var previousButton = Instantiate(nextButton, Gsm.BackButton.transform.parent).gameObject;
|
||||
previousButton.transform.localPosition = new Vector3(-4.4209f, 1.5272f, -25f);
|
||||
previousButton.name = "LeftArrowButton";
|
||||
previousButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
previousButton.transform.FindChild("Active").gameObject.GetComponent<SpriteRenderer>().flipX =
|
||||
previousButton.transform.FindChild("Inactive").gameObject.GetComponent<SpriteRenderer>().flipX = true;
|
||||
previousButton.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
previousButton.transform.FindChild("Active").GetComponent<SpriteRenderer>().flipX =
|
||||
previousButton.transform.FindChild("Inactive").GetComponent<SpriteRenderer>().flipX = true;
|
||||
|
||||
var prevPassiveButton = previousButton.gameObject.GetComponent<PassiveButton>();
|
||||
var prevPassiveButton = previousButton.GetComponent<PassiveButton>();
|
||||
prevPassiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
prevPassiveButton.OnClick.AddListener((UnityAction)PreviousMod);
|
||||
|
||||
@@ -149,7 +149,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var mBtn = Instantiate(Gsm.RoleSettingsButton, Gsm.RoleSettingsButton.transform.parent);
|
||||
_largeButtons[MenuButton.Modifiers] = mBtn;
|
||||
mBtn.name = "ModifiersButton";
|
||||
mBtn.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
mBtn.buttonText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
mBtn.buttonText.text = "Modifiers".Translate();
|
||||
mBtn.OnClick = new Button.ButtonClickedEvent();
|
||||
mBtn.OnClick.AddListener(
|
||||
@@ -168,7 +168,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var c1Btn = Instantiate(mBtn, mBtn.transform.parent);
|
||||
_largeButtons[MenuButton.CustomOne] = c1Btn;
|
||||
c1Btn.name = "CustomOneButton";
|
||||
c1Btn.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
c1Btn.buttonText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
c1Btn.OnClick = new Button.ButtonClickedEvent();
|
||||
c1Btn.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
|
||||
@@ -309,7 +309,7 @@ public static class RoleSettingMenuPatches
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = $"<size=70%>{label}</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
newText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
scrollerNum -= 0.422f;
|
||||
|
||||
|
||||
@@ -1575,20 +1575,13 @@ public static class RoleGuidePatches
|
||||
|
||||
private static void SetupPanelButton(MatchInfoRolePanel panel, Action onClick)
|
||||
{
|
||||
var collider = panel.roleIcon.gameObject.GetComponent<BoxCollider2D>();
|
||||
if (!collider)
|
||||
{
|
||||
collider = panel.roleIcon.gameObject.AddComponent<BoxCollider2D>();
|
||||
}
|
||||
var collider = panel.roleIcon.gameObject.GetOrAddComponent<BoxCollider2D>();
|
||||
|
||||
collider.size = new Vector2(0.13f, 0.13f);
|
||||
collider.offset = new Vector2(0, 0);
|
||||
collider.enabled = true;
|
||||
var passiveButton = panel.roleIcon.gameObject.GetComponent<PassiveButton>();
|
||||
if (!passiveButton)
|
||||
{
|
||||
passiveButton = panel.roleIcon.gameObject.AddComponent<PassiveButton>();
|
||||
}
|
||||
|
||||
var passiveButton = panel.roleIcon.gameObject.GetOrAddComponent<PassiveButton>();
|
||||
|
||||
passiveButton.enabled = true;
|
||||
passiveButton.ClickSound = HudManager.Instance.MapButton.ClickSound;
|
||||
|
||||
@@ -239,7 +239,7 @@ public static class CustomRoleManager
|
||||
|
||||
internal static TaskPanelBehaviour CreateRoleTab(ICustomRole role)
|
||||
{
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent<TaskPanelBehaviour>();
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent<TaskPanelBehaviour>();
|
||||
var clonePanel = Object.Instantiate(ogPanel.gameObject, ogPanel.transform.parent);
|
||||
clonePanel.name = "RolePanel";
|
||||
|
||||
@@ -258,7 +258,7 @@ public static class CustomRoleManager
|
||||
internal static void UpdateRoleTab(TaskPanelBehaviour panel, ICustomRole role)
|
||||
{
|
||||
var tabText = panel.tab.gameObject.GetComponentInChildren<TextMeshPro>();
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent<TaskPanelBehaviour>();
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent<TaskPanelBehaviour>();
|
||||
if (tabText.text != role.RoleName)
|
||||
{
|
||||
tabText.text = role.RoleName;
|
||||
|
||||
@@ -843,6 +843,21 @@ public static class Extensions
|
||||
return comp ? comp : go.AddComponent<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a component that is attached to the provided <see cref="GameObject"/>, attaching and returning the component if it wasn't found, and returns a bool that indicates if the component already existed before.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The component type.</typeparam>
|
||||
/// <param name="go">The <see cref="GameObject"/> to get the component from.</param>
|
||||
/// <param name="exists">When this method returns true if the component already existed; otherwise false.</param>
|
||||
/// <returns>The component.</returns>
|
||||
public static T GetOrAddComponent<T>(this GameObject go, out bool exists)
|
||||
where T : Component
|
||||
{
|
||||
var comp = go.GetComponent<T>();
|
||||
exists = comp;
|
||||
return exists ? comp : go.AddComponent<T>();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Attribute.IsDefined(MemberInfo, Type, bool)"/>
|
||||
/// <typeparam name="T">The type of the attribute.</typeparam>
|
||||
/// <returns>true if a custom attribute of type <typeparamref name="T"/> is applied to element; otherwise, false.</returns>
|
||||
|
||||
@@ -304,7 +304,7 @@ public static class Helpers
|
||||
{
|
||||
var prefab = Object.FindObjectOfType<ArrowBehaviour>(true);
|
||||
var arrow = Object.Instantiate(prefab, parent);
|
||||
arrow.image = arrow.gameObject.GetComponent<SpriteRenderer>();
|
||||
arrow.image = arrow.GetComponent<SpriteRenderer>();
|
||||
arrow.image.color = color;
|
||||
arrow.gameObject.layer = 5;
|
||||
arrow.gameObject.SetActive(true);
|
||||
|
||||
Reference in new issue
Block a user