feat: add Unity 6 client with 2.5D visual system
Unity client features: - WebSocket connection via NativeWebSocket - 2.5D agent visuals with programmatic placeholder sprites - Billboard system for sprites and UI elements - Floating UI panels (name, HP, energy bars) - Speech bubble system with pop-in animation - RTS-style camera controller (WASD + scroll zoom) - Editor tools for prefab creation and scene setup Scripts: - NetworkManager: WebSocket singleton - GameManager: Agent spawning and event handling - AgentVisual: 2.5D sprite and UI creation - Billboard: Camera-facing behavior - SpeechBubble: Animated dialogue display - CameraController: RTS camera with UI input detection - UIManager: HUD and command input 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro.Examples
|
||||
{
|
||||
|
||||
public class TMP_UiFrameRateCounter : MonoBehaviour
|
||||
{
|
||||
public float UpdateInterval = 5.0f;
|
||||
private float m_LastInterval = 0;
|
||||
private int m_Frames = 0;
|
||||
|
||||
public enum FpsCounterAnchorPositions { TopLeft, BottomLeft, TopRight, BottomRight };
|
||||
|
||||
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.TopRight;
|
||||
|
||||
private string htmlColorTag;
|
||||
private const string fpsLabel = "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS";
|
||||
|
||||
private TextMeshProUGUI m_TextMeshPro;
|
||||
private RectTransform m_frameCounter_transform;
|
||||
|
||||
private FpsCounterAnchorPositions last_AnchorPosition;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
Application.targetFrameRate = 1000;
|
||||
|
||||
GameObject frameCounter = new GameObject("Frame Counter");
|
||||
m_frameCounter_transform = frameCounter.AddComponent<RectTransform>();
|
||||
|
||||
m_frameCounter_transform.SetParent(this.transform, false);
|
||||
|
||||
m_TextMeshPro = frameCounter.AddComponent<TextMeshProUGUI>();
|
||||
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
|
||||
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
|
||||
|
||||
m_TextMeshPro.textWrappingMode = TextWrappingModes.NoWrap;
|
||||
m_TextMeshPro.fontSize = 36;
|
||||
|
||||
m_TextMeshPro.isOverlay = true;
|
||||
|
||||
Set_FrameCounter_Position(AnchorPosition);
|
||||
last_AnchorPosition = AnchorPosition;
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
m_LastInterval = Time.realtimeSinceStartup;
|
||||
m_Frames = 0;
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (AnchorPosition != last_AnchorPosition)
|
||||
Set_FrameCounter_Position(AnchorPosition);
|
||||
|
||||
last_AnchorPosition = AnchorPosition;
|
||||
|
||||
m_Frames += 1;
|
||||
float timeNow = Time.realtimeSinceStartup;
|
||||
|
||||
if (timeNow > m_LastInterval + UpdateInterval)
|
||||
{
|
||||
// display two fractional digits (f2 format)
|
||||
float fps = m_Frames / (timeNow - m_LastInterval);
|
||||
float ms = 1000.0f / Mathf.Max(fps, 0.00001f);
|
||||
|
||||
if (fps < 30)
|
||||
htmlColorTag = "<color=yellow>";
|
||||
else if (fps < 10)
|
||||
htmlColorTag = "<color=red>";
|
||||
else
|
||||
htmlColorTag = "<color=green>";
|
||||
|
||||
m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);
|
||||
|
||||
m_Frames = 0;
|
||||
m_LastInterval = timeNow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
|
||||
{
|
||||
switch (anchor_position)
|
||||
{
|
||||
case FpsCounterAnchorPositions.TopLeft:
|
||||
m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
|
||||
m_frameCounter_transform.pivot = new Vector2(0, 1);
|
||||
m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.99f);
|
||||
m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.99f);
|
||||
m_frameCounter_transform.anchoredPosition = new Vector2(0, 1);
|
||||
break;
|
||||
case FpsCounterAnchorPositions.BottomLeft:
|
||||
m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
|
||||
m_frameCounter_transform.pivot = new Vector2(0, 0);
|
||||
m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.01f);
|
||||
m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.01f);
|
||||
m_frameCounter_transform.anchoredPosition = new Vector2(0, 0);
|
||||
break;
|
||||
case FpsCounterAnchorPositions.TopRight:
|
||||
m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
|
||||
m_frameCounter_transform.pivot = new Vector2(1, 1);
|
||||
m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.99f);
|
||||
m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.99f);
|
||||
m_frameCounter_transform.anchoredPosition = new Vector2(1, 1);
|
||||
break;
|
||||
case FpsCounterAnchorPositions.BottomRight:
|
||||
m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
|
||||
m_frameCounter_transform.pivot = new Vector2(1, 0);
|
||||
m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.01f);
|
||||
m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.01f);
|
||||
m_frameCounter_transform.anchoredPosition = new Vector2(1, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user