93 lines
2.6 KiB
C#
93 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using Cabrito;
|
|
using FlaxEngine;
|
|
#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>();
|
|
}
|
|
|
|
public void Initialize(uint playerId)
|
|
{
|
|
playerMovement.SetInput(playerId);
|
|
if (playerId == NetworkManager.LocalPlayerClientId)
|
|
{
|
|
FindActor("CameraHolder").IsActive = true;
|
|
FindActor("ViewModelHolder").IsActive = true;
|
|
}
|
|
}
|
|
|
|
public void UpdateNetworkInput(PlayerInputState inputState)
|
|
{
|
|
if (playerMovement.input is PlayerInputNetwork)
|
|
(playerMovement.input as PlayerInputNetwork).currentState.input = inputState;
|
|
}
|
|
|
|
public void SetPosition(Vector3 newPosition)
|
|
{
|
|
Position = newPosition;
|
|
}
|
|
|
|
public void SetRotation(Vector3 eulerAngles)
|
|
{
|
|
playerMovement.ResetRotation(eulerAngles);
|
|
}
|
|
|
|
public void Teleport(Vector3 newPosition, Vector3 eulerAngles)
|
|
{
|
|
SetPosition(newPosition);
|
|
SetRotation(eulerAngles);
|
|
}
|
|
}
|
|
} |