Added skinned mesh collider. Changed Heat Reset from list to event action. Added curve to heat buildup
This commit is contained in:
@@ -9,7 +9,9 @@ public class EyeTrackingCollisionPoints : MonoBehaviour
|
||||
private float rayDistance = 1.0f;
|
||||
|
||||
[SerializeField]
|
||||
private LayerMask layersToInclude;
|
||||
private LayerMask gazableLayers;
|
||||
[SerializeField]
|
||||
private LayerMask targetLayers;
|
||||
|
||||
public GameObject hitPointPrefab;
|
||||
|
||||
@@ -21,15 +23,10 @@ public class EyeTrackingCollisionPoints : MonoBehaviour
|
||||
|
||||
Vector3 rayCastDirection = transform.TransformDirection(Vector3.forward) * rayDistance;
|
||||
|
||||
if ( hitPoint != null && Physics.Raycast(transform.position, rayCastDirection, out hit, rayDistance, layersToInclude))
|
||||
if ( hitPoint != null && Physics.Raycast(transform.position, rayCastDirection, out hit, rayDistance, gazableLayers))
|
||||
{
|
||||
hitPoint.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
|
||||
|
||||
GameObject hitObject = hit.collider.gameObject;
|
||||
if ( hitObject.GetComponent<RecieveHeat>() != null)
|
||||
{
|
||||
hitObject.GetComponent<RecieveHeat>().AddHeat(0.02f);
|
||||
}
|
||||
FindVisibleTargets(hitPoint.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,5 +35,22 @@ public class EyeTrackingCollisionPoints : MonoBehaviour
|
||||
hitPoint = Instantiate(hitPointPrefab);
|
||||
return hitPoint.transform;
|
||||
}
|
||||
|
||||
void FindVisibleTargets(Vector3 hitPosition) // Sucht in einem Radius von 20 cm um den HitPoint nach Targets
|
||||
{
|
||||
Collider[] visibleTargets = Physics.OverlapSphere(hitPosition, 0.2f, targetLayers);
|
||||
foreach (Collider col in visibleTargets)
|
||||
{
|
||||
GameObject hitObject = col.gameObject;
|
||||
if (hitObject.GetComponent<RecieveHeat>() != null)
|
||||
{
|
||||
hitObject.GetComponent<RecieveHeat>().AddHeat(0.02f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Hit " + hitObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace GhostSystem
|
||||
|
||||
private DateTime latestLoadedTimestamp;
|
||||
|
||||
public static event Action OnRestartLoop;
|
||||
|
||||
[Serializable]
|
||||
public class TrackedObjectBinding
|
||||
{
|
||||
@@ -247,11 +249,8 @@ namespace GhostSystem
|
||||
if (Loop)
|
||||
{
|
||||
playbackTime = 0f;
|
||||
foreach (RecieveHeat target in heatTargets)
|
||||
{
|
||||
target.SetHeat(0);
|
||||
}
|
||||
}
|
||||
OnRestartLoop?.Invoke();
|
||||
}
|
||||
else
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,58 @@
|
||||
using GhostSystem;
|
||||
using UnityEngine;
|
||||
|
||||
public class RecieveHeat : MonoBehaviour
|
||||
{
|
||||
private float heatLevel;
|
||||
public Renderer myRenderer;
|
||||
private float heatLevel; // von 0-255
|
||||
private float heatLevelNormalized; // von 0-1
|
||||
private Material myMat;
|
||||
|
||||
private async void OnEnable()
|
||||
{
|
||||
GhostReplayManager.OnRestartLoop += HandleRestartLoop;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GhostReplayManager.OnRestartLoop -= HandleRestartLoop;
|
||||
}
|
||||
|
||||
private void HandleRestartLoop()
|
||||
{
|
||||
SetHeat(0);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
myMat = GetComponent<Renderer>().material;
|
||||
if (myRenderer == null)
|
||||
{
|
||||
TryGetComponent<Renderer>(out myRenderer);
|
||||
}
|
||||
myMat = myRenderer.material;
|
||||
SetHeat(0);
|
||||
}
|
||||
|
||||
public void SetHeat(float heat)
|
||||
{
|
||||
if (heat > 255) return;
|
||||
if (heat > 1f) return;
|
||||
heatLevel = heat;
|
||||
myMat.color = new Color(heatLevel,0,0);
|
||||
float redAmount = CalcRedAmount(heatLevel);
|
||||
myMat.color = new Color(redAmount,0,0);
|
||||
}
|
||||
|
||||
public void AddHeat(float heat)
|
||||
{
|
||||
heatLevel += heat;
|
||||
myMat.color = new Color(heatLevel, 0, 0);
|
||||
if (heatLevel > 1f) return;
|
||||
float redAmount = CalcRedAmount(heatLevel);
|
||||
Debug.Log(gameObject.ToString() + "Heat in: " + heatLevel + "Heat out: " + redAmount);
|
||||
myMat.color = new Color(redAmount, 0, 0);
|
||||
}
|
||||
|
||||
private float CalcRedAmount(float xNormalized)
|
||||
{
|
||||
float y = Mathf.Pow(xNormalized, 0.5f);
|
||||
return Mathf.Clamp(y, 0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user