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>
This commit is contained in:
Meta Vens 2026-09-14 17:47:33 +02:00
commit 2281793154
17 changed files with 86 additions and 63 deletions

View file

@ -20,6 +20,7 @@ using UnityEngine.Rendering.PostProcessing;
using UnityEngine.Serialization;
using UnityEngine.UI;
using CultMath;
using CultMath.UnityBridge;
using UnityEngine.EventSystems;
using static CultMath.math;
using float2 = CultMath.float2;
@ -1140,7 +1141,7 @@ public class ActionGameManager : MonoBehaviour
foreach (var indicator in _visibleHostileIndicators)
{
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value);
indicator.Value.Place.Target = indicator.Key.Position;
indicator.Value.Place.Target = indicator.Key.Position.ToUnity();
if (!indicator.Key.Active)
indicator.Value.Fill.enabled = false;
else
@ -1155,7 +1156,7 @@ public class ActionGameManager : MonoBehaviour
foreach (var indicator in _visibleFriendlyIndicators)
{
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value);
indicator.Value.Place.Target = indicator.Key.Position;
indicator.Value.Place.Target = indicator.Key.Position.ToUnity();
if (!indicator.Key.Active)
indicator.Value.Fill.enabled = false;
else
@ -1177,7 +1178,7 @@ public class ActionGameManager : MonoBehaviour
if(CurrentEntity is Ship ship)
{
ship.MovementDirection = Input.Player.Move.ReadValue<Vector2>();
ship.MovementDirection = Input.Player.Move.ReadValue<Vector2>().ToCultMath();
}
var target = CurrentEntity.Target.Value;
@ -1209,8 +1210,8 @@ public class ActionGameManager : MonoBehaviour
ViewDot.Target = ZoneRenderer.EntityInstances[CurrentEntity].LookAtPoint.position;
if (CurrentEntity.Target.Value != null)
TargetIndicator.Target = CurrentEntity.Target.Value.Position;
var distance = length((float3)ViewDot.Target - CurrentEntity.Position);
TargetIndicator.Target = CurrentEntity.Target.Value.Position.ToUnity();
var distance = length(ViewDot.Target.ToCultMath() - CurrentEntity.Position);
foreach (var (_, barrels, crosshair) in _articulationGroups)
{
var averagePosition = Vector3.zero;
@ -1226,7 +1227,7 @@ public class ActionGameManager : MonoBehaviour
indicator.gameObject.SetActive(showLockingIndicator);
if(showLockingIndicator)
{
indicator.Target = CurrentEntity.Target.Value.Position;
indicator.Target = CurrentEntity.Target.Value.Position.ToUnity();
indicator.NoiseAmplitude = Settings.GameplaySettings.LockIndicatorNoiseAmplitude * (1 - targetLock.Lock);
indicator.NoiseFrequency = Settings.GameplaySettings.LockIndicatorFrequency.Evaluate(targetLock.Lock);
spin.Speed = Settings.GameplaySettings.LockSpinSpeed.Evaluate(targetLock.Lock);

View file

@ -5,6 +5,7 @@ using System.Linq;
using UniRx;
using UnityEngine;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using float2 = CultMath.float2;
using Random = UnityEngine.Random;
@ -179,7 +180,7 @@ public class EntityInstance : MonoBehaviour
{
var pingInstance = Instantiate(PingPrefab);
var pingMesh = pingInstance.GetComponent<MeshRenderer>();
pingInstance.position = entity.Position;
pingInstance.position = entity.Position.ToUnity();
_pingBrightness = pingMesh.material.GetFloat("_Depth");
_currentPing = (pingInstance, pingMesh);
};
@ -319,7 +320,7 @@ public class EntityInstance : MonoBehaviour
var hitShape = new Shape(hullData.Shape.Width, hullData.Shape.Height);
foreach (var v in hullData.Shape.Coordinates)
{
var localHitDirection = transform.InverseTransformDirection(splash.Direction);
var localHitDirection = transform.InverseTransformDirection(splash.Direction.ToUnity());
var direction = normalize(float2(localHitDirection.x, localHitDirection.z));
var cellDot = dot(normalize(v - hullData.Shape.CenterOfMass), direction);
if (cellDot < 0) hitShape[v] = true;
@ -376,7 +377,7 @@ public class EntityInstance : MonoBehaviour
if (hit.Penetration > .5f)
{
// Find the local 2D vector corresponding to the direction of the incoming hit
var localHitDirection = transform.InverseTransformDirection(hit.Direction);
var localHitDirection = transform.InverseTransformDirection(hit.Direction.ToUnity());
var penetrationVector = normalize(float2(localHitDirection.x, localHitDirection.z));
// TODO: Bresenham's line algorithm
// March a ray through the ship from the hit position
@ -412,7 +413,7 @@ public class EntityInstance : MonoBehaviour
if (gear != Entity.EquippedHull && Random.value < ZoneRenderer.Settings.LootDropProbability)
{
ZoneRenderer.DropItem(
Entity.Position,
Entity.Position.ToUnity(),
Random.onUnitSphere * ZoneRenderer.Settings.LootDropVelocity,
gear.EquippableItem);
}
@ -423,7 +424,7 @@ public class EntityInstance : MonoBehaviour
foreach (var item in cargo.Cargo.Keys)
{
ZoneRenderer.DropItem(
Entity.Position,
Entity.Position.ToUnity(),
Random.onUnitSphere * ZoneRenderer.Settings.LootDropVelocity,
item);
}
@ -512,12 +513,12 @@ public class EntityInstance : MonoBehaviour
foreach (var x in Barrels)
{
Entity.HardpointTransforms[x.Key] = (x.Value[0].position, x.Value[0].forward);
Entity.HardpointTransforms[x.Key] = (x.Value[0].position.ToCultMath(), x.Value[0].forward.ToCultMath());
}
LookAtPoint.position = transform.position + (Vector3) Entity.LookDirection *
LookAtPoint.position = transform.position + Entity.LookDirection.ToUnity() *
(Entity.Target.Value != null ? max(Entity.TargetRange,Entity.ItemManager.GameplaySettings.ConvergenceMinimumDistance) : 10000);
LocalSpace.localPosition = transform.position = Entity.Position;
LocalSpace.localPosition = transform.position = Entity.Position.ToUnity();
if (_influenceInstance)
_influenceInstance.position = new Vector3(Entity.Position.x, 0, Entity.Position.z);
}

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
public class FieldDriver : MonoBehaviour
@ -111,7 +112,7 @@ public class FieldDriver : MonoBehaviour
{
clickableCollider.OnClick += (_, _, ray, hit) =>
{
AddHit(hit.point, ray.direction, TestMagnitude);
AddHit(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestMagnitude);
};
}
_hitBuffer = new ComputeBuffer(MaxHits, 32);
@ -122,8 +123,8 @@ public class FieldDriver : MonoBehaviour
if (_hits.Count >= MaxHits) return;
var hit = new FieldHit
{
Position = Vector3.Scale(normalize(transform.InverseTransformPoint(position)), transform.localScale),
Direction = normalize(transform.rotation * direction),
Position = normalize(transform.InverseTransformPoint(position.ToUnity()).ToCultMath()) * transform.localScale.ToCultMath(),
Direction = normalize((transform.rotation * direction.ToUnity()).ToCultMath()),
Magnitude = magnitude,
Time = 0
};
@ -232,16 +233,16 @@ public class FieldDriver : MonoBehaviour
if (_grabObject != null)
{
_tendrilBasePos = AetheriaMath.Damp(_tendrilBasePos, _grabObject.position, TendrilBaseDamping, Time.deltaTime);
_tendrilBasePos = AetheriaMath.Damp(_tendrilBasePos.ToCultMath(), _grabObject.position.ToCultMath(), TendrilBaseDamping, Time.deltaTime).ToUnity();
switch (_grabPhase)
{
case GrabPhase.Extend:
_tendrilBendTarget = _grabObjectStartPos;
_grabObject.position += _grabObjectVelocity * Time.deltaTime;
_tendrilTargetPos = lerp(
lerp(_grabObjectStartTendrilBasePos, _grabObjectStartPos, _grabTime),
lerp(_grabObjectStartPos, _grabObject.position, _grabTime),
pow(_grabTime, TendrilExtensionExponent));
lerp(_grabObjectStartTendrilBasePos.ToCultMath(), _grabObjectStartPos.ToCultMath(), _grabTime),
lerp(_grabObjectStartPos.ToCultMath(), _grabObject.position.ToCultMath(), _grabTime),
pow(_grabTime, TendrilExtensionExponent)).ToUnity();
_field.SetFloat("_TendrilInfluence", pow(_grabTime, TendrilExtendBaseAnimationExponent));
_field.SetFloat("_TendrilSize", lerp(TendrilBaseRadius/2,TendrilBaseRadius,pow(_grabTime, TendrilExtendBaseAnimationExponent)));
_field.SetFloat("_TendrilRadius", _grabObjectScale * pow(_grabTime, TendrilTipRadiusAnimationExponent) * TendrilTipRadius);
@ -254,8 +255,8 @@ public class FieldDriver : MonoBehaviour
_field.SetFloat("_TendrilRadius", _grabObjectScale * TendrilTipRadius);
break;
case GrabPhase.Pull:
_tendrilTargetPos = _grabObject.position = lerp(_grabObjectEndPos, transform.position, _grabTime*_grabTime);
_tendrilBendTarget = lerp(_grabObjectStartPos, _grabObjectEndPos, _grabTime*_grabTime);
_tendrilTargetPos = _grabObject.position = lerp(_grabObjectEndPos.ToCultMath(), transform.position.ToCultMath(), _grabTime*_grabTime).ToUnity();
_tendrilBendTarget = lerp(_grabObjectStartPos.ToCultMath(), _grabObjectEndPos.ToCultMath(), _grabTime*_grabTime).ToUnity();
if (_fadePoint > .99 && transform.InverseTransformPoint(_grabObject.position).sqrMagnitude < 1)
_fadePoint = _grabTime;
_field.SetFloat("_TendrilInfluence", pow(smoothstep(1, _fadePoint, _grabTime), TendrilFadeExponent));
@ -291,7 +292,7 @@ public class FieldDriver : MonoBehaviour
for (int i = 1; i <= GIZMO_STEPS; i++)
{
var l = (float)i / GIZMO_STEPS;
var next = AetheriaMath.GetQuadraticSplinePosition(_tendrilBasePos, _tendrilBendTarget, _tendrilTargetPos, l);
var next = AetheriaMath.GetQuadraticSplinePosition(_tendrilBasePos.ToCultMath(), _tendrilBendTarget.ToCultMath(), _tendrilTargetPos.ToCultMath(), l).ToUnity();
Gizmos.DrawLine(previous, next);
previous = next;
}

View file

@ -1,5 +1,6 @@
using System;
using CultMath;
using CultMath.UnityBridge;
using UnityEngine;
using static CultMath.math;
using Random = UnityEngine.Random;
@ -32,10 +33,10 @@ public class GridObject : MonoBehaviour
if (Zone == null) return;
var position = t.position;
var gridHeight = Zone.GetHeight(position.Flatland()) + GridOffset;
var gridHeight = Zone.GetHeight(position.Flatland().ToCultMath()) + GridOffset;
Velocity += Vector3.up * (sign(gridHeight - position.y) * GridAttraction * Time.deltaTime);
Velocity *= max(0, 1 - LaunchDrag * Time.deltaTime);
var normal = Zone.GetNormal(position.Flatland());
var normal = Zone.GetNormal(position.Flatland().ToCultMath());
var force = new float2(normal.x, normal.z);
var forceMagnitude = lengthsq(force);
if (forceMagnitude > .001f)

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UniRx;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using UnityEngine;
using float2 = CultMath.float2;
@ -23,8 +24,8 @@ public class HullCollider : MonoBehaviour
Spread = spread,
DamageType = damageType,
Source = source,
TexCoord = texCoord,
Direction = direction
TexCoord = texCoord.ToCultMath(),
Direction = direction.ToCultMath()
});
}
@ -35,13 +36,13 @@ public class HullCollider : MonoBehaviour
Damage = damage,
DamageType = damageType,
Source = source,
Direction = direction
Direction = direction.ToCultMath()
});
}
private void OnCollisionEnter(Collision other)
{
Entity.Velocity += ((float3) other.impulse).xz / Time.deltaTime;
Entity.Velocity += other.impulse.ToCultMath().xz / Time.deltaTime;
}
public class HullHitEventArgs

