浏览代码
Adding logic for displaying an image for each symbol object, and choosing a randomized sequence of symbols. Also adding basic UI for displaying a player's target sequence.
Adding logic for displaying an image for each symbol object, and choosing a randomized sequence of symbols. Also adding basic UI for displaying a player's target sequence.
(Known issue that I just found: It looks like having three players doesn't allow one to join. Will investigate.)/main/staging/ngo_minigame_structure
nathaniel.buck@unity3d.com
3 年前
当前提交
9614d153
共有 12 个文件被更改,包括 1068 次插入 和 607 次删除
-
953Assets/Art/Font/CheckboxFLF SDF.asset
-
383Assets/Prefabs/InGame/InGameLogic.prefab
-
14Assets/Prefabs/InGame/SymbolContainer.prefab
-
59Assets/Prefabs/InGame/SymbolObject.prefab
-
68Assets/Scripts/Game/InGame/InGameRunner.cs
-
8Assets/Scripts/Game/InGame/PlayerCursor.cs
-
37Assets/Scripts/Game/InGame/SymbolObject.cs
-
4Assets/Scripts/Infrastructure/Locator.cs
-
19Assets/Scripts/Game/InGame/IInGameInputHandler.cs
-
11Assets/Scripts/Game/InGame/IInGameInputHandler.cs.meta
-
108Assets/Scripts/Game/InGame/SequenceSelector.cs
-
11Assets/Scripts/Game/InGame/SequenceSelector.cs.meta
953
Assets/Art/Font/CheckboxFLF SDF.asset
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LobbyRelaySample.inGame |
|||
{ |
|||
public interface IInGameInputHandler : IProvidable<IInGameInputHandler> |
|||
{ |
|||
void OnPlayerInput(SymbolObject selectedSymbol); |
|||
} |
|||
|
|||
public class InGameInputHandlerNoop : IInGameInputHandler |
|||
{ |
|||
public void OnPlayerInput(SymbolObject selectedSymbol) { } |
|||
public void OnReProvided(IInGameInputHandler previousProvider) { } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c4f5cf8c17e4ba64ca47aa981116b358 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Netcode; |
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
|
|||
namespace LobbyRelaySample.inGame |
|||
{ |
|||
/// <summary>
|
|||
/// Handles selecting the randomized sequence of symbols to spawn. This also selects a subset of the selected symbols to be the target
|
|||
/// sequence that each player needs to select in order.
|
|||
/// </summary>
|
|||
public class SequenceSelector : NetworkBehaviour |
|||
{ |
|||
[SerializeField] private SymbolData m_symbolData = default; |
|||
[SerializeField] private RawImage[] m_targetSequenceOutput = default; |
|||
public const int k_symbolCount = 100; |
|||
private List<int> m_fullSequence = new List<int>(); // This is owned by the host, and each index is assigned as a NetworkVariable to each SymbolObject.
|
|||
private NetworkList<int> m_targetSequence; // This is owned by the host but needs to be available to all clients, so it's a NetworkedList here.
|
|||
private int m_targetSequenceCurrentIndex = -1; |
|||
|
|||
public void Awake() |
|||
{ |
|||
m_targetSequence = new NetworkList<int>(); |
|||
} |
|||
|
|||
public override void OnNetworkSpawn() |
|||
{ |
|||
if (IsHost) |
|||
{ |
|||
// Choose some subset of the list of symbols to be present in this game, along with a target sequence.
|
|||
List<int> symbolsForThisGame = SelectSymbols(m_symbolData.m_availableSymbols.Count, 8); |
|||
m_targetSequence.Add(symbolsForThisGame[0]); |
|||
m_targetSequence.Add(symbolsForThisGame[1]); |
|||
m_targetSequence.Add(symbolsForThisGame[2]); |
|||
|
|||
// Then, ensure that the target sequence is present in order throughout most of the full set of symbols to spawn.
|
|||
int numTargetSequences = k_symbolCount / 6; // About 1/2 of the 3 symbols will be definitely part of the target sequence.
|
|||
for (; numTargetSequences >= 0; numTargetSequences--) |
|||
{ m_fullSequence.Add(m_targetSequence[2]); // We want a List instead of a Queue or Stack for faster insertion, but we will remove indices backwards so as to not reshift other entries.
|
|||
m_fullSequence.Add(m_targetSequence[1]); |
|||
m_fullSequence.Add(m_targetSequence[0]); |
|||
} |
|||
// Then, fill in with a good mix of the remaining symbols.
|
|||
AddHalfRemaining(3, 2); |
|||
AddHalfRemaining(4, 2); |
|||
AddHalfRemaining(5, 2); |
|||
AddHalfRemaining(6, 2); |
|||
AddHalfRemaining(7, 1); |
|||
|
|||
void AddHalfRemaining(int symbolIndex, int divider) |
|||
{ |
|||
int remaining = k_symbolCount - m_fullSequence.Count; |
|||
for (int n = 0; n < remaining / divider; n++) |
|||
{ |
|||
int randomIndex = UnityEngine.Random.Range(0, m_fullSequence.Count); |
|||
m_fullSequence.Insert(randomIndex, symbolsForThisGame[symbolIndex]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Very simple random selection. Duplicates are allowed.
|
|||
private static List<int> SelectSymbols(int numOptions, int targetCount) |
|||
{ |
|||
List<int> list = new List<int>(); |
|||
for (int n = 0; n < targetCount; n++) |
|||
list.Add(UnityEngine.Random.Range(0, numOptions)); |
|||
return list; |
|||
} |
|||
|
|||
public void Update() |
|||
{ |
|||
// We can't guarantee timing with the host's selection of the target sequence, so retrieve it once it's available.
|
|||
if (m_targetSequenceCurrentIndex < 0 && m_targetSequence.Count > 0) |
|||
{ |
|||
for (int n = 0; n < m_targetSequence.Count; n++) |
|||
m_targetSequenceOutput[n].texture = m_symbolData.GetSymbolForIndex(m_targetSequence[n]).texture; |
|||
m_targetSequenceCurrentIndex = 0; |
|||
ScaleTargetUi(); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// If the index is correct, this will advance the current sequence index.
|
|||
/// </summary>
|
|||
public bool ConfirmSymbolCorrect(int symbolIndex) |
|||
{ |
|||
if (symbolIndex != m_targetSequence[m_targetSequenceCurrentIndex]) |
|||
return false; |
|||
if (++m_targetSequenceCurrentIndex >= m_targetSequence.Count) |
|||
m_targetSequenceCurrentIndex = 0; |
|||
|
|||
ScaleTargetUi(); |
|||
return true; |
|||
} |
|||
private void ScaleTargetUi() |
|||
{ |
|||
for (int i = 0; i < m_targetSequenceOutput.Length; i++) |
|||
m_targetSequenceOutput[i].transform.localScale = Vector3.one * (m_targetSequenceCurrentIndex == i ? 1 : 0.7f); |
|||
} |
|||
|
|||
public int GetNextSymbol(int symbolObjectIndex) |
|||
{ |
|||
return m_fullSequence[symbolObjectIndex]; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 77910b5766924f044995dfe427e9eea3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue