浏览代码

taking feedback from holiday PRs

/main
David Woodruff 4 年前
当前提交
4e0d4420
共有 18 个文件被更改,包括 146 次插入147 次删除
  1. 1
      Assets/BossRoom/Prefabs/Character/CharacterSet.prefab
  2. 6
      Assets/BossRoom/Prefabs/Enemy.prefab
  3. 1
      Assets/BossRoom/Prefabs/Imp.prefab
  4. 4
      Assets/BossRoom/Prefabs/State/BossRoomState.prefab
  5. 2
      Assets/BossRoom/Scenes/DungeonTest.unity
  6. 31
      Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs
  7. 12
      Assets/BossRoom/Scripts/Client/ClientInputSender.cs
  8. 2
      Assets/BossRoom/Scripts/Client/Game/Character/ModelSwap.cs
  9. 2
      Assets/BossRoom/Scripts/Client/UI/MainMenuUI.cs
  10. 9
      Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs
  11. 26
      Assets/BossRoom/Scripts/Server/Game/Action/ChaseAction.cs
  12. 2
      Assets/BossRoom/Scripts/Server/Game/Action/MeleeAction.cs
  13. 15
      Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs
  14. 13
      Assets/BossRoom/Scripts/Server/Net/ServerGNHLogic.cs
  15. 17
      Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs
  16. 69
      Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs
  17. 78
      Assets/BossRoom/Scripts/Shared/NetworkCharacterState.cs
  18. 3
      ProjectSettings/TagManager.asset

1
Assets/BossRoom/Prefabs/Character/CharacterSet.prefab


