Sync daemon authority migration
This commit is contained in:
parent
030b4b5d74
commit
39a0dc8737
295 changed files with 25121 additions and 7360 deletions
|
|
@ -1,79 +1,42 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShieldManager : MonoBehaviour
|
||||
{
|
||||
public Prototype ShieldPrototype;
|
||||
public float CollisionHitDuration = 3;
|
||||
public float LootInteractionCooldown = 0.25f;
|
||||
public float ShieldCollisionCooldown = 0.1f;
|
||||
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
private bool IsShieldActive()
|
||||
{
|
||||
var otherShield = other.collider.GetComponent<ShieldManager>();
|
||||
if (!otherShield)
|
||||
{
|
||||
var gridObject = other.collider.GetComponent<GridObject>();
|
||||
if (gridObject)
|
||||
{
|
||||
var itemPickup = other.collider.GetComponent<ItemPickup>();
|
||||
var mine = other.collider.GetComponent<Mine>();
|
||||
if (itemPickup)
|
||||
{
|
||||
if (ActionGameManager.Instance != null &&
|
||||
ActionGameManager.Instance.CommitLootPickup(Entity, itemPickup.Item))
|
||||
{
|
||||
// TODO: Pickup notification!
|
||||
Destroy(itemPickup.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Pickup failed notification!
|
||||
var cp = other.GetContact(0);
|
||||
gridObject.Velocity += cp.normal * 25;
|
||||
Debug.Log("Attempted item pickup, but no space in cargo bay!");
|
||||
}
|
||||
}
|
||||
else if (mine)
|
||||
{
|
||||
mine.Explode();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Shield collision occurred with grid object, but other collider isn't a mine or an item pickup!");
|
||||
}
|
||||
}
|
||||
else
|
||||
Debug.Log("Shield collision occurred, but other collider isn't a shield or a grid object!");
|
||||
return;
|
||||
}
|
||||
var contact = other.GetContact(0);
|
||||
var normal = normalize(float2(contact.normal.x, contact.normal.z));
|
||||
var tangent = normal.Rotate(ItemRotation.CounterClockwise);
|
||||
var v1n = dot(normal, Entity.Velocity);
|
||||
var v1t = dot(tangent, Entity.Velocity);
|
||||
var v2n = dot(normal, otherShield.Entity.Velocity);
|
||||
//var v2t = dot(tangent, otherShield.Entity.Velocity);
|
||||
|
||||
var v1np = PostCollisionVelocity(v1n, Entity.Mass, v2n, otherShield.Entity.Mass);
|
||||
Entity.Velocity = tangent * v1t + normal * v1np;
|
||||
if(Entity.Shield != null && Entity.Shield.Item.Active.Value) ShowHit(contact.point, CollisionHitDuration);
|
||||
return Entity?.Shield != null && Entity.Shield.Item.Active.Value;
|
||||
}
|
||||
|
||||
private float PostCollisionVelocity(float v1, float m1, float v2, float m2)
|
||||
private Bounds ShieldBounds()
|
||||
{
|
||||
return (v1 * (m1 - m2) + m2 * v2) / (m1 + m2);
|
||||
var renderers = GetComponentsInChildren<Renderer>();
|
||||
if (renderers.Length == 0)
|
||||
return new Bounds(transform.position, Vector3.one);
|
||||
|
||||
var bounds = renderers[0].bounds;
|
||||
for (var i = 1; i < renderers.Length; i++)
|
||||
bounds.Encapsulate(renderers[i].bounds);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
private static float ShieldPlanarRadius(Bounds bounds)
|
||||
{
|
||||
return Mathf.Max(bounds.extents.x, bounds.extents.z, 0.001f);
|
||||
}
|
||||
|
||||
public void ShowHit(Vector3 point, float duration)
|
||||
{
|
||||
var shield = ShieldPrototype.Instantiate<ShieldAnimation>();
|
||||
shield.Direction = normalize(shield.transform.InverseTransformPoint(point));
|
||||
shield.Direction = shield.transform.InverseTransformPoint(point).normalized;
|
||||
shield.Duration = duration;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue