浏览代码
adding ChaseAction. refactoring actions a bit so that ActionLogic metadata is used to serialize the ActionRequestData. Making Action queueing behavior specifiable in the ActionRequestData. Hooking up an example where a player 'moves and attacks' in ClientInputSender. Adding a ClientCharacterMovement component to move the base Player GameObject (previously only the visualization was moving)
/main
adding ChaseAction. refactoring actions a bit so that ActionLogic metadata is used to serialize the ActionRequestData. Making Action queueing behavior specifiable in the ActionRequestData. Hooking up an example where a player 'moves and attacks' in ClientInputSender. Adding a ClientCharacterMovement component to move the base Player GameObject (previously only the visualization was moving)
/main
David Woodruff
4 年前
当前提交
63c07658
共有 12 个文件被更改,包括 322 次插入 和 27 次删除
-
17Assets/BossRoom/Prefabs/Player.prefab
-
38Assets/BossRoom/Scripts/Client/ClientInputSender.cs
-
13Assets/BossRoom/Scripts/Server/Game/Action/Action.cs
-
19Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs
-
13Assets/BossRoom/Scripts/Server/Game/Character/ServerCharacter.cs
-
27Assets/BossRoom/Scripts/Server/ServerCharacterMovement.cs
-
47Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs
-
37Assets/BossRoom/Scripts/Shared/NetworkCharacterState.cs
-
40Assets/BossRoom/Scripts/Client/Game/Character/ClientCharacterMovement.cs
-
11Assets/BossRoom/Scripts/Client/Game/Character/ClientCharacterMovement.cs.meta
-
76Assets/BossRoom/Scripts/Server/Game/Action/ChaseAction.cs
-
11Assets/BossRoom/Scripts/Server/Game/Action/ChaseAction.cs.meta
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace BossRoom.Client |
|||
{ |
|||
/// <summary>
|
|||
/// Client-side of character movement game logic.
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(NetworkCharacterState))] |
|||
public class ClientCharacterMovement : MLAPI.NetworkedBehaviour |
|||
{ |
|||
private NetworkCharacterState m_NetState; |
|||
|
|||
|
|||
// Start is called before the first frame update
|
|||
void Start() |
|||
{ |
|||
m_NetState = GetComponent<NetworkCharacterState>(); |
|||
} |
|||
|
|||
public override void NetworkStart() |
|||
{ |
|||
if (IsServer) |
|||
{ |
|||
//this component is not needed on the host (or dedicated server), because ServerCharacterMovement will directly
|
|||
//update the character's position.
|
|||
this.enabled = false; |
|||
} |
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void Update() |
|||
{ |
|||
transform.position = m_NetState.NetworkPosition.Value; |
|||
transform.rotation = Quaternion.Euler(0, m_NetState.NetworkRotationY.Value, 0); |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 797d92969c575574d868e069887e8486 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using MLAPI; |
|||
|
|||
namespace BossRoom.Server |
|||
{ |
|||
public class ChaseAction : Action |
|||
{ |
|||
private NetworkedObject m_Target; |
|||
private ServerCharacterMovement m_Movement; |
|||
|
|||
private Vector3 m_CurrentTargetPos; |
|||
|
|||
public ChaseAction(ServerCharacter parent, ref ActionRequestData data, int level) : base(parent, ref data, level) |
|||
{ |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Called when the Action starts actually playing (which may be after it is created, because of queueing).
|
|||
/// </summary>
|
|||
/// <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]) ) |
|||
{ |
|||
Debug.Log("Failed to start ChaseAction. The target entity wasn't submitted or doesn't exist anymore" ); |
|||
return false; |
|||
} |
|||
|
|||
m_Target = MLAPI.Spawning.SpawnManager.SpawnedObjects[m_data.TargetIds[0]]; |
|||
|
|||
m_Movement = m_parent.GetComponent<ServerCharacterMovement>(); |
|||
m_Movement.SetMovementTarget(m_Target.transform.position); |
|||
m_CurrentTargetPos = m_Target.transform.position; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Called each frame while the action is running.
|
|||
/// </summary>
|
|||
/// <returns>true to keep running, false to stop. The Action will stop by default when its duration expires, if it has a duration set. </returns>
|
|||
public override bool Update() |
|||
{ |
|||
float dist_to_target = (m_parent.transform.position - m_Target.transform.position).magnitude; |
|||
if( m_data.Amount > dist_to_target ) |
|||
{ |
|||
//we made it! we're done.
|
|||
Cancel(); |
|||
return false; |
|||
} |
|||
|
|||
float target_moved = (m_Target.transform.position - m_CurrentTargetPos).magnitude; |
|||
if( m_data.Amount < target_moved ) |
|||
{ |
|||
//target has moved past our range tolerance. Must repath.
|
|||
this.m_Movement.SetMovementTarget(m_Target.transform.position); |
|||
m_CurrentTargetPos = m_Target.transform.position; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
public override void Cancel() |
|||
{ |
|||
if( m_Movement != null ) |
|||
{ |
|||
m_Movement.CancelMove(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bc4a33f0facd1914f81611eb7038be06 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue