|
- using System;
- using System.Collections.Generic;
- using RobocraftX.GUI.CommandLine;
- using RobocraftX.Multiplayer;
- using RobocraftX.StateSync;
- using RobocraftX.Character;
- using Svelto.ECS;
- using Unity.Entities;
- using uREPL;
- using Svelto.Context;
- using RobocraftX;
-
- namespace ExtraCommands.Waypoints
- {
- [CustomCommand("CreateWaypoint", "Create a waypoint in your current location")]
- [CustomCommand("TeleportPlayerWaypoint", "Teleport to a waypoint")]
- class TeleportWaypointCommandEngine : CustomCommandEngine
- {
- private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>();
- public TeleportWaypointCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
- {
- }
-
- public override void Ready()
- {
- uREPL.RuntimeCommands.Register<object>("CreateWaypoint", CreateWaypointCommand);
- uREPL.RuntimeCommands.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand);
- }
-
- private void CreateWaypointCommand(object name)
- {
- ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup);
- _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z };
- uREPL.Log.Output("Saved " + name.ToString());
- }
-
- private void TeleportToWaypointCommand(object name)
- {
- if (!_waypoints.ContainsKey(name))
- {
- uREPL.Log.Error("Waypoint not found");
- return;
- }
- float[] loc = _waypoints[name];
- uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
- }
-
- public override void Dispose()
- {
- uREPL.RuntimeCommands.Unregister("CreateWaypoint");
- uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint");
- }
- }
- }
|