animations refactor
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootKit.Engine.Network;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootReality.jelycho.Feedbacks {
|
||||
@@ -12,7 +15,7 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
public float radius;
|
||||
public float intensity;
|
||||
public float timer;
|
||||
|
||||
|
||||
public static int GetMaxBytes() {
|
||||
return sizeof(float) * 3 + sizeof(float) * 3;
|
||||
}
|
||||
@@ -21,8 +24,33 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
public class FeedbacksManagerActor : Actor {
|
||||
static readonly Logger s_Logger = new Logger(nameof(FeedbacksManagerActor));
|
||||
|
||||
[SerializeField] Volume m_Volume;
|
||||
|
||||
[SerializeField] float m_QuickAttackIndicatorDuration = 0.3f;
|
||||
[SerializeField] float m_QuickAttackIndicatorPaniniAppearSpeed = 2.0f;
|
||||
[SerializeField] float m_QuickAttackIndicatorChromaticAppearSpeed = 2.0f;
|
||||
[SerializeField] float m_QuickAttackIndicatorPaniniDisappearSpeed = 2.0f;
|
||||
[SerializeField] float m_QuickAttackIndicatorChromaticDisappearSpeed = 2.0f;
|
||||
[SerializeField] float m_QuickAttackIndicatorPaniniIntensity = 0.1f;
|
||||
[SerializeField] float m_QuickAttackIndicatorChromaticIntensity = 1.0f;
|
||||
|
||||
PaniniProjection m_PaniniProjection;
|
||||
ChromaticAberration m_ChromaticAberration;
|
||||
|
||||
float m_QuickAttackTimer;
|
||||
|
||||
List<CameraShakeFeedback> m_ActiveCameraShakes = new List<CameraShakeFeedback>();
|
||||
|
||||
void Awake() {
|
||||
if (!m_Volume.profile.TryGet(out m_PaniniProjection)) {
|
||||
s_Logger.Error($"Failed to find PaniniProjection on volume: {m_Volume.name}");
|
||||
}
|
||||
|
||||
if (!m_Volume.profile.TryGet(out m_ChromaticAberration)) {
|
||||
s_Logger.Error($"Failed to find ChromaticAberration on volume: {m_Volume.name}");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: Camera shake
|
||||
//
|
||||
@@ -31,7 +59,7 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
s_Logger.Error("ShakeCamera can only be called on the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
FeedbacksCameraShakeEvent ev = new FeedbacksCameraShakeEvent {
|
||||
Feedback = new CameraShakeFeedback {
|
||||
center = center,
|
||||
@@ -40,7 +68,7 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
timer = duration
|
||||
}
|
||||
};
|
||||
SendActorEvent((byte)FeedbacksManagerActorEvents.CameraShake, ref ev);
|
||||
SendActorEvent((byte) FeedbacksManagerActorEvents.CameraShake, ref ev);
|
||||
}
|
||||
|
||||
public float GetShakeIntensityForPosition(Vector3 position) {
|
||||
@@ -70,14 +98,21 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
|
||||
return intensity;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// @MARK: Local only
|
||||
//
|
||||
public void ShowQuickAttackIndicator() {
|
||||
m_QuickAttackTimer = m_QuickAttackIndicatorDuration;
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: Actor
|
||||
//
|
||||
protected override IActorData CreateActorData() {
|
||||
return new NoActorData();
|
||||
}
|
||||
|
||||
|
||||
public override void OnClientTick(float deltaTime) {
|
||||
for (int i = m_ActiveCameraShakes.Count - 1; i >= 0; i--) {
|
||||
CameraShakeFeedback feedback = m_ActiveCameraShakes[i];
|
||||
@@ -90,13 +125,40 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
|
||||
m_ActiveCameraShakes[i] = feedback;
|
||||
}
|
||||
|
||||
m_QuickAttackTimer -= Time.deltaTime;
|
||||
if (m_QuickAttackTimer <= 0.0f) {
|
||||
float chromaticIntensity = m_ChromaticAberration.intensity.value;
|
||||
chromaticIntensity = Mathf.MoveTowards(chromaticIntensity,
|
||||
0.0f,
|
||||
deltaTime * m_QuickAttackIndicatorChromaticDisappearSpeed);
|
||||
m_ChromaticAberration.intensity.value = chromaticIntensity;
|
||||
|
||||
float paniniIntensity = m_PaniniProjection.distance.value;
|
||||
paniniIntensity = Mathf.MoveTowards(paniniIntensity,
|
||||
0.0f,
|
||||
deltaTime * m_QuickAttackIndicatorPaniniDisappearSpeed);
|
||||
m_PaniniProjection.distance.value = paniniIntensity;
|
||||
} else {
|
||||
float chromaticIntensity = m_ChromaticAberration.intensity.value;
|
||||
chromaticIntensity = Mathf.MoveTowards(chromaticIntensity,
|
||||
m_QuickAttackIndicatorChromaticIntensity,
|
||||
deltaTime * m_QuickAttackIndicatorChromaticAppearSpeed);
|
||||
m_ChromaticAberration.intensity.value = chromaticIntensity;
|
||||
|
||||
float paniniIntensity = m_PaniniProjection.distance.value;
|
||||
paniniIntensity = Mathf.MoveTowards(paniniIntensity,
|
||||
m_QuickAttackIndicatorPaniniIntensity,
|
||||
deltaTime * m_QuickAttackIndicatorPaniniAppearSpeed);
|
||||
m_PaniniProjection.distance.value = paniniIntensity;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActorEventClient(ActorEvent actorEvent) {
|
||||
FeedbacksManagerActorEvents feedbackEvent = (FeedbacksManagerActorEvents)actorEvent.EventID;
|
||||
FeedbacksManagerActorEvents feedbackEvent = (FeedbacksManagerActorEvents) actorEvent.EventID;
|
||||
|
||||
switch (feedbackEvent) {
|
||||
|
||||
|
||||
case FeedbacksManagerActorEvents.CameraShake: {
|
||||
FeedbacksCameraShakeEvent ev = new FeedbacksCameraShakeEvent();
|
||||
DataSerializationUtils.Deserialize(actorEvent.Data, ref ev);
|
||||
@@ -106,11 +168,11 @@ namespace RebootReality.jelycho.Feedbacks {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum FeedbacksManagerActorEvents : byte {
|
||||
None = 0x00,
|
||||
CameraShake = 0x01,
|
||||
|
||||
Reference in New Issue
Block a user