Added Swap
parent
8ab130dc7d
commit
7b825ef1b3
@ -0,0 +1,43 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 51bc649ad66145f4f9160e06d4162795, type: 3}
|
||||||
|
m_Name: Swap
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
Config:
|
||||||
|
Logic: 18
|
||||||
|
Amount: 0
|
||||||
|
ManaCost: 0
|
||||||
|
Range: 0
|
||||||
|
DurationSeconds: 0
|
||||||
|
ExecTimeSeconds: 0
|
||||||
|
EffectDurationSeconds: 0
|
||||||
|
ReuseTimeSeconds: 0
|
||||||
|
AnimAnticipation:
|
||||||
|
Anim:
|
||||||
|
Anim2:
|
||||||
|
ReactAnim:
|
||||||
|
OtherAnimatorVariable:
|
||||||
|
SplashDamage: 0
|
||||||
|
MoveSpeed: 0
|
||||||
|
KnockbackSpeed: 0
|
||||||
|
KnockbackDuration: 0
|
||||||
|
Radius: 0
|
||||||
|
ActionInput: {fileID: 0}
|
||||||
|
ActionInterruptible: 0
|
||||||
|
IsInterruptableBy: []
|
||||||
|
BlockingMode: 1
|
||||||
|
Projectiles: []
|
||||||
|
Spawns: []
|
||||||
|
IsFriendly: 0
|
||||||
|
Icon: {fileID: 0}
|
||||||
|
DisplayedName:
|
||||||
|
Description:
|
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c55ead416f0a54c4f95b4664d7e5bea1
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Binary file not shown.
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cd817e3eace813041ad4d732be64af84
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 23800000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,73 @@
|
|||||||
|
using Unity.BossRoom.Gameplay.Actions;
|
||||||
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
||||||
|
using Unity.Netcode;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CreateAssetMenu(menuName = "BossRoom/Actions/Swap Action")]
|
||||||
|
public class SwapAction : Action
|
||||||
|
{
|
||||||
|
private ServerCharacter m_TargetCharacter; // The character to swap with
|
||||||
|
private Vector3 m_TargetOriginalPosition; // Target's original position
|
||||||
|
private Vector3 m_ServerCharacterOriginalPosition; // Server character's original position
|
||||||
|
private bool m_MovementStarted = false; // Ensures movement commands are sent only once
|
||||||
|
|
||||||
|
public override bool OnStart(ServerCharacter serverCharacter)
|
||||||
|
{
|
||||||
|
// Validate the target
|
||||||
|
if (Data.TargetIds == null || Data.TargetIds.Length == 0)
|
||||||
|
{
|
||||||
|
Debug.LogError("SwapAction failed: No target specified!");
|
||||||
|
return false; // End the action immediately
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the target character
|
||||||
|
if (!NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(Data.TargetIds[0], out var targetObject) ||
|
||||||
|
!targetObject.TryGetComponent(out m_TargetCharacter))
|
||||||
|
{
|
||||||
|
Debug.LogError("SwapAction failed: Target is invalid or missing!");
|
||||||
|
return false; // End the action immediately
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store original positions
|
||||||
|
m_ServerCharacterOriginalPosition = serverCharacter.physicsWrapper.Transform.position;
|
||||||
|
m_TargetOriginalPosition = m_TargetCharacter.physicsWrapper.Transform.position;
|
||||||
|
|
||||||
|
// Command both characters to move to each other's original positions
|
||||||
|
serverCharacter.ServerSendCharacterInputRpc(m_TargetOriginalPosition);
|
||||||
|
m_TargetCharacter.ServerSendCharacterInputRpc(m_ServerCharacterOriginalPosition);
|
||||||
|
|
||||||
|
Debug.Log("SwapAction: Movement commands sent to both players.");
|
||||||
|
m_MovementStarted = true;
|
||||||
|
return true; // Keep the action active
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnUpdate(ServerCharacter serverCharacter)
|
||||||
|
{
|
||||||
|
if (!m_MovementStarted)
|
||||||
|
{
|
||||||
|
Debug.LogError("SwapAction OnUpdate called without movement initialization!");
|
||||||
|
return false; // Fail-safe: End the action
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if both characters have reached their destinations
|
||||||
|
bool serverCharacterReached = Vector3.Distance(serverCharacter.physicsWrapper.Transform.position, m_TargetOriginalPosition) < 0.1f;
|
||||||
|
bool targetCharacterReached = Vector3.Distance(m_TargetCharacter.physicsWrapper.Transform.position, m_ServerCharacterOriginalPosition) < 0.1f;
|
||||||
|
|
||||||
|
if (serverCharacterReached && targetCharacterReached)
|
||||||
|
{
|
||||||
|
Debug.Log("SwapAction: Both players have swapped positions successfully.");
|
||||||
|
return false; // End the action
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; // Continue the action until both characters reach their destinations
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
base.Reset();
|
||||||
|
m_TargetCharacter = null;
|
||||||
|
m_TargetOriginalPosition = Vector3.zero;
|
||||||
|
m_ServerCharacterOriginalPosition = Vector3.zero;
|
||||||
|
m_MovementStarted = false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 51bc649ad66145f4f9160e06d4162795
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue