-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
…not in tent * removed static flag from candybars, since they are rigidbodies * adjusted tablet right hand grip position * hands, tablet, and pelican case update lighting mask depending on if they are in the tent * started on key animation behaviors (look, additive layer masking)
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using FieldDay.Components; | ||
using UnityEngine; | ||
|
||
namespace Pennycook.Animation { | ||
public sealed class LookSmoothing : BatchedComponent { | ||
public Animator Animator; | ||
public Transform LookFrom; | ||
public float LookLerpSpeed; | ||
|
||
[NonSerialized] public LookTargetMode Mode; | ||
[NonSerialized] public Vector3 LookVector; | ||
[NonSerialized] public Transform LookTowards; | ||
[NonSerialized] public Vector2 LastAppliedLook; | ||
|
||
public Vector2 WorldLookDirectionToLocal(Vector3 worldVec) { | ||
return (Vector2) LookFrom.InverseTransformDirection(worldVec); | ||
} | ||
} | ||
|
||
public enum LookTargetMode { | ||
Disabled, | ||
Forward, | ||
ConstantLocal, | ||
ConstantWorld, | ||
TowardsTransform | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using BeauRoutine; | ||
using FieldDay.Components; | ||
using FieldDay.Systems; | ||
using UnityEngine; | ||
|
||
namespace Pennycook.Animation { | ||
public sealed class LookSmoothingSystem : ComponentSystemBehaviour<LookSmoothing> { | ||
static private int LookXParam; | ||
static private int LookYParam; | ||
|
||
public override void Initialize() { | ||
base.Initialize(); | ||
|
||
LookXParam = Animator.StringToHash("LookX"); | ||
LookYParam = Animator.StringToHash("LookY"); | ||
} | ||
|
||
public override void ProcessWork(float deltaTime) { | ||
float targetX, targetY, newX, newY; | ||
|
||
foreach (var comp in m_Components) { | ||
if (comp.Mode == LookTargetMode.Disabled) { | ||
continue; | ||
} | ||
|
||
switch (comp.Mode) { | ||
case LookTargetMode.Forward: | ||
default: { | ||
targetX = targetY = 0; | ||
break; | ||
} | ||
|
||
case LookTargetMode.ConstantLocal: { | ||
targetX = comp.LookVector.x; | ||
targetY = comp.LookVector.y; | ||
break; | ||
} | ||
|
||
case LookTargetMode.ConstantWorld: { | ||
Vector2 localVec = comp.WorldLookDirectionToLocal(comp.LookVector); | ||
targetX = localVec.x; | ||
targetY = localVec.y; | ||
break; | ||
} | ||
|
||
case LookTargetMode.TowardsTransform: { | ||
Vector3 towards = comp.LookTowards.position - comp.LookFrom.position; | ||
Vector2 localVec = comp.WorldLookDirectionToLocal(towards.normalized); | ||
targetX = localVec.x; | ||
targetY = localVec.y; | ||
break; | ||
} | ||
} | ||
|
||
float lerpAmt = TweenUtil.Lerp(comp.LookLerpSpeed, 1, deltaTime); | ||
|
||
newX = Mathf.Lerp(comp.LastAppliedLook.x, targetX, lerpAmt); | ||
newY = Mathf.Lerp(comp.LastAppliedLook.y, targetY, lerpAmt); | ||
|
||
if (!Mathf.Approximately(newX, comp.LastAppliedLook.x)) { | ||
comp.Animator.SetFloat(LookXParam, newX); | ||
comp.LastAppliedLook.x = newX; | ||
} | ||
if (!Mathf.Approximately(targetY, comp.LastAppliedLook.y)) { | ||
comp.Animator.SetFloat(LookYParam, newY); | ||
comp.LastAppliedLook.y = newY; | ||
} | ||
|
||
bool wasConstant = comp.Mode == LookTargetMode.Forward || comp.Mode == LookTargetMode.ConstantLocal; | ||
if (wasConstant && Mathf.Approximately(targetX, newX) && Mathf.Approximately(targetY, newY)) { | ||
comp.Mode = LookTargetMode.Disabled; | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using BeauUtil; | ||
using FieldDay.Animation; | ||
using UnityEngine; | ||
|
||
namespace Pennycook.Animation { | ||
public sealed class AdditiveBlendMaskSM : FrameKeyedSMBehaviour { | ||
[Range(0, 7)] public int LayerIndex; | ||
[Range(0, 1)] public float DefaultWeight; | ||
[Range(0, 1)] public float InRangeWeight; | ||
public OffsetLengthU16[] Ranges; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BeauUtil; | ||
using FieldDay.Animation; | ||
using FieldDay.Components; | ||
using FieldDay.Scenes; | ||
using UnityEngine; | ||
|
||
namespace Pennycook.Animation { | ||
[RequireComponent(typeof(Animator))] | ||
public sealed class AdditiveBlendMaskState : BatchedComponent, IScenePreload { | ||
#region Types | ||
|
||
public struct LerpState { | ||
public Float8 Current; | ||
public Float8 Target; | ||
public Float8 Lerp; | ||
} | ||
|
||
#endregion // Types | ||
|
||
[Required] public Animator Animator; | ||
public float DefaultLerpSpeed = 5; | ||
public float StateMachineMaskLerpSpeed = 20; | ||
|
||
[NonSerialized] public int LayerCount; | ||
[NonSerialized] public Float8 LastAppliedWeights; | ||
[NonSerialized] public LerpState ScriptWeights; | ||
[NonSerialized] public LerpState StateMachineWeights; | ||
|
||
IEnumerator<WorkSlicer.Result?> IScenePreload.Preload() { | ||
LayerCount = Animator.layerCount; | ||
for(int i = 0; i < LayerCount; i++) { | ||
ScriptWeights.Current[i] = Animator.GetLayerWeight(i); | ||
} | ||
ScriptWeights.Target = ScriptWeights.Current; | ||
ScriptWeights.Lerp = new Float8(LayerCount, DefaultLerpSpeed); | ||
|
||
StateMachineWeights.Current = new Float8(LayerCount, 1); | ||
StateMachineWeights.Target = StateMachineWeights.Current; | ||
StateMachineWeights.Lerp = new Float8(LayerCount, StateMachineMaskLerpSpeed); | ||
|
||
LastAppliedWeights = ScriptWeights.Current; | ||
return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BeauRoutine; | ||
using BeauUtil; | ||
using FieldDay; | ||
using FieldDay.Animation; | ||
using FieldDay.Components; | ||
using FieldDay.Scenes; | ||
using FieldDay.Systems; | ||
using UnityEngine; | ||
|
||
namespace Pennycook.Animation { | ||
[SysUpdate(GameLoopPhase.LateUpdate, -1000)] | ||
public sealed class AdditiveBlendMaskSystem : ComponentSystemBehaviour<AdditiveBlendMaskState> { | ||
public override void ProcessWork(float deltaTime) { | ||
foreach(var component in m_Components) { | ||
if (!component.Animator.isActiveAndEnabled) { | ||
continue; | ||
} | ||
|
||
int layerCount = component.LayerCount; | ||
ProcessInterpolations(ref component.ScriptWeights, layerCount, deltaTime); | ||
ProcessInterpolations(ref component.StateMachineWeights, layerCount, deltaTime); | ||
|
||
Float8 finalWeights = new Float8(); | ||
for (int i = 0; i < layerCount; i++) { | ||
finalWeights[i] = component.ScriptWeights.Current[i] * component.StateMachineWeights.Current[i]; | ||
} | ||
|
||
ApplyBlend(component, finalWeights); | ||
} | ||
} | ||
|
||
static private void ProcessInterpolations(ref AdditiveBlendMaskState.LerpState lerps, int count, float deltaTime) { | ||
float target; | ||
for (int i = 0; i < count; i++) { | ||
ref float current = ref lerps.Current[i]; | ||
target = lerps.Target[i]; | ||
current = Mathf.Lerp(current, target, TweenUtil.Lerp(lerps.Lerp[i], 1, deltaTime)); | ||
if (Mathf.Approximately(current, target)) { | ||
current = target; | ||
} | ||
} | ||
} | ||
|
||
static private void ApplyBlend(AdditiveBlendMaskState state, Float8 weights) { | ||
for (int i = 0; i < state.LayerCount; i++) { | ||
if (state.LastAppliedWeights[i] != weights[i]) { | ||
state.Animator.SetLayerWeight(i, weights[i]); | ||
} | ||
} | ||
state.LastAppliedWeights = weights; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using BeauRoutine; | ||
using BeauUtil; | ||
using FieldDay.Animation; | ||
using UnityEngine; | ||
|
||
namespace Pennycook.Animation { | ||
[RequireComponent(typeof(Animator))] | ||
public sealed class AnimatorRotationState : MonoBehaviour { | ||
public Transform Root; | ||
|
||
[NonSerialized] public Vector3 StartRotation; | ||
[NonSerialized] public Vector3 TargetRotation; | ||
|
||
#if UNITY_EDITOR | ||
private void Reset() { | ||
Root = transform; | ||
} | ||
#endif // UNITY_EDITOR | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.