Moar Gamecraft commands!
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

55 satır
2.1KB

  1. using System;
  2. using System.Collections.Generic;
  3. using RobocraftX.GUI.CommandLine;
  4. using RobocraftX.Multiplayer;
  5. using RobocraftX.StateSync;
  6. using RobocraftX.Character;
  7. using Svelto.ECS;
  8. using Unity.Entities;
  9. using uREPL;
  10. using Svelto.Context;
  11. using RobocraftX;
  12. namespace ExtraCommands.Waypoints
  13. {
  14. [CustomCommand("CreateWaypoint", "Create a waypoint in your current location")]
  15. [CustomCommand("TeleportPlayerWaypoint", "Teleport to a waypoint")]
  16. class TeleportWaypointCommandEngine : CustomCommandEngine
  17. {
  18. private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>();
  19. public TeleportWaypointCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
  20. {
  21. }
  22. public override void Ready()
  23. {
  24. uREPL.RuntimeCommands.Register<object>("CreateWaypoint", CreateWaypointCommand);
  25. uREPL.RuntimeCommands.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand);
  26. }
  27. private void CreateWaypointCommand(object name)
  28. {
  29. ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup);
  30. _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z };
  31. uREPL.Log.Output("Saved " + name.ToString());
  32. }
  33. private void TeleportToWaypointCommand(object name)
  34. {
  35. if (!_waypoints.ContainsKey(name))
  36. {
  37. uREPL.Log.Error("Waypoint not found");
  38. return;
  39. }
  40. float[] loc = _waypoints[name];
  41. uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
  42. }
  43. public override void Dispose()
  44. {
  45. uREPL.RuntimeCommands.Unregister("CreateWaypoint");
  46. uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint");
  47. }
  48. }
  49. }