View file

@ -1,6 +1,7 @@
using System;
using TMPro;
using CultMath;
using CultMath.UnityBridge;
using UnityEngine;
using static CultMath.math;
@ -22,16 +23,16 @@ public class ItemPickup : MonoBehaviour
private void Update()
{
var diff = (float3) transform.position - ViewOrigin;
var diff = transform.position.ToCultMath() - ViewOrigin;
var toThis = normalize(diff);
var viewAngle = acos(Vector3.Dot(toThis, ViewDirection)) * Mathf.Rad2Deg;
var viewAngle = acos(dot(toThis, ViewDirection)) * Mathf.Rad2Deg;
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;
ScanLabelContainer.rotation = Quaternion.LookRotation(-toThis);
ScanLabelContainer.rotation = Quaternion.LookRotation((-toThis).ToUnity());
}
private void OnDestroy()

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using UnityEngine;
@ -72,7 +73,7 @@ public class ShieldManager : MonoBehaviour
public void ShowHit(Vector3 point, float duration)
{
var shield = ShieldPrototype.Instantiate<ShieldAnimation>();
shield.Direction = normalize(shield.transform.InverseTransformPoint(point));
shield.Direction = normalize(shield.transform.InverseTransformPoint(point).ToCultMath()).ToUnity();
shield.Duration = duration;
}
}

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Linq;
using UnityEngine;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
public class ShipInstance : EntityInstance
@ -113,7 +114,7 @@ public class ShipInstance : EntityInstance
base.Update();
TractorBeam.Power = Entity.TractorPower;
TractorBeam.Direction = Entity.LookDirection;
TractorBeam.Direction = Entity.LookDirection.ToUnity();
if (_aetherDrive != null)
{
@ -134,6 +135,6 @@ public class ShipInstance : EntityInstance
emissionModule.rateOverTimeMultiplier = thrusterInstance.BaseEmission * thrusterInstance.Thruster.Axis * (item.Durability / data.Durability);
}
transform.rotation = Ship.Rotation;
transform.rotation = Ship.Rotation.ToUnity();
}
}

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using Random = UnityEngine.Random;
using static Noise1D;
@ -71,18 +72,18 @@ public class GuidedProjectile : MonoBehaviour
StartCoroutine(FadeOut());
return;
}
var position = (float3) t.position;
var position = t.position.ToCultMath();
var targetPosition = TargetPosition?.Invoke() ?? Target.position;
_targetVelocity = lerp(_targetVelocity, targetPosition - _previousTargetPosition, saturate(Time.deltaTime * 5));
_targetVelocity = lerp(_targetVelocity.ToCultMath(), (targetPosition - _previousTargetPosition).ToCultMath(), saturate(Time.deltaTime * 5)).ToUnity();
_previousTargetPosition = targetPosition;
targetPosition = AetheriaMath.FirstOrderIntercept(position,float3.zero, TopSpeed, targetPosition, _targetVelocity);
targetPosition = AetheriaMath.FirstOrderIntercept(position,float3.zero, TopSpeed, targetPosition.ToCultMath(), _targetVelocity.ToCultMath()).ToUnity();
var diff = targetPosition - transform.position;
var targetDist = diff.magnitude;
var sourceDist = length(StartPosition.xz - position.xz);
if (sourceDist > Range || dot(diff,Velocity) < 0)
if (sourceDist > Range || dot(diff.ToCultMath(), Velocity.ToCultMath()) < 0)
{
StartCoroutine(FadeOut());
if (HitEffect != null)
@ -97,8 +98,8 @@ public class GuidedProjectile : MonoBehaviour
var targetDistFlat = diff.Flatland().magnitude;
var curveLerp = 1 - targetDistFlat / (sourceDist + targetDistFlat);
var dir = diff.normalized;
var right = cross(dir, float3(0, 1, 0));
var up = cross(dir, right);
var right = cross(dir.ToCultMath(), float3(0, 1, 0));
var up = cross(dir.ToCultMath(), right);
if (Children > 0 && SplitTime < curveLerp)
{
@ -107,9 +108,9 @@ public class GuidedProjectile : MonoBehaviour
var child = ChildProjectile.Instantiate<GuidedProjectile>();
child.transform.position = t.position;
child.StartPosition = StartPosition;
var randomDirection = normalize(Random.insideUnitCircle);
var randomDirection = normalize(Random.insideUnitCircle.ToCultMath());
var perpendicularRandom = randomDirection.x * right + randomDirection.y * up;
child.Velocity = normalize(lerp(perpendicularRandom, dir, SplitSeparationForwardness)) * length(Velocity) * SplitSeparationVelocity;
child.Velocity = (normalize(lerp(perpendicularRandom, dir.ToCultMath(), SplitSeparationForwardness)) * length(Velocity.ToCultMath()) * SplitSeparationVelocity).ToUnity();
child.Range = Range;
child.Damage = Damage / Children;
child.Penetration = Penetration;
@ -136,7 +137,7 @@ public class GuidedProjectile : MonoBehaviour
var dodge = normalize(lerp(
normalize(right * noise(Time.time * Frequency + _phase) + up * noise(Time.time * Frequency + (100 + _phase))),
Vector3.up, LiftCurve.Evaluate(curveLerp)));
float3(0, 1, 0), LiftCurve.Evaluate(curveLerp))).ToUnity();
var desired = Vector3.Slerp(dodge, dir, GuidanceCurve.Evaluate(curveLerp)).normalized * TopSpeed;
var thrustCurve = ThrustCurve.Evaluate(curveLerp);
var thrust = Thrust * thrustCurve;

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UniRx;
using CultMath;
using CultMath.UnityBridge;
using UnityEngine;
using static CultMath.math;
@ -24,7 +25,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
p.Frequency = launcher.DodgeFrequency;
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
var barrel = source.GetBarrel(hp);
p.StartPosition = p.transform.position = barrel.position;
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
p.Damage = weapon.Damage;
p.Range = weapon.Range;
p.Penetration = weapon.Penetration;
@ -46,7 +47,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
p.Frequency = guidance.DodgeFrequency;
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
var barrel = source.GetBarrel(hp);
p.StartPosition = p.transform.position = barrel.position;
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
p.Damage = weapon.Damage;
p.Range = weapon.Range;
p.Penetration = weapon.Penetration;
@ -58,7 +59,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
p.Velocity = barrel.forward * weapon.Velocity;
p.Thrust = item.Evaluate(guidance.Thrust);
p.TopSpeed = item.Evaluate(guidance.MissileVelocity);
p.TargetPosition = () => source.Entity.Position + length( (float3)source.LookAtPoint.position - source.Entity.Position) * source.Entity.LookDirection;
p.TargetPosition = () => (source.Entity.Position + length(source.LookAtPoint.position.ToCultMath() - source.Entity.Position) * source.Entity.LookDirection).ToUnity();
}
else Debug.LogError($"Weapon {item.Data.Name} linked to {name} effect, but is not a Launcher!");
}

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using UnityEngine;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using Random = UnityEngine.Random;
@ -76,7 +77,7 @@ public class FieldTester : MonoBehaviour
private void Update()
{
var move = _forceThrust ? float2(0,1) : (float2)_input.Player.Move.ReadValue<Vector2>();
var move = _forceThrust ? float2(0,1) : _input.Player.Move.ReadValue<Vector2>().ToCultMath();
var turn = _input.Player.Turn.ReadValue<float>();
if (_directionalPush)
{

View file

@ -1,5 +1,6 @@
using UnityEngine;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using static Noise1D;
@ -57,7 +58,7 @@ public class PlaceUIElementWorldspace : MonoBehaviour
Mathf.Clamp(screenPoint.x, BorderPixels, Screen.width - BorderPixels),
Mathf.Clamp(screenPoint.y, BorderPixels, Screen.height - BorderPixels));
var toEdge = _mainCamera.ScreenPointToRay(clampedPoint);
var edgeLerp = smoothstep(1 - EdgeMargin, 1, dot(toEdge.direction, toTarget));
var edgeLerp = smoothstep(1 - EdgeMargin, 1, dot(toEdge.direction.ToCultMath(), toTarget.ToCultMath()));
if (PointAtTarget)
{
transform.rotation = Quaternion.Slerp(

View file

@ -5,6 +5,7 @@
using System.Collections;
using System.Collections.Generic;
using CultMath;
using CultMath.UnityBridge;
using UnityEngine;
using UnityEngine.EventSystems;
@ -26,22 +27,22 @@ public class MapMenuInput : MonoBehaviour, IBeginDragHandler, IDragHandler, IScr
public void OnBeginDrag(PointerEventData eventData)
{
_startMousePosition = eventData.position;
_startMapPosition = Map.Position;
_startMapPosition = Map.Position.ToUnity();
}
public void OnDrag(PointerEventData eventData)
{
Map.Position = _startMapPosition - (eventData.position - _startMousePosition) * Map.Scale;
Map.Position = (_startMapPosition - (eventData.position - _startMousePosition) * Map.Scale).ToCultMath();
}
public void OnScroll(PointerEventData eventData)
{
Vector3[] mapCorners = new Vector3[4];
_mapRect.GetWorldCorners(mapCorners);
var mapCenter = ((float3)(mapCorners[2] + mapCorners[0]) / 2).xy;
var oldPointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
var mapCenter = ((mapCorners[2] + mapCorners[0]).ToCultMath() / 2).xy;
var oldPointerPosition = Map.Position + (eventData.position.ToCultMath() - mapCenter) * Map.Scale;
Map.Scale *= 1 - eventData.scrollDelta.y * ZoomSpeed;
var pointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
var pointerPosition = Map.Position + (eventData.position.ToCultMath() - mapCenter) * Map.Scale;
Map.Position += oldPointerPosition - pointerPosition;
}
}

View file

@ -8,6 +8,7 @@ using System.Collections.Generic;
using TMPro;
using UnityEngine;
using CultMath;
using CultMath.UnityBridge;
using UnityEngine.UI;
using static CultMath.math;
using int2 = CultMath.int2;
@ -113,7 +114,7 @@ public class MapRenderer : MonoBehaviour
InfluenceDisplay.material.SetTexture("_DetailTex", _influenceTexture);
}
var pos = ((Vector2) Position).Flatland(1);
var pos = Position.ToUnity().Flatland(1);
MapOverlayCamera.transform.position = pos;
MapOverlayCamera.orthographicSize = _size.y * Scale * .5f;

View file

@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using float2 = CultMath.float2;
@ -159,26 +160,26 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
_sectorBackgroundTransform.localScale = new Vector3(_aspectRatio * _viewSize, _viewSize);
_sectorCameraTransform.position = new Vector3(_position.x, _position.y, _sectorCameraDepth);
SectorCamera.orthographicSize = halfSize;
SectorBackgroundRenderer.material.SetVector("Extents", bounds);
SectorBackgroundRenderer.material.SetVector("Extents", bounds.ToUnity());
}
public void OnBeginDrag(PointerEventData eventData)
{
_startMousePosition = eventData.position;
_startMousePosition = eventData.position.ToCultMath();
_startMapPosition = _position;
}
public void OnDrag(PointerEventData eventData)
{
_position = _startMapPosition - ((float2)eventData.position - _startMousePosition) / _size.y * _viewSize;
_position = _startMapPosition - (eventData.position.ToCultMath() - _startMousePosition) / _size.y * _viewSize;
}
public void OnScroll(PointerEventData eventData)
{
var mapCenter = float2((float)Screen.width / 2, (float)Screen.height / 2);
var oldPointerPosition = _position + ((float2)eventData.position - mapCenter) / Screen.height * _viewSize;
var oldPointerPosition = _position + (eventData.position.ToCultMath() - mapCenter) / Screen.height * _viewSize;
_viewSize = clamp(_viewSize * (1 - eventData.scrollDelta.y * ZoomSpeed), MinViewSize, MaxViewSize);
var pointerPosition = _position + ((float2)eventData.position - mapCenter) / Screen.height * _viewSize;
var pointerPosition = _position + (eventData.position.ToCultMath() - mapCenter) / Screen.height * _viewSize;
_position += oldPointerPosition - pointerPosition;
}
}

View file

@ -13,6 +13,7 @@ using UnityEngine.Serialization;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using float2 = CultMath.float2;
@ -512,7 +513,7 @@ public class ZoneRenderer : MonoBehaviour
foreach (var wormhole in WormholeInstances.Values)
{
var difference = wormhole.gravity.transform.position.Flatland() - (Vector2)PerspectiveEntity.Position.xz;
var difference = wormhole.gravity.transform.position.Flatland() - PerspectiveEntity.Position.xz.ToUnity();
var distance = difference.magnitude;
wormhole.icon.gameObject.SetActive(distance > _minimapDistance);
wormhole.icon.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg - 90);