97 lines
2.8 KiB
C#
97 lines
2.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 PlayerActor : RigidBody
|
|
{
|
|
private PlayerMovement playerMovement;
|
|
private RigidBody playerRigidBody;
|
|
|
|
public PlayerActor()
|
|
{
|
|
// Default internal values for RigidBody
|
|
IsKinematic = true;
|
|
EnableGravity = false;
|
|
LinearDamping = 0f;
|
|
AngularDamping = 0f;
|
|
Constraints = RigidbodyConstraints.LockRotation;
|
|
}
|
|
|
|
public override void OnBeginPlay()
|
|
{
|
|
base.OnBeginPlay();
|
|
|
|
playerMovement = FindScript<PlayerMovement>();
|
|
playerRigidBody = FindActor<RigidBody>();
|
|
|
|
NetworkReplicator.AddObject(this);
|
|
}
|
|
|
|
public void Initialize(uint playerId)
|
|
{
|
|
playerMovement.SetInput(playerId);
|
|
//if (playerId == NetworkManager.LocalPlayerClientId)
|
|
if (NetworkReplicator.GetObjectRole(this) == NetworkObjectRole.OwnedAuthoritative)
|
|
{
|
|
FindActor("CameraHolder").IsActive = true;
|
|
//FindActor("ViewModelHolder").IsActive = true;
|
|
FindActor("PlayerModel").IsActive = false;
|
|
}
|
|
}
|
|
|
|
public void UpdateNetworkInput(PlayerInputState inputState)
|
|
{
|
|
if (playerMovement.input is PlayerInputNetwork)
|
|
(playerMovement.input as PlayerInputNetwork).currentState.input = inputState;
|
|
}
|
|
|
|
public void SetPosition(Float3 newPosition)
|
|
{
|
|
Position = newPosition;
|
|
}
|
|
|
|
public void SetRotation(Float3 eulerAngles)
|
|
{
|
|
playerMovement.ResetRotation(eulerAngles);
|
|
}
|
|
|
|
public void Teleport(Float3 newPosition, Float3 eulerAngles)
|
|
{
|
|
SetPosition(newPosition);
|
|
SetRotation(eulerAngles);
|
|
}
|
|
}
|
|
} |