Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: UNT0008 (https://github.com/microsoft/Microsoft.Unity.Analyzers/blob/main/doc/UNT0008.md) #187

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Submerged/ExileCutscene/FishController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ public void PlayBite()

public void Closed()
{
targetObj!?.gameObject.SetActive(false);
bubbles!?.Stop();
if (targetObj != null)
{
targetObj.gameObject.SetActive(false);
}
if (bubbles != null)
{
bubbles.Stop();
}
this.StartCoroutine(LerpSpeed(0.5f, _speed, 25f));
}

Expand Down
6 changes: 4 additions & 2 deletions Submerged/Extensions/ComponentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ private static Dictionary<string, Type> RegisteredTypes
}
}

public static T EnsureComponent<T>(this GameObject obj) where T : Component => obj.GetComponent<T>() ?? obj.AddComponent<T>();
public static T EnsureComponent<T>(this GameObject obj) where T : Component =>
obj.TryGetComponent<T>(out T comp) ? comp : obj.AddComponent<T>();

public static Component EnsureComponent(this GameObject obj, Type type) => obj.GetComponent(Il2CppType.From(type)) ?? obj.AddComponent(Il2CppType.From(type));
public static Component EnsureComponent(this GameObject obj, Type type)
=> obj.TryGetComponent(Il2CppType.From(type), out Component comp) ? comp : obj.AddComponent(Il2CppType.From(type));

public static Component AddInjectedComponentByName(this GameObject obj, string typeName) => obj.AddComponent(Il2CppType.From(RegisteredTypes[typeName]));
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ private void Update()
[HideFromIl2Cpp]
private IEnumerator Sparkle()
{
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());

Animator anim = transform.Find("Sparkle").GetComponent<Animator>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ private void Update()
_finished = CheckFinished();

if (!_finished) return;
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,28 @@ private void Update()
{
if (_filling)
{
_audioSource!?.UnPause();
if (_audioSource != null)
{
_audioSource.UnPause();
}
_timer += Time.deltaTime;

if (_timer > 5f)
{
button.onUp.Invoke();
_audioSource!?.Stop();
if (_audioSource != null)
{
_audioSource.Stop();
}
Destroy(button);
}
}
else
{
_audioSource!?.Pause();
if (_audioSource != null)
{
_audioSource.Pause();
}
if (waterAnimation.GetCurrentStateName(0) != "EndWater") waterAnimation.Play("EndWater");
}

Expand All @@ -97,7 +106,10 @@ private void Update()
cap.position = capTarget.position;
capDraggable.forceStop = true;
SoundManager.Instance.PlaySound(minigameProperties.audioClips[1], false);
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public void UpdateCompletedStep(int index)

if (_completedSpecies[0] && _completedSpecies[1] && amClosing == CloseState.None)
{
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ private void Start()
private void CompleteTask()
{
if (amClosing != CloseState.None) return;
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ public IEnumerator CoScaleInwards(Transform self, float source, float target, fl
[HideFromIl2Cpp]
public IEnumerator CoWipeScreen()
{
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());

transform.Find("NewText/EnabledText").gameObject.SetActive(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ private IEnumerator PopBubble()
public IEnumerator Oxygenate()
{
if (amClosing != CloseState.None) yield break;
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());

_bubbleTransform.gameObject.SetActive(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public void Complete()
needle.movementType = NeedleBehaviour.Movement.RandomBounce;

Transform valve = transform.Find("Valve");
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
this.StartCoroutine(SpinItem(valve));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public void Update()
{
circutBreaker.enabled = false;
}

MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
}
Expand Down
27 changes: 20 additions & 7 deletions Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ private void Start()
this.StartCoroutine(CoOnMouseDown(clickableSprite.gameObject));
};

transform.Find("Books/Benthic Beasts")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book02_Lounge);
transform.Find("Books/Ichthyologist Weekly")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book06_Lounge);
transform.Find("Books/Octopus Digest")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book11_Lounge);
transform.Find("Books/Kelper Worms")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book08_Medical);
transform.Find("Books/Nautical Nonsense")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book10_Medical);
transform.Find("Books/Sea Slugs & You!")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book13_Medical);
SetText("Books/Benthic Beasts", Tasks.ReshelveBooks_Book02_Lounge);
SetText("Books/Ichthyologist Weekly", Tasks.ReshelveBooks_Book06_Lounge);
SetText("Books/Octopus Digest", Tasks.ReshelveBooks_Book11_Lounge);
SetText("Books/Kelper Worms", Tasks.ReshelveBooks_Book08_Medical);
SetText("Books/Nautical Nonsense", Tasks.ReshelveBooks_Book10_Medical);
SetText("Books/Sea Slugs & You!", Tasks.ReshelveBooks_Book13_Medical);
}

[HideFromIl2Cpp]
private IEnumerator CoOnMouseDown(GameObject obj)
{
minigame.Task.customData[minigame.ConsoleId + 2] = 1;
minigame.Task!?.NextStep();
if (minigame.Task != null)
{
minigame.Task.NextStep();
}

SpriteRenderer rend = obj.GetComponent<SpriteRenderer>();
TextMeshPro text = obj.GetComponentInChildren<TextMeshPro>();
Expand All @@ -65,4 +68,14 @@ private IEnumerator CoOnMouseDown(GameObject obj)

minigame.minigameProperties.CloseTask();
}

private void SetText(string objName, string targetText)
{
Transform targetTrans = transform.Find(objName);
if (targetTrans == null)
{
return;
}
targetTrans.GetComponentInChildren<TextMeshPro>().SetText(targetText);
}
}
59 changes: 36 additions & 23 deletions Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,40 @@ private void Start()
draggable.onUp += () => OnDragEnd(rend);
}

