Skip to content

Commit

Permalink
* pelican case travels with player, switches to "exterior" mode when …
Browse files Browse the repository at this point in the history
…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
BeauchesneFieldDay committed Oct 11, 2024
1 parent 4059036 commit 8b46888
Show file tree
Hide file tree
Showing 69 changed files with 6,570 additions and 862 deletions.
8 changes: 6 additions & 2 deletions Assets/Code/Animation/Footstep/FootstepEffectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ public override void ProcessWorkForComponent(FootstepPlayer component, float del

if (isLeft) {
Sfx.PlayDetached(stepSfx, component.LeftFoot);
VFXUtility.QueueFootstepDecal(component.LeftFoot, component.DecalType | FootstepDecalType.LeftFoot);
if (component.DecalType != 0) {
VFXUtility.QueueFootstepDecal(component.LeftFoot, component.DecalType | FootstepDecalType.LeftFoot);
}
// TODO: decals/particles
}

if (isRight) {
Sfx.PlayDetached(stepSfx, component.RightFoot);
VFXUtility.QueueFootstepDecal(component.RightFoot, component.DecalType | FootstepDecalType.RightFoot);
if (component.DecalType != 0) {
VFXUtility.QueueFootstepDecal(component.RightFoot, component.DecalType | FootstepDecalType.RightFoot);
}
// TODO: decals/particles
}
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Code/Animation/LookAt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Assets/Code/Animation/LookAt/LookSmoothing.cs
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
}
}
11 changes: 11 additions & 0 deletions Assets/Code/Animation/LookAt/LookSmoothing.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Assets/Code/Animation/LookAt/LookSmoothingSystem.cs
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;
}
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Code/Animation/LookAt/LookSmoothingSystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Code/Animation/StateMachine.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Code/Animation/StateMachine/AdditiveBlendMaskSM.cs
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;
}
}
11 changes: 11 additions & 0 deletions Assets/Code/Animation/StateMachine/AdditiveBlendMaskSM.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Assets/Code/Animation/StateMachine/AdditiveBlendMaskState.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Code/Animation/StateMachine/AdditiveBlendMaskState.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Assets/Code/Animation/StateMachine/AdditiveBlendMaskSystem.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Code/Animation/StateMachine/AdditiveBlendMaskSystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Assets/Code/Animation/StateMachine/AnimatorRotationState.cs
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
}
}
11 changes: 11 additions & 0 deletions Assets/Code/Animation/StateMachine/AnimatorRotationState.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8b46888

Please sign in to comment.