Skip to content

Commit

Permalink
* halfway through adjusting tablet ui
Browse files Browse the repository at this point in the history
  • Loading branch information
BeauPrime committed Dec 5, 2024
1 parent 2b3b4dd commit e635c22
Show file tree
Hide file tree
Showing 33 changed files with 5,683 additions and 1,499 deletions.
4 changes: 3 additions & 1 deletion Assets/Code/Tablet/Highlight/TabletHighlightSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public override void ProcessWork(float deltaTime) {
if (Frame.Interval(3) && isGripping && m_StateB.CurrentTool != TabletTool.None && !m_StateA.RaycastJob.IsValid()) {
if (searchMask != 0) {
TabletZoomState zoomState = Find.State<TabletZoomState>();
float coneRadius = zoomState.ZoomMultiplier;
float coneDistance = 25 * zoomState.ZoomMultiplier;
float coneRadius = coneDistance * m_StateB.CurrentToolDef.RaycastUnitConeRadius * CameraHelper.UnitHeightForFOV(m_StateA.LookCamera.fieldOfView) / 2;

m_StateA.CachedLookCameraTransform.GetPositionAndRotation(out Vector3 cameraPos, out Quaternion cameraRot);
m_StateA.RaycastJob = RaycastJobs.SmoothConeCast(cameraPos, Geom.Forward(cameraRot), coneRadius, coneDistance, 5, searchMask);
Expand All @@ -35,6 +35,8 @@ public override void ProcessWork(float deltaTime) {
}

if (m_StateA.RaycastJob.IsValid()) {
m_StateA.RaycastJob.Complete();

TabletHighlightable scannable;
RaycastHit hit;
scannable = RaycastJobs.Analyze(ref m_StateA.RaycastJob, m_StateB.CurrentToolDef.HighlightPredicate, m_StateA, out hit);
Expand Down
6 changes: 6 additions & 0 deletions Assets/Code/Tablet/TabletToolData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace Pennycook.Tablet {
public class TabletToolDefinition {
public LayerMask RaycastMask;
public float RaycastUnitConeRadius;
public bool ShowReticle = true;

public Predicate<TabletHighlightable, TabletHighlightState> HighlightPredicate;
public TabletToolHighlightEventDelegate OnHighlighted;
Expand Down Expand Up @@ -45,6 +47,7 @@ static public class TabletToolDefinitions {

static public readonly TabletToolDefinition Scan = new TabletToolDefinition() {
RaycastMask = TabletUtility.DefaultSearchMask,
RaycastUnitConeRadius = 0.05f,

HighlightPredicate = (h, hc) => {
return h.CachedInteraction && TabletInteractionUtility.HasInteractions(h, h.CachedInteraction);
Expand Down Expand Up @@ -91,6 +94,8 @@ static public class TabletToolDefinitions {

static public readonly TabletToolDefinition Count = new TabletToolDefinition() {
RaycastMask = TabletUtility.CountSearchMask,
RaycastUnitConeRadius = 0.65f,
ShowReticle = false,

HighlightPredicate = (h, hc) => {
return h.CachedCountable && TabletUtility.IsButtonHeld(XRHandButtons.TriggerButton) && TabletCountUtility.IsCountable(h.CachedCountable);
Expand All @@ -117,6 +122,7 @@ static public class TabletToolDefinitions {

static public readonly TabletToolDefinition Warp = new TabletToolDefinition() {
RaycastMask = TabletUtility.TravelSearchMask,
RaycastUnitConeRadius = 0.05f,

HighlightPredicate = (h, hc) => {
return h.CachedWarp && h.CachedWarp.CanWarp;
Expand Down
5 changes: 5 additions & 0 deletions Assets/Code/Tablet/TabletToolState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using FieldDay.Audio;
using FieldDay.Scripting;
using FieldDay.SharedState;
using FieldDay.UI;
using FieldDay.UI.Animation;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -24,6 +26,7 @@ public struct ToolConfig {
public ToolConfig[] Configs;
public ShapeGraphic Outline;
public Graphic[] ToolColorTinted;
public FadeGroup Reticle;

[Header("State")]
public TabletTool CurrentTool;
Expand Down Expand Up @@ -99,6 +102,8 @@ static public void SetTool(TabletToolState toolState, int index, bool playFeedba
toolState.CurrentToolDef.OnHighlighted?.Invoke(highlights.HighlightedObject, ctrl);
}

toolState.Reticle.SetVisible(toolState.CurrentToolDef.ShowReticle);

if (playFeedback) {
TabletUtility.PlaySfx("Tablet.ModeChanged");
TabletUtility.PlayHaptics(0.1f, 0.01f);
Expand Down
18 changes: 6 additions & 12 deletions Assets/Code/UI/ModeLabelDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FieldDay;
using FieldDay.Animation;
using FieldDay.UI.Animation;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -9,22 +11,14 @@ public class ModeLabelDisplay : MonoBehaviour {

[Header("Selected State")]
public GameObject ExpandedContent;
public Vector4 SelectedBGSize;

[Header("Unselected State")]
public Vector4 UnselectedBGSize;

public void SetState(bool selected) {
ExpandedContent.SetActive(selected);
BG.gameObject.SetActive(selected);

Vector2 offsetMin, offsetMax;
Vector4 offsets = selected ? SelectedBGSize : UnselectedBGSize;

offsetMin = new Vector2(offsets.x, offsets.y);
offsetMax = new Vector2(offsets.z, offsets.w);

BG.offsetMin = offsetMin;
BG.offsetMax = offsetMax;
if (selected) {
PopAnim.Play(Offset, PopAnim.Default);
}
}
}
}
5 changes: 3 additions & 2 deletions Assets/Code/VRHands/Socket/ObjectSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using BeauUtil;
using FieldDay.Components;
using FieldDay.Physics;
using FieldDay.Scenes;
using UnityEngine;

namespace FieldDay.Sockets {
[DefaultExecutionOrder(1)]
public class ObjectSocket : BatchedComponent {
public class ObjectSocket : BatchedComponent, ISceneLoadHandler {
#region Inspector

public bool Locked = false;
Expand Down Expand Up @@ -53,7 +54,7 @@ private void Awake() {
Detector.onTriggerExit.AddListener(OnDetectorExited);
}

private void Start() {
void ISceneLoadHandler.OnSceneLoad(SceneBinding inScene, object inContext) {
if (Current != null && Current.CurrentSocket == null) {
SocketUtility.TryAddToSocket(Current, this, true);
} else {
Expand Down
33 changes: 33 additions & 0 deletions Assets/FieldDay/Plugins/ScriptableBake/ChangeParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;

namespace ScriptableBake {

/// <summary>
/// Changes the transform parent.
/// </summary>
[AddComponentMenu("ScriptableBake/Change Parent"), DisallowMultipleComponent]
public sealed class ChangeParent : MonoBehaviour, IBaked {

public const int Order = FlattenHierarchy.Order - 10;

public Transform NewParent;

#region IBaked

#if UNITY_EDITOR

int IBaked.Order {
get { return Order; }
}

bool IBaked.Bake(BakeFlags flags, BakeContext context) {
transform.SetParent(NewParent);
Baking.Destroy(this);
return true;
}

#endif // UNITY_EDITOR

#endregion // IBaked
}
}
11 changes: 11 additions & 0 deletions Assets/FieldDay/Plugins/ScriptableBake/ChangeParent.cs.meta

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

6 changes: 6 additions & 0 deletions Assets/FieldDay/UI/Animation/FadeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public sealed class FadeGroup : MonoBehaviour, IGuiPanel {
[NonSerialized] public AnimHandle CurrentHandle;
[NonSerialized] public bool CurrentState;

private void Awake() {
CurrentState = isActiveAndEnabled;
}

#region IGuiPanel

public Transform Root { get { return this.CacheComponent(ref CachedTransform); } }
Expand Down Expand Up @@ -122,6 +126,8 @@ public override bool UpdateAnimation(FadeGroup target, ref LiteAnimatorState sta
static private readonly FadeInAnim FadeInAnimator = new FadeInAnim();
static private readonly FadeOutAnim FadeOutAnimator = new FadeOutAnim();

// TODO: bounce anims

#endregion // Anims
}
}
55 changes: 55 additions & 0 deletions Assets/FieldDay/UI/Animation/PopAnim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using BeauRoutine;
using FieldDay.Animation;
using UnityEngine;
using UnityEngine.UI;

namespace FieldDay.UI.Animation {
public sealed class PopAnim : LiteAnimator<LayoutOffset> {

private readonly Vector2 m_Offset;
private readonly float m_Duration;
private readonly Curve m_Ease;

public PopAnim(Vector2 offset, float duration, Curve ease = Curve.Linear) {
m_Offset = offset;
m_Duration = duration;
m_Ease = ease;
}

static private void PrepareState(ref LiteAnimatorState state, Vector2 offsetAmt, float duration, float delay, Curve easing) {
state.Duration = duration;
state.TimeRemaining = duration + delay;
state.InitParamA.Float2 = offsetAmt;
state.Easing = easing;
}

public override void InitAnimation(LayoutOffset target, ref LiteAnimatorState state) {
if (state.TimeRemaining <= state.Duration) {
target.Offset1 = state.InitParamA.Float2;
}
}

public override void ResetAnimation(LayoutOffset target, ref LiteAnimatorState state) {
target.Offset1 = default;
}

public override bool UpdateAnimation(LayoutOffset target, ref LiteAnimatorState state, float deltaTime) {
state.TimeRemaining -= deltaTime;
float percent = state.Easing.Evaluate(1 - Math.Max(0, state.TimeRemaining / state.Duration));
if (percent >= 0) {
target.Offset1 = state.InitParamA.Float2 * (1f - percent);
}
return state.TimeRemaining > 0;
}

static public readonly PopAnim Default = new PopAnim(new Vector2(0, -4), 8 / 60f, Curve.Linear);
static public readonly PopAnim DefaultUp = new PopAnim(new Vector2(0, 4), 8 / 60f, Curve.Linear);

static public AnimHandle Play(LayoutOffset offset, PopAnim config, float delay = 0, GameLoopPhase phase = GameLoopPhase.Update) {
LiteAnimatorState animState = new LiteAnimatorState();
PrepareState(ref animState, config.m_Offset, config.m_Duration, delay, config.m_Ease);
return Game.Animation.AddLiteAnimator(config, offset, animState, phase);
}
}
}
11 changes: 11 additions & 0 deletions Assets/FieldDay/UI/Animation/PopAnim.cs.meta

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

15 changes: 15 additions & 0 deletions Assets/FieldDay/UI/Panels/IGuiPanel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Runtime.CompilerServices;
using BeauUtil;
using UnityEngine;

Expand All @@ -22,4 +23,18 @@ public interface IGuiPanel {
/// Singleton interface panel.
/// </summary>
public interface ISharedGuiPanel : IGuiPanel { }

/// <summary>
/// Interface panel extensions.
/// </summary>
static public class GuiPanelExtensions {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public void SetVisible(this IGuiPanel panel, bool visible) {
if (visible) {
panel.Show();
} else {
panel.Hide();
}
}
}
}
9 changes: 8 additions & 1 deletion Assets/FieldDay/World/Animation/ILiteAnimator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using BeauRoutine;
using BeauUtil;
using UnityEngine;

Expand Down Expand Up @@ -38,7 +39,8 @@ bool ILiteAnimator.UpdateAnimation(object target, ref LiteAnimatorState state, f
public struct LiteAnimatorState {
public float TimeRemaining;
public float Duration;
public BitSet32 Flags;
public Curve Easing;
public ushort Flags;
public int StateId;
public LiteAnimatorStateParam InitParamA;
public LiteAnimatorStateParam InitParamB;
Expand All @@ -48,6 +50,11 @@ public void ResetTime(float duration) {
TimeRemaining = Duration = duration;
}

public void ResetTimeWithDelay(float duration, float delay) {
Duration = duration;
TimeRemaining = duration + delay;
}

public void ScaleTime(float scale) {
TimeRemaining *= scale;
Duration *= scale;
Expand Down
12 changes: 12 additions & 0 deletions Assets/FieldDay/World/Scene/SceneMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,18 @@ static public bool IsPersistent(Component component) {
return component.TryGetComponent(out Persist _);
}

/// <summary>
/// Returns if any scenes are baking.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool IsBaking() {
#if UNITY_EDITOR
return Editor.AreDelayedSceneProcessorsRunning();
#else
return false;
#endif // UNITY_EDITOR
}

static public class Editor {
#if UNITY_EDITOR
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Loading

0 comments on commit e635c22

Please sign in to comment.