### C# Custom Movement with Frame-Based Timer and Callbacks Source: https://context7.com/et-packages/cn.etetet.move/llms.txt This snippet demonstrates a custom movement controller in C# that utilizes a frame-based timer for interpolating unit positions. It includes logic for monitoring movement progress, implementing timeouts, and detecting obstacles during the movement phase. Dependencies include ET framework components like MoveComponent, TimerComponent, and TimeInfo. ```csharp using ET; using Unity.Mathematics; // Example: Custom movement with external timer management public class CustomMoveController { public async ETTask MoveWithCallback(Unit unit, List path, float speed) { MoveComponent moveComp = unit.GetComponent(); // Track movement progress with callback long startTime = TimeInfo.Instance.ClientNow(); // Start movement var moveTask = moveComp.MoveToAsync(path, speed, turnTime: 150); // Monitor progress in parallel while (!moveComp.IsArrived()) { await TimerComponent.Instance.WaitFrameAsync(); // Calculate elapsed time long elapsed = TimeInfo.Instance.ClientNow() - startTime; // Custom logic during movement if (elapsed > 5000) // 5 seconds timeout { moveComp.Stop(false); Log.Warning("Movement timeout - stopping unit"); break; } // Check for obstacles if (DetectObstacle(unit.Position)) { moveComp.Stop(false); Log.Info("Obstacle detected - stopping unit"); break; } } bool success = await moveTask; return success; } private bool DetectObstacle(float3 position) { // Raycast or physics check implementation return false; } } ``` -------------------------------- ### Handle Movement Events - C# Source: https://context7.com/et-packages/cn.etetet.move/llms.txt The system emits MoveStart and MoveStop events to notify other game systems when a unit's movement begins or ends. These events can be handled using ET's event system to trigger animations, particle effects, or other state changes. Event handlers are implemented as classes inheriting from AEvent. ```csharp using ET; // Example: Listen for movement events [Event(SceneType.Current)] public class MoveStartHandler : AEvent { protected override async ETTask Run(Scene scene, MoveStart args) { Unit unit = args.Unit; Log.Info($"Unit {unit.Id} started moving"); // Trigger walk animation AnimatorComponent animator = unit.GetComponent(); animator?.SetBool("IsWalking", true); // Enable movement particles EffectComponent effects = unit.GetComponent(); effects?.PlayEffect("DustTrail"); await ETTask.CompletedTask; } } [Event(SceneType.Current)] public class MoveStopHandler : AEvent { protected override async ETTask Run(Scene scene, MoveStop args) { Unit unit = args.Unit; Log.Info($"Unit {unit.Id} stopped moving"); // Trigger idle animation AnimatorComponent animator = unit.GetComponent(); animator?.SetBool("IsWalking", false); // Disable movement particles EffectComponent effects = unit.GetComponent(); effects?.StopEffect("DustTrail"); await ETTask.CompletedTask; } } ``` -------------------------------- ### Move along path asynchronously with ET.Move in C# Source: https://context7.com/et-packages/cn.etetet.move/llms.txt Initiates movement for a unit along a series of waypoints. This C# API takes a list of float3 positions, movement speed, and turn interpolation time. It returns a task that indicates whether the movement was completed successfully or cancelled. ```csharp using ET; using Unity.Mathematics; using System.Collections.Generic; // Example: Move a unit along a path Unit playerUnit = GetPlayerUnit(); MoveComponent moveComp = playerUnit.GetComponent(); // Define a path with multiple waypoints List path = new List { new float3(0, 0, 0), // Starting position new float3(10, 0, 5), // Waypoint 1 new float3(20, 0, 15), // Waypoint 2 new float3(30, 0, 20) // Final destination }; float moveSpeed = 5.0f; // 5 meters per second int turnTime = 100; // 100ms turn interpolation // Start movement and await completion bool success = await moveComp.MoveToAsync(path, moveSpeed, turnTime); if (success) { Log.Info("Unit reached destination successfully"); } else { Log.Info("Movement was cancelled or interrupted"); } ``` -------------------------------- ### C# Movement System: Horizontal and Full 3D Rotation Control Source: https://context7.com/et-packages/cn.etetet.move/llms.txt This C# code configures rotation behavior for units during movement, offering options for horizontal-only turning (ground units) or full 3D rotation (flying units). It shows how to enable/disable `IsTurnHorizontal` and manage `turnTime` for smooth or instant rotations. Dependencies include ET framework and Unity.Mathematics. ```csharp using ET; using Unity.Mathematics; using System.Collections.Generic; // Example: Ground unit with horizontal rotation async ETTask MoveGroundUnit(Unit unit, List path) { MoveComponent moveComp = unit.GetComponent(); // Enable horizontal-only turning (default) moveComp.IsTurnHorizontal = true; float speed = 6.0f; int turnTime = 200; // 200ms smooth turn await moveComp.MoveToAsync(path, speed, turnTime); } // Example: Flying unit with full 3D rotation async ETTask MoveFlyingUnit(Unit unit, List path) { MoveComponent moveComp = unit.GetComponent(); // Enable full 3D turning for aerial movement moveComp.IsTurnHorizontal = false; float speed = 15.0f; int turnTime = 100; // Faster turn for flying await moveComp.MoveToAsync(path, speed, turnTime); } // Example: Instant rotation (no turn time) async ETTask MoveWithInstantRotation(Unit unit, List path) { MoveComponent moveComp = unit.GetComponent(); float speed = 5.0f; int turnTime = 0; // Instant rotation, no interpolation // Unit will snap to face movement direction immediately await moveComp.MoveToAsync(path, speed, turnTime); } // Example: Custom rotation control void SetCustomRotation(Unit unit, float3 lookDirection) { MoveComponent moveComp = unit.GetComponent(); // For ground units, zero out Y component if (moveComp.IsTurnHorizontal) { lookDirection.y = 0; } // Calculate rotation quaternion if (math.lengthsq(lookDirection) > 0.0001f) { quaternion rotation = quaternion.LookRotation(lookDirection, math.up()); unit.Rotation = rotation; } } ``` -------------------------------- ### Access Movement State Properties - C# Source: https://context7.com/et-packages/cn.etetet.move/llms.txt The MoveComponent provides properties to query the current movement state of a unit. These include the current position, speed, remaining time, and waypoint information. This allows for detailed debugging and calculation of movement progress. The properties are accessed directly from the MoveComponent instance. ```csharp using ET; using Unity.Mathematics; // Example: Display movement debug information void ShowMovementDebugInfo(Unit unit) { MoveComponent moveComp = unit.GetComponent(); if (moveComp.IsArrived()) { Log.Info("Unit is stationary"); return; } // Access movement properties float3 currentTarget = moveComp.NextTarget; float3 previousTarget = moveComp.PreTarget; float3 finalDestination = moveComp.FinalTarget; float currentSpeed = moveComp.Speed; long timeRemaining = moveComp.NeedTime; int currentWaypoint = moveComp.N; int totalWaypoints = moveComp.Targets.Count; Log.Info($"Moving to waypoint {currentWaypoint}/{totalWaypoints}"); Log.Info($"Speed: {currentSpeed} m/s"); Log.Info($"Next target: {currentTarget}"); Log.Info($"Final destination: {finalDestination}"); Log.Info($"Time to next waypoint: {timeRemaining}ms"); } // Example: Calculate progress percentage float GetMovementProgress(MoveComponent moveComp) { if (moveComp.IsArrived()) { return 100f; } int completed = moveComp.N; int total = moveComp.Targets.Count; return (completed / (float)total) * 100f; } ``` -------------------------------- ### Teleport unit instantly with FlashTo in ET.Move (C#) Source: https://context7.com/et-packages/cn.etetet.move/llms.txt Instantly transports a unit to a specified target position without any movement animation or interpolation. This C# function is ideal for teleportation, respawning, or correcting a unit's position. It returns a boolean indicating the success of the operation. ```csharp using ET; using Unity.Mathematics; // Example: Teleport unit to spawn point Unit unit = GetUnit(); MoveComponent moveComp = unit.GetComponent(); float3 spawnPosition = new float3(100, 0, 100); bool success = moveComp.FlashTo(spawnPosition); if (success) { Log.Info($"Unit teleported to {spawnPosition}"); } // Example: Respawn after death async ETTask RespawnPlayer(Unit playerUnit) { MoveComponent moveComp = playerUnit.GetComponent(); // Stop any existing movement if (!moveComp.IsArrived()) { moveComp.Stop(false); } // Calculate spawn point based on team float3 respawnPoint = GetTeamSpawnPoint(playerUnit.TeamId); // Instant teleport to respawn moveComp.FlashTo(respawnPoint); // Reset unit state playerUnit.Health = playerUnit.MaxHealth; Log.Info($"Player respawned at {respawnPoint}"); } ``` -------------------------------- ### Adjust movement speed dynamically with ET.Move in C# Source: https://context7.com/et-packages/cn.etetet.move/llms.txt Allows changing the movement speed of a unit during active path traversal. This C# function recalculates the remaining path timing based on the new speed. It returns true if the speed was successfully changed, and false otherwise (e.g., invalid speed or unit not moving). ```csharp using ET; using Unity.Mathematics; // Example: Slow down unit when entering hazardous terrain Unit unit = GetUnit(); MoveComponent moveComp = unit.GetComponent(); // Check if unit is currently moving if (!moveComp.IsArrived()) { float newSpeed = 2.5f; // Reduce speed by half bool changed = moveComp.ChangeSpeed(newSpeed); if (changed) { Log.Info($"Speed changed to {newSpeed} m/s"); } else { Log.Warning("Failed to change speed - invalid speed value or unit not moving"); } } // Example: Speed boost on special terrain if (onSpeedBoostPad) { moveComp.ChangeSpeed(10.0f); // Double normal speed } ``` -------------------------------- ### Stop movement instantly with ET.Move in C# Source: https://context7.com/et-packages/cn.etetet.move/llms.txt Immediately halts a unit's current movement operation. This C# API takes a boolean to indicate the result of the stop (e.g., cancellation). It updates the unit's position to its current interpolated location and can be used to manage movement states, such as during combat. ```csharp using ET; // Example: Stop movement when combat begins Unit unit = GetUnit(); MoveComponent moveComp = unit.GetComponent(); // Stop movement and return false to indicate cancellation moveComp.Stop(false); // Check if unit has arrived (no active movement) if (moveComp.IsArrived()) { Log.Info("Unit is now stationary"); } // Example: Emergency stop with cleanup async ETTask HandleCombatStart(Unit unit) { MoveComponent moveComp = unit.GetComponent(); if (!moveComp.IsArrived()) { moveComp.Stop(false); // Cancel current movement Log.Info($"Stopped unit at position: {unit.Position}"); } // Begin combat logic await EnterCombatMode(unit); } ``` -------------------------------- ### Check Movement Status with IsArrived - C# Source: https://context7.com/et-packages/cn.etetet.move/llms.txt The IsArrived method of the MoveComponent checks if a unit has completed all movement and has no pending waypoints. This is useful for determining if a unit is stationary, allowing subsequent actions to be performed only after arrival. It can be used in loops to poll for arrival or to check the status of multiple units in a squad. ```csharp using ET; // Example: Wait for unit to finish moving before starting action async ETTask PerformActionAtDestination(Unit unit) { MoveComponent moveComp = unit.GetComponent(); // Poll until arrival (alternative to awaiting MoveToAsync) while (!moveComp.IsArrived()) { await TimerComponent.Instance.WaitFrameAsync(); } // Unit has arrived, perform action PerformInteraction(unit); } // Example: Check if any units in squad are moving bool IsSquadStationary(List squad) { foreach (Unit unit in squad) { MoveComponent moveComp = unit.GetComponent(); if (!moveComp.IsArrived()) { return false; // At least one unit is still moving } } return true; // All units are stationary } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.