added: full logic and ability for downing and picking up allies

This commit is contained in:
Chris
2025-10-20 16:36:23 -04:00
parent 021e664320
commit 0bb10a8f46
10 changed files with 489 additions and 64 deletions

File diff suppressed because one or more lines are too long

View File

@@ -497,6 +497,31 @@ BlendTree:
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 0
--- !u!1101 &-1649584047298262204
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: PickUp
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -3079066222818897921}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.87603307
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-1540905845034213700
AnimatorStateTransition:
m_ObjectHideFlags: 1
@@ -641,6 +666,18 @@ AnimatorController:
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Downed
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: PickUp
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
@@ -754,14 +791,14 @@ AnimatorStateMachine:
m_Position: {x: 910, y: 230, z: 0}
- serializedVersion: 1
m_State: {fileID: 6032011949097874162}
m_Position: {x: 520, y: 570, z: 0}
m_Position: {x: 30, y: 250, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions:
- {fileID: 3576987541970407646}
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 230, y: 570, z: 0}
m_AnyStatePosition: {x: -190, y: 260, z: 0}
m_EntryPosition: {x: 10, y: 150, z: 0}
m_ExitPosition: {x: 1310, y: 280, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
@@ -825,7 +862,10 @@ AnimatorStateTransition:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Downed
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 6032011949097874162}
m_Solo: 0
@@ -974,10 +1014,11 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: New State
m_Name: Downed
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_Transitions:
- {fileID: -1649584047298262204}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0

View File

@@ -175,7 +175,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.NetworkObject
GlobalObjectIdHash: 3816484910
GlobalObjectIdHash: 1109077195
InScenePlacedSourceGlobalObjectIdHash: 0
DeferredDespawnTick: 0
Ownership: 1
@@ -201,6 +201,76 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
ShowTopMostFoldoutHeaderGroup: 1
state:
testSTate:
m_InternalValue:
utf8LengthInBytes: 0
bytes:
offset0000:
byte0000: 0
byte0001: 0
byte0002: 0
byte0003: 0
byte0004: 0
byte0005: 0
byte0006: 0
byte0007: 0
byte0008: 0
byte0009: 0
byte0010: 0
byte0011: 0
byte0012: 0
byte0013: 0
byte0014: 0
byte0015: 0
offset0016:
byte0000: 0
byte0001: 0
byte0002: 0
byte0003: 0
byte0004: 0
byte0005: 0
byte0006: 0
byte0007: 0
byte0008: 0
byte0009: 0
byte0010: 0
byte0011: 0
byte0012: 0
byte0013: 0
byte0014: 0
byte0015: 0
offset0032:
byte0000: 0
byte0001: 0
byte0002: 0
byte0003: 0
byte0004: 0
byte0005: 0
byte0006: 0
byte0007: 0
byte0008: 0
byte0009: 0
byte0010: 0
byte0011: 0
byte0012: 0
byte0013: 0
byte0014: 0
byte0015: 0
byte0048: 0
byte0049: 0
byte0050: 0
byte0051: 0
byte0052: 0
byte0053: 0
byte0054: 0
byte0055: 0
byte0056: 0
byte0057: 0
byte0058: 0
byte0059: 0
byte0060: 0
byte0061: 0
controls: {fileID: 0}
_isDowned:
m_InternalValue: 1
@@ -794,8 +864,8 @@ MonoBehaviour:
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"Combat
Information":{"_value":{},"_name":"Combat Information","_id":"a15396c3-5ba0-4789-b5c5-39a6cfea1943","$type":"NodeCanvas.Framework.Variable`1[[NodeCanvas.Framework.VariableSeperator,
ParadoxNotion, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"inGoHard":{"_propertyPath":"PlayerMeter.inGoHard","_name":"inGoHard","_id":"dc9f60c8-856e-4970-bf11-25745eff1201","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"pickupTarget":{"_propertyPath":"Reset.Units.Player.pickupTarget","_name":"pickupTarget","_id":"bf809a37-76c1-4dd7-8528-cc09527cb016","$type":"NodeCanvas.Framework.Variable`1[[Reset.Units.Player,
Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}'
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"testobject":{"_name":"testobject","_id":"45e90651-1912-40ef-b4fc-6c27d00d0ef0","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}'
_objectReferences:
- {fileID: 0}
- {fileID: 8505492416078151957}
@@ -835,8 +905,8 @@ MonoBehaviour:
- _json: '{"_propertyPath":"PlayerMeter.inGoHard","_name":"inGoHard","_id":"dc9f60c8-856e-4970-bf11-25745eff1201","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}'
_references: []
- _json: '{"_propertyPath":"Reset.Units.Player.pickupTarget","_name":"pickupTarget","_id":"bf809a37-76c1-4dd7-8528-cc09527cb016","$type":"NodeCanvas.Framework.Variable`1[[Reset.Units.Player,
Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
- _json: '{"_name":"testobject","_id":"45e90651-1912-40ef-b4fc-6c27d00d0ef0","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
_references: []
--- !u!95 &8583102325603564116
Animator:
@@ -978,7 +1048,14 @@ MonoBehaviour:
TransitionDuration: 0.08350754
TriggerNameHash: -309998415
TransitionIndex: 0
m_Animator: {fileID: 6535719103590072454}
- IsCrossFadeExit: 0
Layer: 0
OriginatingState: -660779543
DestinationState: -50309357
TransitionDuration: 0.25
TriggerNameHash: -743040919
TransitionIndex: 0
m_Animator: {fileID: 8505492416078151957}
--- !u!114 &2832127593411522816
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@@ -1826,7 +1826,8 @@ PrefabInstance:
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"Combat
Information":{"_value":{},"_name":"Combat Information","_id":"a15396c3-5ba0-4789-b5c5-39a6cfea1943","$type":"NodeCanvas.Framework.Variable`1[[NodeCanvas.Framework.VariableSeperator,
ParadoxNotion, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"inGoHard":{"_propertyPath":"PlayerMeter.inGoHard","_name":"inGoHard","_id":"dc9f60c8-856e-4970-bf11-25745eff1201","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}}}'
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"pickupTarget":{"_propertyPath":"Reset.Units.Player.pickupTarget","_name":"pickupTarget","_id":"bf809a37-76c1-4dd7-8528-cc09527cb016","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _objectReferences.Array.size
@@ -1842,10 +1843,19 @@ PrefabInstance:
value: '{"_name":"modelAnimator","_id":"64fd28ff-2ca7-4b11-89b9-2c0cf8961bf8","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Animator,
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[11]._json
value: '{"_propertyPath":"Reset.Units.Player.pickupTarget","_name":"pickupTarget","_id":"bf809a37-76c1-4dd7-8528-cc09527cb016","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[8]._references.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6694215117007243537, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6755910944311034920, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 25.23057
@@ -1882,6 +1892,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 66.36815
objectReference: {fileID: 0}
- target: {fileID: 7010788291086685387, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7087274578062743959, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 83.97552
@@ -2078,6 +2092,10 @@ PrefabInstance:
propertyPath: data.rotationSpeed.defaultValue
value: 10
objectReference: {fileID: 0}
- target: {fileID: 8191935187182503649, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8195681124149962496, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -63.06196
@@ -2182,6 +2200,22 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: -61.47872
objectReference: {fileID: 0}
- target: {fileID: 8855283078872505435, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8855283078872505435, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8855283078872505435, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8855283078872505435, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8921845175749348414, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 45.77425
@@ -3558,12 +3592,17 @@ PrefabInstance:
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"Combat
Information":{"_value":{},"_name":"Combat Information","_id":"a15396c3-5ba0-4789-b5c5-39a6cfea1943","$type":"NodeCanvas.Framework.Variable`1[[NodeCanvas.Framework.VariableSeperator,
ParadoxNotion, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"inGoHard":{"_propertyPath":"PlayerMeter.inGoHard","_name":"inGoHard","_id":"dc9f60c8-856e-4970-bf11-25745eff1201","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}}}'
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"testobject":{"_name":"testobject","_id":"1ed67ab7-76d3-45fa-b36b-7e676e69dcea","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _objectReferences.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.size
value: 12
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[6]._json
value: '{"_propertyPath":"UnityEngine.CharacterController.isGrounded","_name":"isGrounded","_id":"5dbc6a46-39ce-4d74-87a2-ac8211a5a77f","_debugBoundValue":true,"$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
@@ -3574,6 +3613,11 @@ PrefabInstance:
value: '{"_name":"modelAnimator","_id":"64fd28ff-2ca7-4b11-89b9-2c0cf8961bf8","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Animator,
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[11]._json
value: '{"_name":"testobject","_id":"1ed67ab7-76d3-45fa-b36b-7e676e69dcea","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[8]._references.Array.size
value: 0
@@ -5288,6 +5332,50 @@ Mesh:
- serializedVersion: 1
m_IndexStart: 0
m_IndexCount: 0
--- !u!1 &1291419215
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1291419217}
- component: {fileID: 1291419216}
m_Layer: 0
m_Name: WidgetEventDispatcher
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1291419216
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1291419215}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 318dc804b7b04630a9ed534a2243e51f, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.Multiplayer.Widgets.Core::Unity.Multiplayer.Widgets.WidgetEventDispatcher
--- !u!4 &1291419217
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1291419215}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1379726749
GameObject:
m_ObjectHideFlags: 0
@@ -6368,12 +6456,17 @@ PrefabInstance:
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"Combat
Information":{"_value":{},"_name":"Combat Information","_id":"a15396c3-5ba0-4789-b5c5-39a6cfea1943","$type":"NodeCanvas.Framework.Variable`1[[NodeCanvas.Framework.VariableSeperator,
ParadoxNotion, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"},"inGoHard":{"_propertyPath":"PlayerMeter.inGoHard","_name":"inGoHard","_id":"dc9f60c8-856e-4970-bf11-25745eff1201","$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}}}'
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"testobject":{"_name":"testobject","_id":"de2c7183-a5c3-4036-b92c-4b952c7a7af0","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _objectReferences.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.size
value: 12
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[6]._json
value: '{"_propertyPath":"UnityEngine.CharacterController.isGrounded","_name":"isGrounded","_id":"5dbc6a46-39ce-4d74-87a2-ac8211a5a77f","_debugBoundValue":true,"$type":"NodeCanvas.Framework.Variable`1[[System.Boolean,
@@ -6384,6 +6477,11 @@ PrefabInstance:
value: '{"_name":"modelAnimator","_id":"64fd28ff-2ca7-4b11-89b9-2c0cf8961bf8","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.Animator,
UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[11]._json
value: '{"_name":"testobject","_id":"de2c7183-a5c3-4036-b92c-4b952c7a7af0","$type":"NodeCanvas.Framework.Variable`1[[UnityEngine.GameObject,
UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}'
objectReference: {fileID: 0}
- target: {fileID: 6546916578030478377, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
propertyPath: _serializedVariables.Array.data[8]._references.Array.size
value: 0
@@ -8530,3 +8628,4 @@ SceneRoots:
- {fileID: 1834179742}
- {fileID: 1113569334}
- {fileID: 4518178797721885223}
- {fileID: 1291419217}

View File

@@ -24,7 +24,7 @@ namespace Reset.Core {
//EndAction can be called from anywhere.
protected override void OnExecute(){
try {
agent.SetTrigger("trigger");
agent.SetTrigger(trigger.value);
} catch (Exception e) {
Debug.LogError($"Did not set Network Animator trigger <i>{trigger.name}</i> on <b>{(agent == null ? null : agent.name)}</b>: {e.Message}");
}

View File

@@ -27,30 +27,27 @@ namespace Reset.Units {
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
protected override void OnExecute(){
Unit targetUnit = target.value.GetComponent<Unit>();
try {
if (targetUnit != null) {
if (target.value.GetComponent<Unit>().UnitIsNetworked()) {
targetUnit.DoGraphEventRpc(eventToSend);
} else {
targetUnit.GetComponent<GraphOwner>().SendEvent("eventToSend");
}
}
} catch (Exception e) {
Debug.LogError($"Failed to send event {eventToSend} to {target}: {e.Message}");
}
EndAction(true);
}
//Called once per frame while the action is active.
protected override void OnUpdate(){
try {
if (target.value.GetComponent<Unit>().UnitIsNetworked()) {
ulong targetID = (target.value.GetComponent<NetworkObject>()).NetworkObjectId;
SendEventRpc(agent.RpcTarget.Single(targetID, RpcTargetUse.Temp));
} else {
target.value.GetComponent<GraphOwner>().SendEvent("eventToSend");
}
} catch (Exception e) {
Debug.LogError($"Failed to send event {eventToSend} to {target}: {e.Message}");
}
}
[Rpc(SendTo.SpecifiedInParams)]
void SendEventRpc(RpcParams rpcParams = default){
target.value.GetComponent<GraphOwner>().SendEvent("eventToSend");
Debug.Log("");
}
//Called when the task is disabled.

View File

@@ -6,3 +6,4 @@ public interface IInteractable{
public void CancelInteract();
public void OnObserverDetected(EnvironmentObserver observer);
}

View File

@@ -1,24 +1,28 @@
using System;
using System.Collections;
using Drawing;
using Reset;
using Reset.Core;
using Reset.Core.Tools;
using Reset.Units;
using UnityEngine;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using Unity.Netcode;
namespace Reset.Units{
public class Player : Unit, IKillable{
public class Player : Unit, IKillable, IInteractable{
[HideInInspector] public PlayerControls controls;
float IKillable.maxHealth{ get; set; }
float IKillable.currentHealth{ get; set; }
public float maxHealth{ get; set; }
public float currentHealth{ get; set; }
public NetworkVariable<bool> _isDowned;
public bool IsDowned => _isDowned.Value;
private float timeDowned;
public GameObject pickupTarget;
void Awake(){
controls = GetComponent<PlayerControls>();
maxHealth = 20f;
}
public void Attach(){
@@ -47,6 +51,14 @@ namespace Reset.Units{
public override void UnitUpdate(){
GetComponent<IKillable>().DrawHealthDebug();
if (IsDowned) {
timeDowned += 1f * Time.deltaTime;
}
if (timeDowned > 5f) {
Kill();
}
}
public void TakeDamage(DamageSource[] sources){
@@ -58,14 +70,107 @@ namespace Reset.Units{
public void TakeDamage(DamageSource source){
((IKillable)this).currentHealth -= source.damageDealt;
if (((IKillable)this).currentHealth <= 0) {
Kill();
if (UnitIsNetworked()) {
SetNewHealthRpc(currentHealth);
}
}
// TODO: Move somewhere not stupid so there's not an identical method in Enemy.cs
[Rpc(SendTo.Everyone)]
public void SetNewHealthRpc(float health){
currentHealth = health;
// NOTE: only here for testing. Move out of here into some "post damage" check method
if (((IKillable)this).currentHealth <= 0) {
// if (UnitIsNetworked()) {
Down();
// } else {
// Kill();
// }
}
}
public override void SetNewPosition(Vector3 position){
var contr = GetComponent<CharacterController>();
contr.enabled = false;
transform.position = position;
contr.enabled = true;
}
public void Down(){
Graph.SendEvent("Downed");
}
public void Kill(){
throw new NotImplementedException();
Graph.SendEvent("Killed");
}
public void Interact(){
// Check if the other player can be interacted with at all
if (pickupTarget&& pickupTarget.GetComponent<Player>().CanInteract()) {
// Tell the local player to start picking up the ally and switch states
Graph.SendEvent("Picking Up Ally");
// Tell the target player to start getting picked up.
pickupTarget.GetComponent<Player>().StartPickupRpc();
// Wait for the pickup timer to finish
StartCoroutine(PickupTimer());
}
}
[Rpc(SendTo.Owner)]
public void StartPickupRpc(){
// When picked up by another player, move into the pick up state
// TODO: Turn all these send events into a goddamn task maybe? State stuff should happen in the state machine. Concurrent stuff should happen in code
Graph.SendEvent("Pick Up Start");
}
IEnumerator PickupTimer(){
// Start a timer and wait for it to complete
float elapsed = 0f;
while (elapsed < 7f) {
elapsed += 1f * Time.deltaTime;
yield return null;
}
Graph.SendEvent("Pick Up Success");
}
public bool CanInteract(){
return IsDowned;
}
public void CancelInteract(){
Graph.SendEvent("Pick Up Failed");
}
public void OnObserverDetected(EnvironmentObserver observer){
// Try and get a Player component from the current hit object
// The rest of the logic will continue as expected so long as an
pickupTarget = observer.hit.collider.gameObject;
DrawInteractStatus();
}
void DrawInteractStatus(){
using (Draw.WithColor(Color.blue)) {
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, "Interactable",
Color.orchid);
}
}
void LateUpdate(){
// Clear the pickupTarget every frame
// NOTE: Will this work online?
pickupTarget = null;
}
}
}

View File

@@ -157,7 +157,8 @@ public class EnvironmentObserver{
}
if (hit.transform != null) {
if (hit.transform.GetComponent<IInteractable>() != null) {
IInteractable interactable = hit.transform.GetComponent<IInteractable>();
if (interactable != null && interactable.CanInteract()) {
hit.transform.GetComponent<IInteractable>().OnObserverDetected(this);
}
return true;

View File

@@ -2,17 +2,55 @@
using System.Collections;
using System.Threading.Tasks;
using Drawing;
using NodeCanvas.BehaviourTrees;
using NodeCanvas.Framework;
using NodeCanvas.StateMachines;
using Reset;
using Reset.Units;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
namespace Reset.Units{
public class Unit : NetworkBehaviour{
public class Unit : NetworkBehaviour, INetworkSerializeByMemcpy{
public string state;
public NetworkVariable<FixedString64Bytes> testSTate;
private FSMOwner fsm;
private UnitMovementHandler _movement;
internal UnitMovementHandler Movement{
get{
if (!_movement) {
_movement = GetComponent<UnitMovementHandler>();
}
return _movement;
}
}
private GraphOwner _graph;
internal GraphOwner Graph{
get{
if (!_graph) {
_graph = GetComponent<GraphOwner>();
}
return _graph;
}
}
private void Awake(){
fsm = GetComponent<FSMOwner>();
}
public virtual void Start(){
UnitStart();
}
public virtual void UnitStart(){ }
public bool UnitIsNetworked(){
@@ -37,9 +75,16 @@ namespace Reset.Units{
UnitUpdate();
}
public virtual void SetNewPosition(Vector3 position){ }
public virtual void UnitUpdate(){ }
void UpdateGizmos(){
DrawOnlineStatusGizmo();
DrawStateGizmo();
}
private void DrawOnlineStatusGizmo(){
string onlineStatus = "Not Online";
Color onlineColor = Color.gray;
@@ -56,9 +101,43 @@ namespace Reset.Units{
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
}
private void DrawStateGizmo(){
if (fsm && UnitIsLocal()) {
testSTate.Value = fsm.currentRootStateName;
// if (UnitIsNetworked()) {
// // state = fsm.currentRootStateName;
// SendStateInformationRpc(fsm.currentRootStateName);
// } else {
// state = fsm.currentRootStateName;
// }
} else {
fsm = GetComponent<FSMOwner>();
}
// state = state.ToString().ToUpper();
try {
Draw.ingame.Label2D(transform.position + Vector3.up * 2.7f, testSTate.Value.ToString(), Color.red);
} catch (Exception e) {
Debug.LogError(e.Message);
}
}
[Rpc(SendTo.Everyone)]
public void SendStateInformationRpc(string newState){
Debug.Log($"newstate! {newState}");
state = newState;
}
[Rpc(SendTo.Owner)]
public void TakeOwnershipRpc(ulong clientID){
GetComponent<NetworkObject>().ChangeOwnership(clientID);
}
[Rpc(SendTo.Owner)]
public void DoGraphEventRpc(string eventToSend){
Debug.Log(eventToSend);
GetComponent<FSMOwner>().SendEvent(eventToSend); }
}
}