2021-04-18 05:13:20 +01:00
|
|
|
using System;
|
|
|
|
|
using TMPro;
|
2026-09-14 17:39:12 +02:00
|
|
|
using CultMath;
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
using CultMath.UnityBridge;
|
2021-04-15 04:25:22 +01:00
|
|
|
using UnityEngine;
|
2026-09-14 17:39:12 +02:00
|
|
|
using static CultMath.math;
|
2021-04-15 04:25:22 +01:00
|
|
|
|
|
|
|
|
public class ItemPickup : MonoBehaviour
|
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
public float LabelFadeDuration = .5f;
|
|
|
|
|
public float LabelPersistDuration = 3;
|
|
|
|
|
public float LabelDisplayAngle = 15;
|
|
|
|
|
public float LabelDisplayMaxDistance = 500;
|
|
|
|
|
public Transform ScanLabelContainer;
|
|
|
|
|
public TextMeshPro ScanLabel;
|
|
|
|
|
|
2021-04-15 04:25:22 +01:00
|
|
|
public ItemInstance Item { get; set; }
|
2021-04-18 05:13:20 +01:00
|
|
|
public ZoneRenderer ZoneRenderer { get; set; }
|
2026-08-10 14:57:50 +01:00
|
|
|
public float3 ViewOrigin { get; set; }
|
|
|
|
|
public float3 ViewDirection { get; set; }
|
2021-04-18 05:13:20 +01:00
|
|
|
|
|
|
|
|
private float _displayTime;
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
var diff = transform.position.ToCultMath() - ViewOrigin;
|
2021-04-18 05:13:20 +01:00
|
|
|
var toThis = normalize(diff);
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
var viewAngle = acos(dot(toThis, ViewDirection)) * Mathf.Rad2Deg;
|
2021-04-18 05:13:20 +01:00
|
|
|
if (length(diff) < LabelDisplayMaxDistance && viewAngle < LabelDisplayAngle)
|
|
|
|
|
_displayTime = Time.time;
|
|
|
|
|
var targetAlpha = Time.time - _displayTime < LabelPersistDuration ? 1 : 0;
|
|
|
|
|
var c = ScanLabel.color;
|
|
|
|
|
c.a = c.a + sign(targetAlpha - c.a) * (Time.deltaTime / LabelFadeDuration);
|
|
|
|
|
ScanLabel.color = c;
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
ScanLabelContainer.rotation = Quaternion.LookRotation((-toThis).ToUnity());
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
2025-01-30 01:58:05 +00:00
|
|
|
ZoneRenderer?.DestroyLoot(this);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
}
|