mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Create components for achievement reveals
This commit is contained in:
parent
e7f2d9b93a
commit
e0bde5551b
@ -0,0 +1,52 @@
|
|||||||
|
using NewHorizons.AchievementsPlus;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NewHorizons.Components.Achievement
|
||||||
|
{
|
||||||
|
public class AchievementObserveTrigger : MonoBehaviour, IObservable
|
||||||
|
{
|
||||||
|
public string achievementID;
|
||||||
|
public float maxViewDistance = 2f;
|
||||||
|
public float maxViewAngle = 180f;
|
||||||
|
public bool disableColliderOnUnlockAchievement;
|
||||||
|
public bool achievementUnlocked;
|
||||||
|
|
||||||
|
private OWCollider _owCollider;
|
||||||
|
|
||||||
|
private void Reset()
|
||||||
|
{
|
||||||
|
gameObject.layer = LayerMask.NameToLayer("Interactible");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (disableColliderOnUnlockAchievement)
|
||||||
|
{
|
||||||
|
_owCollider = gameObject.GetAddComponent<OWCollider>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Observe(RaycastHit raycastHit, Vector3 raycastOrigin)
|
||||||
|
{
|
||||||
|
float num = Vector3.Angle(raycastHit.point - raycastOrigin, -transform.forward);
|
||||||
|
if (!achievementUnlocked && raycastHit.distance < maxViewDistance && num < maxViewAngle)
|
||||||
|
{
|
||||||
|
if (disableColliderOnUnlockAchievement)
|
||||||
|
{
|
||||||
|
_owCollider.SetActivation(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
AchievementHandler.Earn(achievementID);
|
||||||
|
|
||||||
|
achievementUnlocked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoseFocus() { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
using NewHorizons.AchievementsPlus;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NewHorizons.Components.Achievement
|
||||||
|
{
|
||||||
|
// Modified version of ShipLogFactSnapshotTrigger
|
||||||
|
public class AchievementSnapshotTrigger : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
_visibilityTracker = GetComponent<VisibilityTracker>();
|
||||||
|
GlobalMessenger<ProbeCamera>.AddListener("ProbeSnapshot", new Callback<ProbeCamera>(OnProbeSnapshot));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
GlobalMessenger<ProbeCamera>.RemoveListener("ProbeSnapshot", new Callback<ProbeCamera>(OnProbeSnapshot));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnProbeSnapshot(ProbeCamera probeCamera)
|
||||||
|
{
|
||||||
|
if (_visibilityTracker != null && _visibilityTracker.IsVisibleToProbe(probeCamera.GetOWCamera()) && (_visibilityTracker.transform.position - probeCamera.transform.position).magnitude < maxDistance)
|
||||||
|
{
|
||||||
|
AchievementHandler.Earn(achievementID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string achievementID;
|
||||||
|
public float maxDistance = 200f;
|
||||||
|
|
||||||
|
private VisibilityTracker _visibilityTracker;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
NewHorizons/Components/Achievement/AchievementVolume.cs
Normal file
42
NewHorizons/Components/Achievement/AchievementVolume.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using NewHorizons.AchievementsPlus;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NewHorizons.Components.Achievement
|
||||||
|
{
|
||||||
|
public class AchievementVolume : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_trigger = gameObject.GetRequiredComponent<OWTriggerVolume>();
|
||||||
|
_trigger.OnEntry += OnEntry;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
_trigger.OnEntry -= OnEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEntry(GameObject hitObj)
|
||||||
|
{
|
||||||
|
if ((!_player || hitObj.CompareTag("PlayerDetector")) && (!_probe || hitObj.CompareTag("ProbeDetector")))
|
||||||
|
{
|
||||||
|
AchievementHandler.Earn(achievementID);
|
||||||
|
|
||||||
|
_trigger.OnEntry -= OnEntry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string achievementID;
|
||||||
|
|
||||||
|
private bool _player = true;
|
||||||
|
private bool _probe;
|
||||||
|
|
||||||
|
private OWTriggerVolume _trigger;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user