156 lines
4.8 KiB
C#
156 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using FlaxEngine;
|
|
using FlaxEngine.Networking;
|
|
#if FLAX_EDITOR
|
|
using FlaxEditor.CustomEditors.Dedicated;
|
|
using FlaxEditor.Scripting;
|
|
#endif
|
|
|
|
namespace Game
|
|
{
|
|
#if FLAX_EDITOR
|
|
[CustomEditor(typeof(PlayerActor))]
|
|
public class PlayerActorEditor : ActorEditor
|
|
{
|
|
protected override List<ItemInfo> GetItemsForType(ScriptType type)
|
|
{
|
|
var items = GetItemsForType(type, type.IsClass, true);
|
|
|
|
// Remove all Rigid Body options
|
|
items.RemoveAll(x => x.Display?.Group == "Rigid Body");
|
|
|
|
// Inject scripts editor
|
|
ScriptMemberInfo scriptsMember = type.GetProperty("Scripts");
|
|
if (scriptsMember != ScriptMemberInfo.Null)
|
|
{
|
|
ItemInfo item = new ItemInfo(scriptsMember)
|
|
{
|
|
CustomEditor = new CustomEditorAttribute(typeof(ScriptsEditor))
|
|
};
|
|
items.Add(item);
|
|
}
|
|
|
|
return items;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
public class SomeActor : EmptyActor
|
|
{
|
|
|
|
}
|
|
|
|
public class PlayerActor : RigidBody//, INetworkSerializable
|
|
{
|
|
private PlayerMovement playerMovement;
|
|
public CapsuleCollider capsuleCollider;
|
|
public BoxCollider boxCollider;
|
|
public MeshCollider meshCollider;
|
|
|
|
//[NetworkReplicated]
|
|
public uint PlayerId = uint.MaxValue;
|
|
|
|
/*public PlayerActor()
|
|
{
|
|
// Default internal values for RigidBody
|
|
IsKinematic = true;
|
|
EnableGravity = false;
|
|
LinearDamping = 0f;
|
|
AngularDamping = 0f;
|
|
Constraints = RigidbodyConstraints.LockRotation;
|
|
}*/
|
|
|
|
public override void OnBeginPlay()
|
|
{
|
|
// Default internal values for RigidBody
|
|
IsKinematic = true;
|
|
EnableGravity = false;
|
|
LinearDamping = 0f;
|
|
AngularDamping = 0f;
|
|
Constraints = RigidbodyConstraints.LockRotation;
|
|
|
|
base.OnBeginPlay();
|
|
|
|
playerMovement = FindScript<PlayerMovement>();
|
|
capsuleCollider = GetChild<CapsuleCollider>();
|
|
boxCollider = GetChild<BoxCollider>();
|
|
meshCollider = GetChild<MeshCollider>();
|
|
//playerRigidBody = FindActor<RigidBody>();
|
|
|
|
|
|
|
|
//Console.Print("OnBeginPlay playerid: " + PlayerId.ToString());
|
|
//playerMovement.input = new PlayerInputNetwork();
|
|
}
|
|
|
|
public override void OnEnable()
|
|
{
|
|
// Trigger OnEnable manually, does not seem to propagate when parent gets enabled/disabled
|
|
playerMovement.Enabled = true;
|
|
//NetworkReplicator.AddObject(this);
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
playerMovement.Enabled = false;
|
|
//NetworkReplicator.RemoveObject(this);
|
|
}
|
|
|
|
//[NetworkRpc(client: true)]
|
|
public void Initialize(uint playerId, Float3 newPosition, Float3 eulerAngles)
|
|
{
|
|
if (PlayerId == playerId) // FIXME
|
|
return;
|
|
|
|
FindActor("PlayerModel").IsActive = true;
|
|
IsActive = true;
|
|
|
|
PlayerId = playerId;
|
|
playerMovement.SetInput(playerId);
|
|
if (playerId == NetworkManager.LocalPlayerClientId)
|
|
{
|
|
FindActor("CameraHolder").IsActive = true;
|
|
//FindActor("ViewModelHolder").IsActive = true;
|
|
FindActor("PlayerModel").IsActive = false;
|
|
}
|
|
SetPosition(newPosition);
|
|
SetRotation(eulerAngles);
|
|
//else
|
|
// FindActor("PlayerModel").IsActive = true;
|
|
//IsActive = true;
|
|
}
|
|
|
|
//[NetworkRpc(server: true)]
|
|
public void UpdateNetworkInput(PlayerInputState inputState/*, Float4 viewDeltaXYMoveForwardRight, bool attacking, bool jumping*/)
|
|
{
|
|
if (playerMovement.input is not PlayerInputNetwork playerInputNetwork)
|
|
return;
|
|
|
|
//PlayerInputState inputState = new PlayerInputState(frame, viewDeltaXYMoveForwardRight.X, viewDeltaXYMoveForwardRight.Y, viewDeltaXYMoveForwardRight.Z, viewDeltaXYMoveForwardRight.W, attacking, jumping);
|
|
//playerInputNetwork.currentState.input = inputState;
|
|
playerInputNetwork.SetState(inputState.frame, inputState);
|
|
}
|
|
|
|
public void SetPosition(Float3 newPosition)
|
|
{
|
|
Position = newPosition;
|
|
}
|
|
|
|
public void SetRotation(Float3 eulerAngles)
|
|
{
|
|
playerMovement.ResetRotation(eulerAngles);
|
|
}
|
|
|
|
public Float3 GetRotation()
|
|
{
|
|
return playerMovement.viewAngles;
|
|
}
|
|
|
|
//[NetworkRpc(client: true)]
|
|
public void Teleport(Float3 newPosition, Float3 eulerAngles)
|
|
{
|
|
SetPosition(newPosition);
|
|
SetRotation(eulerAngles);
|
|
}
|
|
}
|
|
} |