|
- using System;
- using RobocraftX.GUI.CommandLine;
- using RobocraftX.Multiplayer;
- using RobocraftX.StateSync;
- using RobocraftX.Character;
- using Svelto.ECS;
- using Unity.Entities;
- using UnityEngine;
- using uREPL;
- using Svelto.Context;
- using RobocraftX;
- using Svelto.ECS.EntityStructs;
- using Unity.Mathematics;
- using RobocraftX.Character.Camera;
- using RobocraftX.Character.Factories;
-
- namespace ExtraCommands.Basics
- {
- [CustomCommand("RotateTo")]
- class RotatePlayerCommandEngine : CustomCommandEngine
- {
-
- public RotatePlayerCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
- {
- }
-
- public override void Ready()
- {
- CustomCommandUtility.Register<float, float>("RotateAbsolute", RotateAbsoluteCommand, "Rotate the player camera to the entered rotation");
- CustomCommandUtility.Register<float, float>("RotateRelative", RotateRelativeCommand, "Rotate the player camera by the entered rotation");
- }
-
-
- private void RotateAbsoluteCommand(float vertical, float horizontal)
- {
- uint count;
- CharacterCameraEntityStruct[] cameras = entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count);
- int num2 = 0;
- while ((long)num2 < (long)((ulong)count))
- {
- cameras[num2].eulerRotation.x = vertical;
- cameras[num2].eulerRotation.y = horizontal;
- // TODO: Multiplayer compatibility
- /*
- uint num3;
- InputEntityStruct[] array;
- if (this.entitiesDB.TryQueryEntitiesAndIndex<InputEntityStruct>(item2[num2].ID.entityID, PlayersExclusiveGroups.LocalPlayers, out num3, out array))
- {
- desiredDistance = math.clamp(desiredDistance, 0f, item[num2].maxDistance);
- array[(int)num3].cameraZoomFactor = math.unlerp(item[num2].minDistance, item[num2].maxDistance, desiredDistance);
- }
- */
- num2++;
- }
- }
-
- private void RotateRelativeCommand(float vertical, float horizontal)
- {
- float2 angleDelta = new float2(vertical, horizontal);
- uint count;
- ValueTuple<CharacterCameraSettingsEntityStruct[], CharacterCameraEntityStruct[]> tuple = this.entitiesDB.QueryEntities<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count);
- CharacterCameraSettingsEntityStruct[] settings = tuple.Item1;
- CharacterCameraEntityStruct[] cameras = tuple.Item2;
- int num2 = 0;
- while ((long)num2 < (long)((ulong)count))
- {
- CharacterCameraMovementUtility.UpdateCameraRotationFromDelta(ref cameras[num2], in settings[num2], angleDelta);
- // TODO: Multiplayer compatibility
- /*
- uint num3;
- InputEntityStruct[] array;
- if (this.entitiesDB.TryQueryEntitiesAndIndex<InputEntityStruct>(item2[num2].ID.entityID, PlayersExclusiveGroups.LocalPlayers, out num3, out array))
- {
- desiredDistance = math.clamp(desiredDistance, 0f, item[num2].maxDistance);
- array[(int)num3].cameraZoomFactor = math.unlerp(item[num2].minDistance, item[num2].maxDistance, desiredDistance);
- }
- */
- num2++;
- }
- }
-
- public override void Dispose()
- {
- CustomCommandUtility.Unregister("RotateAbsolute");
- CustomCommandUtility.Unregister("RotateRelative");
- }
- }
- }
|