Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions demo/Blackholio/client-unity/Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &75691256
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -665,10 +665,10 @@ RectTransform:
- {fileID: 15926227}
m_Father: {fileID: 920270125}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 119.685, y: -18.51}
m_SizeDelta: {x: 239.37, y: 37.02}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &380907976
MonoBehaviour:
Expand Down Expand Up @@ -1214,10 +1214,10 @@ RectTransform:
m_Children: []
m_Father: {fileID: 867669873}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 209.305, y: -40.11}
m_SizeDelta: {x: 378.61, y: 40.22}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &734198859
MonoBehaviour:
Expand Down Expand Up @@ -1335,7 +1335,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &867669873
RectTransform:
m_ObjectHideFlags: 0
Expand All @@ -1356,7 +1356,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: 418.61, y: 216.14}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &867669874
MonoBehaviour:
Expand Down Expand Up @@ -1620,10 +1620,10 @@ RectTransform:
- {fileID: 380907975}
m_Father: {fileID: 867669873}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 209.305, y: -96.03001}
m_SizeDelta: {x: 239.37, y: 37.02}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &920270126
MonoBehaviour:
Expand Down Expand Up @@ -1826,8 +1826,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fdf6b37246fc5824eb3c4e6888c33a4a, type: 3}
m_Name:
m_EditorClassIdentifier:
elements:
- {fileID: 75691255}
- {fileID: 867669872}
UsernameInputField: {fileID: 380907977}
PlayButton: {fileID: 1670294508}
--- !u!1 &1005992895
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2424,10 +2426,10 @@ RectTransform:
- {fileID: 1005992896}
m_Father: {fileID: 867669873}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 209.305, y: -163.98999}
m_SizeDelta: {x: 179.31, y: 64.3}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1670294507
MonoBehaviour:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using SpacetimeDB.Types;
using UnityEngine;

public class CameraController : MonoBehaviour
Expand All @@ -9,10 +10,10 @@ public class CameraController : MonoBehaviour
private void LateUpdate()
{
var arenaCenterTransform = new Vector3(WorldSize / 2, WorldSize / 2, -10.0f);
if (PlayerController.Local == null || !GameManager.IsConnected())
if (PlayerController.Local == null || !GameManager.IsConnected() || PlayerController.Local.NumberOfOwnedCircles == 0)
{
// Set the camera to be in middle of the arena if we are not connected or
// there is no local player
// there are no circles to follow
transform.position = arenaCenterTransform;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public abstract class EntityController : MonoBehaviour

protected float LerpTime;
protected Vector3 LerpStartPosition;
protected Vector3 LerpTargetPositio;
protected Vector3 LerpTargetPosition;
protected Vector3 TargetScale;

protected virtual void Spawn(uint entityId)
{
EntityId = entityId;

var entity = GameManager.Conn.Db.Entity.EntityId.Find(entityId);
LerpStartPosition = LerpTargetPositio = transform.position = (Vector2)entity.Position;
LerpStartPosition = LerpTargetPosition = transform.position = (Vector2)entity.Position;
transform.localScale = Vector3.one;
TargetScale = MassToScale(entity.Mass);
}
Expand All @@ -38,7 +38,7 @@ public virtual void OnEntityUpdated(Entity newVal)
{
LerpTime = 0.0f;
LerpStartPosition = transform.position;
LerpTargetPositio = (Vector2)newVal.Position;
LerpTargetPosition = (Vector2)newVal.Position;
TargetScale = MassToScale(newVal.Mass);
}

Expand Down Expand Up @@ -78,7 +78,7 @@ public virtual void Update()
{
//Interpolate position and scale
LerpTime = Mathf.Min(LerpTime + Time.deltaTime, LERP_DURATION_SEC);
transform.position = Vector3.Lerp(LerpStartPosition, LerpTargetPositio, LerpTime / LERP_DURATION_SEC);
transform.position = Vector3.Lerp(LerpStartPosition, LerpTargetPosition, LerpTime / LERP_DURATION_SEC);
transform.localScale = Vector3.Lerp(transform.localScale, TargetScale, Time.deltaTime * 8);
}

Expand Down
31 changes: 30 additions & 1 deletion demo/Blackholio/client-unity/Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private void Start()
// and their circles will be able to eat each other.
if (AuthToken.Token != "")
{
Debug.Log("Using auth token!");
builder = builder.WithToken(AuthToken.Token);
}

Expand Down Expand Up @@ -98,11 +99,39 @@ private void HandleSubscriptionApplied(SubscriptionEventContext ctx)
{
Debug.Log("Subscription applied!");
OnSubscriptionApplied?.Invoke();

// Once we have the initial subscription sync'd to the client cache
// Get the world size from the config table and set up the arena
var worldSize = Conn.Db.Config.Id.Find(0).WorldSize;
SetupArena(worldSize);

// Check to see if we already have a player, if we don't we'll need to create one
var player = ctx.Db.Player.Identity.Find(LocalIdentity);
if (string.IsNullOrEmpty(player.Name))
{
// The player has to choose a username
UIUsernameChooser.Instance.Show(true);

// When our username is updated, hide the username chooser
Conn.Db.Player.OnUpdate += (_, _, newPlayer) =>
{
if (newPlayer.Identity == LocalIdentity)
{
UIUsernameChooser.Instance.Show(false);
}
};
} else {
// We already have a player
if (ctx.Db.Circle.PlayerId.Filter(player.PlayerId).Any())
{
// We already have at least one circle, we should just be able to start
// playing immediately.
UIUsernameChooser.Instance.Show(false);
} else {
// Create a new circle for our player.
ctx.Reducers.EnterGame(player.Name);
}
}
}

private void SetupArena(float worldSize)
Expand Down
23 changes: 12 additions & 11 deletions demo/Blackholio/client-unity/Assets/Scripts/UIUsernameChooser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,33 @@ public class UIUsernameChooser : MonoBehaviour
{
public static UIUsernameChooser Instance { get; private set; }

// The elements that compose the username chooser UI
public GameObject[] elements;
public TMPro.TMP_InputField UsernameInputField;
public Button PlayButton;

private void Start()
{
Instance = this;
GameManager.Conn.Db.Player.OnInsert += (ctx, newPlayer) =>
{
if (newPlayer.Identity == GameManager.LocalIdentity)
{
// We have a player
UsernameInputField.text = newPlayer.Name;
}
};
}

public void PlayPressed()
{
Debug.Log("Creating player");

string name = UsernameInputField.text.Trim();
var name = UsernameInputField.text.Trim();
if (string.IsNullOrEmpty(name))
{
name = "<No Name>";
}
GameManager.Conn.Reducers.EnterGame(name);
gameObject.SetActive(false);
Show(false);
}

public void Show(bool showing)
{
foreach (var element in elements)
{
element.SetActive(showing);
}
}
}

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.

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.

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.

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.

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.

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.

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.

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

Loading
Loading