m_Script: {fileID: 11500000, guid: 9520a47fc61d5ab4ca99cdac2d574909, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ClientVisualsAnimator: {fileID: 4199396739699390757}
MinZoomDistance: 3
MaxZoomDistance: 30
ZoomSpeed: 3

6
Assets/BossRoom/Prefabs/Enemy.prefab


m_Script: {fileID: 11500000, guid: 9520a47fc61d5ab4ca99cdac2d574909, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ClientVisualsAnimator: {fileID: 8221438362690823759}
MinZoomDistance: 3
MaxZoomDistance: 30
ZoomSpeed: 3

m_CorrespondingSourceObject: {fileID: 4099936395697225189, guid: 08c3914aa4064d349a429bc090494787, type: 3}
m_PrefabInstance: {fileID: 2025951435693425104}
m_PrefabAsset: {fileID: 0}
--- !u!95 &8221438362690823759 stripped
Animator:
m_CorrespondingSourceObject: {fileID: 7927965616957794207, guid: 08c3914aa4064d349a429bc090494787, type: 3}
m_PrefabInstance: {fileID: 2025951435693425104}
m_PrefabAsset: {fileID: 0}

1
Assets/BossRoom/Prefabs/Imp.prefab


m_Script: {fileID: 11500000, guid: 9520a47fc61d5ab4ca99cdac2d574909, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ClientVisualsAnimator: {fileID: 8731146078263039551}
MinZoomDistance: 0
MaxZoomDistance: 0
ZoomSpeed: 0

4
Assets/BossRoom/Prefabs/State/BossRoomState.prefab


m_Script: {fileID: 11500000, guid: 927521835ae055247b17e4abe805b4ab, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayerPrefab: {fileID: 4600110157238723790, guid: bb87f9bac2595f8499c048016c4b2e1d, type: 3}
EnemyPrefab: {fileID: -3741253011127748524, guid: 5f8daaa54415e5e41b5162cd13121359, type: 3}
m_PlayerPrefab: {fileID: 4600110157238723790, guid: bb87f9bac2595f8499c048016c4b2e1d, type: 3}
m_EnemyPrefab: {fileID: -3741253011127748524, guid: 5f8daaa54415e5e41b5162cd13121359, type: 3}

2
Assets/BossRoom/Scenes/DungeonTest.unity


- component: {fileID: 2097550086}
m_Layer: 0
m_Name: CM vcam1
m_TagString: Untagged
m_TagString: CMCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

31
Assets/BossRoom/Scripts/Client/ClientCharacterVisualization.cs


using UnityEngine;
using Cinemachine;
namespace BossRoom.Viz
namespace BossRoom.Visual
{
/// <summary>
/// <see cref="ClientCharacterVisualization"/> is responsible for displaying a character on the client's screen based on state information sent by the server.

{
private NetworkCharacterState m_NetState;
[SerializeField]
private CinemachineVirtualCamera m_MainCamera;
private Transform m_Parent;

m_ClientVisualsAnimator.SetTrigger("BeginAttack");
}
void Awake()
void Update()
m_ClientVisualsAnimator = GetComponent<Animator>();
}
if (m_Parent == null)
{
//since we aren't in the transform hierarchy, we have to explicitly die when our parent dies.
GameObject.Destroy(this.gameObject);
return;
}
void Update()
{
if (m_ClientVisualsAnimator)
{

private void SmoothMove()
{
if (m_Parent == null)
{
//since we aren't in the transform hierarchy, we have to explicitly die when our parent dies.
GameObject.Destroy(this.gameObject);
return;
}
var pos_diff = m_Parent.transform.position - transform.position;
var angle_diff = Quaternion.Angle(m_Parent.transform.rotation, transform.rotation);

private void AttachCamera()
{
m_MainCamera = (CinemachineVirtualCamera)FindObjectOfType(typeof(CinemachineVirtualCamera));
var cameraGO = GameObject.FindGameObjectWithTag("CMCamera");
if( cameraGO == null ) { return; }
m_MainCamera = cameraGO.GetComponent<CinemachineVirtualCamera>();
if (m_MainCamera)
{
m_MainCamera.Follow = transform;

12
Assets/BossRoom/Scripts/Client/ClientInputSender.cs


//these two actions will queue one after the other, causing us to run over to our target and take a swing.
var chase_data = new ActionRequestData();
chase_data.ActionTypeEnum = ActionType.GENERAL_CHASE;
chase_data.Amount = 3f;
chase_data.Amount = ActionData.ActionDescriptions[ActionType.TANK_BASEATTACK][0].Range;
m_NetworkCharacter.C2S_DoAction(ref chase_data);
m_NetworkCharacter.ClientSendActionRequest(ref chase_data);
m_NetworkCharacter.C2S_DoAction(ref hit_data);
m_NetworkCharacter.ClientSendActionRequest(ref hit_data);
m_NetworkCharacter.C2S_DoAction(ref data);
m_NetworkCharacter.ClientSendActionRequest(ref data);
}
m_AttackClickRequest = null;

/// </summary>
private ulong GetTargetObject(ref RaycastHit hit )
{
if( hit.collider == null ) { return 0; }
if (hit.collider == null) { return 0; }
if( targetObj == null ) { return 0; }
if (targetObj == null) { return 0; }
return targetObj.NetworkId;
}

2
Assets/BossRoom/Scripts/Client/Game/Character/ModelSwap.cs


using UnityEngine;
using UnityEngine.UI;
namespace BossRoom.Viz
namespace BossRoom.Visual
{
public class ModelSwap : MonoBehaviour
{

2
Assets/BossRoom/Scripts/Client/UI/MainMenuUI.cs


using System.Collections.Generic;
using UnityEngine;
namespace BossRoom.Viz
namespace BossRoom.Visual
{
/// <summary>
/// Provides backing logic for all of the UI that runs in the MainMenu stage.

9
Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs


{
if( this.m_queue.Count > 0 )
{
bool keepgoing = m_queue[0].Update();
bool expirable = m_queue[0].Description.Duration_s > 0f; //non-positive value is a sentinel indicating the duration is indefinite.
bool time_expired = expirable && (Time.time - m_queue[0].TimeStarted) >= m_queue[0].Description.Duration_s;
if ( !keepgoing || time_expired )
Action runningAction = m_queue[0]; //action at the front of the queue is the one that is actively running.
bool keepGoing = runningAction.Update();
bool expirable = runningAction.Description.Duration_s > 0f; //non-positive value is a sentinel indicating the duration is indefinite.
bool timeExpired = expirable && (Time.time - runningAction.TimeStarted) >= runningAction.Description.Duration_s;
if ( !keepGoing || timeExpired )
{
AdvanceQueue(true);
}

26
Assets/BossRoom/Scripts/Server/Game/Action/ChaseAction.cs


/// <returns>false if the action decided it doesn't want to run after all, true otherwise. </returns>
public override bool Start()
{
if(m_Data.TargetIds == null || m_Data.TargetIds.Length == 0 || !MLAPI.Spawning.SpawnManager.SpawnedObjects.ContainsKey(m_Data.TargetIds[0]) )
if (!HasValidTarget())
{
Debug.Log("Failed to start ChaseAction. The target entity wasn't submitted or doesn't exist anymore" );
return false;

m_CurrentTargetPos = m_Target.transform.position;
return true;
}
/// <summary>
/// Returns true if our ActionRequestData came with a valid target. For the ChaseAction, this is pretty liberal (could be friend or foe, could be
/// dead or alive--just needs to be present).
/// </summary>
private bool HasValidTarget()
{
return m_Data.TargetIds != null &&
m_Data.TargetIds.Length > 0 &&
MLAPI.Spawning.SpawnManager.SpawnedObjects.ContainsKey(m_Data.TargetIds[0]);
}
/// <summary>

public override bool Update()
{
float dist_to_target = (m_Parent.transform.position - m_Target.transform.position).magnitude;
if( m_Data.Amount > dist_to_target )
float distToTarget2 = (m_Parent.transform.position - m_Target.transform.position).sqrMagnitude;
if( (m_Data.Amount*m_Data.Amount) > distToTarget2 )
{
//we made it! we're done.
Cancel();

float target_moved = (m_Target.transform.position - m_CurrentTargetPos).magnitude;
if( m_Data.Amount < target_moved )
float targetMoved2 = (m_Target.transform.position - m_CurrentTargetPos).sqrMagnitude;
if( (m_Data.Amount*m_Data.Amount) < targetMoved2 )
{
//target has moved past our range tolerance. Must repath.
this.m_Movement.SetMovementTarget(m_Target.transform.position);

public override void Cancel()
{
if( m_Movement != null )
{
m_Movement.CancelMove();
}
m_Movement?.CancelMove();
}
}

2
Assets/BossRoom/Scripts/Server/Game/Action/MeleeAction.cs


public override bool Start()
{
m_Parent.NetState.S2C_BroadcastAction(ref Data);
m_Parent.NetState.ServerBroadcastAction(ref Data);
return true;
}

15
Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs


using System.Collections;
using System.Collections.Generic;
using BossRoom;
using System;
using MLAPI;
namespace BossRoom.Server

{
[SerializeField]
[Tooltip("Make sure this is included in the NetworkingManager's list of prefabs!")]
private NetworkedObject PlayerPrefab;
private NetworkedObject m_PlayerPrefab;
private NetworkedObject EnemyPrefab;
private NetworkedObject m_EnemyPrefab;
public override GameState ActiveState { get { return GameState.BOSSROOM; } }

private void SpawnPlayer(ulong clientId)
{
var NewPlayer = Instantiate(PlayerPrefab);
NewPlayer.SpawnAsPlayerObject(clientId);
var newPlayer = Instantiate(m_PlayerPrefab);
newPlayer.SpawnAsPlayerObject(clientId);
var NewEnemy = Instantiate(EnemyPrefab);
NewEnemy.SpawnWithOwnership(NetworkingManager.Singleton.LocalClientId);
var newEnemy = Instantiate(m_EnemyPrefab);
newEnemy.SpawnWithOwnership(NetworkingManager.Singleton.LocalClientId);
}
/// <summary>

13
Assets/BossRoom/Scripts/Server/Net/ServerGNHLogic.cs


// used in ApprovalCheck. This is intended as a bit of light protection against DOS attacks that rely on sending silly big buffers of garbage.
private const int k_MaxConnectPayload = 1024;
// note: MonoBehaviours' constructors are *never* called and this should be removed for clarity
public ServerGNHLogic(GameNetHub hub)
{
m_Hub = hub;
m_Hub.NetManager.ConnectionApprovalCallback += this.ApprovalCheck;
}
m_Hub.NetworkStartEvent += this.NetworkStart;
m_Hub.NetworkStartEvent += NetworkStart;
m_Hub.NetManager.ConnectionApprovalCallback += this.ApprovalCheck;
m_Hub.NetManager.ConnectionApprovalCallback += ApprovalCheck;
}
public void NetworkStart()

this.enabled = false;
enabled = false;
}
else
{

17
Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs


[SerializeField]
private float m_MovementSpeed; // TODO [GOMPS-86] this should be assigned based on character definition
private void Awake()
{
m_NavMeshAgent = GetComponent<NavMeshAgent>();
m_NetworkCharacterState = GetComponent<NetworkCharacterState>();
m_CharLogic = GetComponent<ServerCharacter>();
m_Rigidbody = GetComponent<Rigidbody>();
}
public override void NetworkStart()
{
if (!IsServer)

/// </summary>
public void CancelMove()
{
//Luke, is there anything else I should do to clear move state here?
}
private void Awake()
{
m_NavMeshAgent = GetComponent<NavMeshAgent>();
m_NetworkCharacterState = GetComponent<NetworkCharacterState>();
m_CharLogic = GetComponent<ServerCharacter>();
m_Rigidbody = GetComponent<Rigidbody>();
}
private void FixedUpdate()

69
Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs


using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace BossRoom

RANGEDTARGETED,
CHASE,
//O__O adding a new ActionLogic branch? Update Action.MakeAction!
//O__O adding a new ActionLogic type? Update Action.MakeAction!
}
/// <summary>

{new ActionDescription{Logic=ActionLogic.CHASE } }
}
}
};
}

/// the Action gets played, and also what gets sent server->client to broadcast the action event. Note that the OUTCOMES of the action effect
/// don't ride along with this object when it is broadcast to clients; that information is sync'd separately, usually by NetworkedVars.
/// </summary>
public struct ActionRequestData
public struct ActionRequestData : MLAPI.Serialization.IBitWritable
{
public ActionType ActionTypeEnum; //the action to play.
public Vector3 Position; //center position of skill, e.g. "ground zero" of a fireball skill.

public float Amount; //can mean different things depending on the Action. For a ChaseAction, it will be target range the ChaseAction is trying to achieve.
public bool ShouldQueue; //if true, this action should queue. If false, it should clear all current actions and play immediately.
//O__O Hey, are you adding something? Be sure to update ActionLogicInfo and NetworkCharacterState.SerializeAction, RecvDoAction as well.
//O__O Hey, are you adding something? Be sure to update ActionLogicInfo, as well as the methods below.
public void Read(Stream stream)
{
using (var reader = MLAPI.Serialization.Pooled.PooledBitReader.Get(stream))
{
ActionTypeEnum = (ActionType)reader.ReadInt16();
ShouldQueue = reader.ReadBool();
var Logic = ActionData.ActionDescriptions[ActionTypeEnum][0].Logic;
var Info = ActionData.LogicInfos[Logic];
if (Info.HasPosition)
{
Position = reader.ReadVector3();
}
if (Info.HasDirection)
{
Direction = reader.ReadVector3();
}
if (Info.HasTarget)
{
TargetIds = reader.ReadULongArray();
}
if (Info.HasAmount)
{
Amount = reader.ReadSingle();
}
}
}
public void Write(Stream stream)
{
using (var writer = MLAPI.Serialization.Pooled.PooledBitWriter.Get(stream))
{
ActionLogic Logic = ActionData.ActionDescriptions[ActionTypeEnum][0].Logic;
ActionLogicInfo Info = ActionData.LogicInfos[Logic];
writer.WriteInt16((short)ActionTypeEnum);
writer.WriteBool(ShouldQueue);
if (Info.HasPosition)
{
writer.WriteVector3(Position);
}
if (Info.HasDirection)
{
writer.WriteVector3(Direction);
}
if (Info.HasTarget)
{
writer.WriteULongArray(TargetIds);
}
if (Info.HasAmount)
{
writer.WriteSingle(Amount);
}
}
}
}
}

78
Assets/BossRoom/Scripts/Shared/NetworkCharacterState.cs


/// Client->Server RPC that sends a request to play an action.
/// </summary>
/// <param name="data">Data about which action to play an dits associated details. </param>
public void C2S_DoAction(ref ActionRequestData data)
public void ClientSendActionRequest(ref ActionRequestData data)
SerializeAction(ref data, stream);
data.Write(stream);
InvokeServerRpcPerformance(RecvDoActionServer, stream);
}
}

/// </summary>
/// <param name="data">The data associated with this Action, including what action type it is.</param>
public void S2C_BroadcastAction(ref ActionRequestData data )
public void ServerBroadcastAction(ref ActionRequestData data )
SerializeAction(ref data, stream);
data.Write(stream);
private void SerializeAction( ref ActionRequestData data, PooledBitStream stream )
{
var Logic = ActionData.ActionDescriptions[data.ActionTypeEnum][0].Logic;
var Info = ActionData.LogicInfos[Logic];
using (PooledBitWriter writer = PooledBitWriter.Get(stream))
{
writer.WriteInt16((short)data.ActionTypeEnum);
writer.WriteBool(data.ShouldQueue);
if( Info.HasPosition )
{
writer.WriteVector3(data.Position);
}
if (Info.HasDirection)
{
writer.WriteVector3(data.Direction);
}
if (Info.HasTarget )
{
writer.WriteULongArray(data.TargetIds);
}
if( Info.HasAmount )
{
writer.WriteSingle(data.Amount);
}
}
}
ActionRequestData data = RecvDoAction(clientId, stream);
var data = new ActionRequestData();
data.Read(stream);
DoActionEventClient?.Invoke(data);
}

ActionRequestData data = RecvDoAction(clientId, stream);
var data = new ActionRequestData();
data.Read(stream);
private ActionRequestData RecvDoAction(ulong clientId, Stream stream )
{
ActionRequestData data = new ActionRequestData();
using (PooledBitReader reader = PooledBitReader.Get(stream))
{
data.ActionTypeEnum = (ActionType)reader.ReadInt16();
data.ShouldQueue = reader.ReadBool();
var Logic = ActionData.ActionDescriptions[data.ActionTypeEnum][0].Logic;
var Info = ActionData.LogicInfos[Logic];
if (Info.HasPosition)
{
data.Position = reader.ReadVector3();
}
if (Info.HasDirection)
{
data.Direction = reader.ReadVector3();
}
if (Info.HasTarget)
{
data.TargetIds = reader.ReadULongArray();
}
if (Info.HasAmount)
{
data.Amount = reader.ReadSingle();
}
}
return data;
}
}
}

3
ProjectSettings/TagManager.asset


--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
tags:
- CMCamera
layers:
- Default
- TransparentFX

正在加载...
取消
保存