books.Find("Benthic Beasts")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book02_Lounge);
books.Find("Ichthyologist Weekly")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book06_Lounge);
books.Find("Octopus Digest")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book11_Lounge);
books.Find("Kelper Worms")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book08_Medical);
books.Find("Nautical Nonsense")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book10_Medical);
books.Find("Sea Slugs & You!")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book13_Medical);
SetText(books, "Benthic Beasts", Tasks.ReshelveBooks_Book02_Lounge);
SetText(books, "Ichthyologist Weekly", Tasks.ReshelveBooks_Book06_Lounge);
SetText(books, "Octopus Digest", Tasks.ReshelveBooks_Book11_Lounge);
SetText(books, "Kelper Worms", Tasks.ReshelveBooks_Book08_Medical);
SetText(books, "Nautical Nonsense", Tasks.ReshelveBooks_Book10_Medical);
SetText(books, "Sea Slugs & You!", Tasks.ReshelveBooks_Book13_Medical);

Transform drop = transform.Find("DropZoneIndicators");
drop.Find("Benthic Beasts")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book02_Lounge);
drop.Find("Ichthyologist Weekly")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book06_Lounge);
drop.Find("Octopus Digest")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book11_Lounge);
drop.Find("Kelper Worms")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book08_Medical);
drop.Find("Nautical Nonsense")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book10_Medical);
drop.Find("Sea Slugs & You!")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book13_Medical);

transform.Find("Background/A")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book01);
transform.Find("Background/C")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book03);
transform.Find("Background/E")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book04);
transform.Find("Background/F")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book05);
transform.Find("Background/J")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book07);
transform.Find("Background/M")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book09);
transform.Find("Background/P")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book12);
transform.Find("Background/V")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book14);
transform.Find("Background/W")?.GetComponentInChildren<TextMeshPro>().SetText(Tasks.ReshelveBooks_Book15);
SetText(drop, "Benthic Beasts", Tasks.ReshelveBooks_Book02_Lounge);
SetText(drop, "Ichthyologist Weekly", Tasks.ReshelveBooks_Book06_Lounge);
SetText(drop, "Octopus Digest", Tasks.ReshelveBooks_Book11_Lounge);
SetText(drop, "Kelper Worms", Tasks.ReshelveBooks_Book08_Medical);
SetText(drop, "Nautical Nonsense", Tasks.ReshelveBooks_Book10_Medical);
SetText(drop, "Sea Slugs & You!", Tasks.ReshelveBooks_Book13_Medical);

SetText(transform, "Background/A", Tasks.ReshelveBooks_Book01);
SetText(transform, "Background/C", Tasks.ReshelveBooks_Book03);
SetText(transform, "Background/E", Tasks.ReshelveBooks_Book04);
SetText(transform, "Background/F", Tasks.ReshelveBooks_Book05);
SetText(transform, "Background/J", Tasks.ReshelveBooks_Book07);
SetText(transform, "Background/M", Tasks.ReshelveBooks_Book09);
SetText(transform, "Background/P", Tasks.ReshelveBooks_Book12);
SetText(transform, "Background/V", Tasks.ReshelveBooks_Book14);
SetText(transform, "Background/W", Tasks.ReshelveBooks_Book15);
}

private void Update()
{
if (remainingBooks == 0)
{
minigame.Task!?.NextStep();
if (minigame.Task != null)
{
minigame.Task.NextStep();
}
minigame.StartCoroutine(minigame.CoStartClose());
remainingBooks = -1;
}
Expand Down Expand Up @@ -147,4 +150,14 @@ private void TryClose()
if (_stopClose) return;
minigame.minigameProperties.CloseTask();
}

private void SetText(Transform search, string objName, string targetText)
{
Transform targetTrans = search.Find(objName);
if (targetTrans == null)
{
return;
}
targetTrans.GetComponentInChildren<TextMeshPro>().SetText(targetText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public override void Complete()
{
isComplete = true;
PlayerControl.LocalPlayer.RemoveTask(this);
FindObjectOfType<OxygenSabotageMinigame>()?.Close();
OxygenSabotageMinigame minigame = FindObjectOfType<OxygenSabotageMinigame>();
if (minigame != null)
{
minigame.Close();
}
}

public override void OnRemove() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ private void Start()
if (CheckBoxes())
{
_forceClose = true;
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ private void Start()
_button.onDown += () =>
{
if (!_task.visible || _finished) return;
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose(1f));
_finished = true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ private void Update()
{
text.text = Tasks.StartSubmersible_Status_Active;
_audio.Stop();
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}
}
Expand Down Expand Up @@ -181,7 +184,10 @@ public void EnableEverything()

for (int i = 0; i < 3; i++)
{
switches.GetChild(i).Find("Off/OffSwitch").GetComponent<SpriteRenderer>()?.material.SetFloat("_Outline", 1);
if (switches.GetChild(i).Find("Off/OffSwitch").TryGetComponent(out SpriteRenderer rend))
{
rend.material.SetFloat("_Outline", 1);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ private void Update()
{
Color32 col = new(30, 150, 0, 255);
_statusText.text = string.Format(Tasks.SteadyHeartbeat_Status, $"<color=#{col.r:X2}{col.g:X2}{col.b:X2}{col.a:X2}>{Tasks.SteadyHeartbeat_Status_Stable}</color>");
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ private void Update()
if (percent >= 100)
{
if (amClosing != CloseState.None) return;
MyNormTask!?.NextStep();
if (MyNormTask != null)
{
MyNormTask.NextStep();
}
StartCoroutine(CoStartClose());

foreach (TextMeshPro t in _textMeshPros)
Expand Down