mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
shrine and compass
This commit is contained in:
parent
7e0a9b1e76
commit
0089a83d47
77
NewHorizons/Components/Quantum/NHQuantumShrine.cs
Normal file
77
NewHorizons/Components/Quantum/NHQuantumShrine.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using NewHorizons.Utility.OWML;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components.Quantum
|
||||
{
|
||||
public class NHQuantumShrine : QuantumStructure
|
||||
{
|
||||
[SerializeField]
|
||||
public NomaiGateway gate;
|
||||
|
||||
[SerializeField]
|
||||
public MeshRenderer floorRenderer;
|
||||
|
||||
[SerializeField]
|
||||
public Material[] floorMaterials = new Material[0];
|
||||
|
||||
[SerializeField]
|
||||
public OWRenderer exteriorRenderer;
|
||||
|
||||
[SerializeField]
|
||||
public NomaiInterfaceOrb[] childOrbs = new NomaiInterfaceOrb[0];
|
||||
|
||||
[SerializeField]
|
||||
public OWLightController exteriorLightController;
|
||||
|
||||
private bool _orbsLocked;
|
||||
|
||||
public override void OnQuantumPlanetStateChanged(int state)
|
||||
{
|
||||
if (exteriorRenderer != null)
|
||||
{
|
||||
exteriorRenderer.SetActivation(state != -1);
|
||||
}
|
||||
if (!_orbsLocked && state == -1)
|
||||
{
|
||||
_orbsLocked = true;
|
||||
foreach (var childOrb in childOrbs)
|
||||
{
|
||||
childOrb.AddLock();
|
||||
}
|
||||
}
|
||||
else if (_orbsLocked && state != -1)
|
||||
{
|
||||
_orbsLocked = false;
|
||||
foreach (var childOrb in childOrbs)
|
||||
{
|
||||
childOrb.RemoveLock();
|
||||
}
|
||||
}
|
||||
if (floorRenderer != null && state != -1)
|
||||
{
|
||||
floorRenderer.material = floorMaterials[state];
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetOpenFraction()
|
||||
{
|
||||
return gate != null ? gate.GetOpenFraction() : base.GetOpenFraction();
|
||||
}
|
||||
|
||||
public override void OnPlayerEntry(GameObject playerDetector)
|
||||
{
|
||||
if (exteriorLightController != null)
|
||||
{
|
||||
exteriorLightController.FadeTo(0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPlayerExit(GameObject playerDetector)
|
||||
{
|
||||
if (exteriorLightController != null)
|
||||
{
|
||||
exteriorLightController.FadeTo(1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
NewHorizons/Components/Quantum/QuantumPlanetCompass.cs
Normal file
69
NewHorizons/Components/Quantum/QuantumPlanetCompass.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components.Quantum
|
||||
{
|
||||
public class QuantumPlanetCompass : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Transform compassTransform;
|
||||
|
||||
[SerializeField]
|
||||
public Transform[] stateSymbols = new Transform[0];
|
||||
|
||||
[SerializeField]
|
||||
public bool loop = false;
|
||||
|
||||
[SerializeField]
|
||||
public QuantumPlanet quantumPlanet;
|
||||
|
||||
private float _degrees;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (compassTransform == null)
|
||||
{
|
||||
compassTransform = transform;
|
||||
}
|
||||
if (quantumPlanet == null)
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
int stateIndex = quantumPlanet.CurrentIndex;
|
||||
if (stateIndex < 0 || stateIndex >= stateSymbols.Length) return;
|
||||
|
||||
float num = GetSymbolDegrees(stateIndex);
|
||||
if (!loop && num < 0f)
|
||||
{
|
||||
num += 360f;
|
||||
}
|
||||
else if (loop)
|
||||
{
|
||||
if (num - _degrees > 180f)
|
||||
{
|
||||
num -= 360f;
|
||||
}
|
||||
else if (num - _degrees < -180f)
|
||||
{
|
||||
num += 360f;
|
||||
}
|
||||
}
|
||||
_degrees = Mathf.MoveTowards(_degrees, num, Time.deltaTime * 90f);
|
||||
compassTransform.localEulerAngles = new Vector3(0f, _degrees, 0f);
|
||||
}
|
||||
|
||||
private float GetSymbolDegrees(int index)
|
||||
{
|
||||
Vector3 to = Vector3.ProjectOnPlane(stateSymbols[index].transform.position - transform.position, transform.up);
|
||||
return OWMath.Angle(Vector3.ProjectOnPlane(stateSymbols[0].transform.position - transform.position, transform.up), to, transform.up);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user