This commit is contained in:
2026-07-09 21:33:33 +02:00
commit 84a2a365f3
2364 changed files with 950134 additions and 0 deletions
@@ -0,0 +1,195 @@
using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Player.Input;
namespace VOID.Generic.Player
{
/// <summary>
/// Manager with full control of camera with movement by player.
/// </summary>
[DefaultExecutionOrder(-1)]
public class CameraManager : MonoBehaviour
{
public static CameraManager current {get; private set;}
// Camera Movement Settings
[Title("Camera Horizontal Movement")]
[SerializeField, MinValue(1f), MaxValue(10f), SuffixLabel("m/s")]
private float moveSpeed = 5f;
[SerializeField, MinValue(1f), MaxValue(5f)]
private float moveSpeedFastMultiplier = 2.5f;
// Camera's target elevating
[Title("Camera Vertical Movement")]
[SerializeField, MinValue(1f), MaxValue(20f), SuffixLabel("m/s")]
private float elevateSpeed = 1f;
// Camera Rotate and Tilt Settings
[Title("Camera Rotate and Tilt")]
[SerializeField, MinValue(0.01f), MaxValue(1f)]
private float rotateSensitivity = 0.1f;
[SerializeField, MinValue(0.01f), MaxValue(1f)]
private float tiltSensitivity = 0.06f;
[SerializeField, MinMaxSlider(10f, 90f, true)]
private Vector2 tiltLimit = new(20f, 85f);
// Camera Zoom Settings
[Title("Camera Zoom")]
[SerializeField, MinValue(0.05f), MaxValue(1f)]
private float zoomSensitivity = 0.3f;
[SerializeField, MinMaxSlider(1f, 30f, true)]
private Vector2 zoomLimit = new(2f, 15f);
[SerializeField]
private float zoomCurrent = 8f;
// Camera Offset
[Title("Camera Offset")]
[SerializeField, MinValue(0f), MaxValue(3f)]
private float targetVerticalOffset = 1.0f;
[SerializeField]
private Vector3 cameraOffset = new(0f, 0f, -1f);
// Camera and Target
private Camera _camera;
private GameObject _target;
// Stick properties
[Title("Sticking to transform")]
public Transform stickTo;
// Aditional Components
private CameraInputManager _cameraInputManager;
private void Awake()
{
current = this;
}
private void Start()
{
_cameraInputManager = CameraInputManager.current;
_camera = Camera.main;
_target = CameraTarget.InstantiateNew().gameObject;
}
private void FixedUpdate()
{
MoveHorizontally();
MoveVertically();
RotateAndTilt();
Zoom();
Offset();
CameraLookAtTarget();
}
/// <summary>
/// Moves camera's target to given position.
/// </summary>
public void MoveTo(Vector3 position)
{
_target.transform.position = position;
stickTo = null;
}
/// <summary>
/// Moving camera's target horizontally.
/// </summary>
private void MoveHorizontally()
{
// No camera movement from player, but it can be sticked to something
if (!_cameraInputManager.isMoving) {
if (stickTo) _target.transform.position = stickTo.position + new Vector3(0f, 1.5f, 0f);
return;
}
// Player moved camera - unstick camera
stickTo = null;
// Calculate camera's target next relative position
var moveVector = _cameraInputManager.movementDelta * (moveSpeed * Time.deltaTime);
if (_cameraInputManager.isMovingFaster) moveVector *= moveSpeedFastMultiplier;
var position = _target.transform.TransformDirection(moveVector.x, 0, moveVector.y);
_target.transform.position += position;
}
/// <summary>
/// Moving camera's target vertically.
/// </summary>
private void MoveVertically()
{
// IMPORTANT - target's pos already include offset!
var targetPos = _target.transform.position;
// Find point where camera's target can stick to
Physics.Raycast(
new Ray(targetPos + Vector3.up*50f, Vector3.down),
out var rayCastHit,
100f,
LayerManager.Static);
// Nothing - seems like camera floating and there is nothing above or below
if (!rayCastHit.collider) return;
// IMPORTANT - target include offset by default, but not raycast - we need add offset to raycast point!
var rayCastPos = rayCastHit.point + new Vector3(0, targetVerticalOffset, 0);
// If distance is positive we go UP, otherwise we go DOWN
var distance = rayCastPos.y - targetPos.y;
// Move camera's target towards new position, if really close then move remaining distance to prevent jiggling
var speed = Mathf.Sign(distance) * Mathf.Min(Mathf.Abs(distance), elevateSpeed * Time.fixedDeltaTime);
_target.transform.position += new Vector3(0f, speed, 0f);
}
/// <summary>
/// Rotating and tilting camera.<br/>
/// Rotating camera's target.
/// </summary>
private void RotateAndTilt()
{
if (_cameraInputManager.isRotatingAndTilting == false) return;
var delta = _cameraInputManager.rotateAndTiltDelta;
var tiltDelta = delta.y * tiltSensitivity * -1;
var rotateDelta = delta.x * rotateSensitivity;
var previousEuler = _camera.transform.rotation.eulerAngles;
var nextEuler = previousEuler + new Vector3(tiltDelta, rotateDelta, 0);
if (nextEuler.x < tiltLimit.x) nextEuler.x = tiltLimit.x;
if (nextEuler.x > tiltLimit.y) nextEuler.x = tiltLimit.y;
_camera.transform.rotation = Quaternion.Euler(nextEuler);
_target.transform.rotation = Quaternion.Euler(0f, nextEuler.y, 0f);
}
/// <summary>
/// Updating camera's zoom.
/// </summary>
private void Zoom()
{
if (_cameraInputManager.isZooming == false) return;
zoomCurrent -= _cameraInputManager.zoomDelta * zoomSensitivity;
if (zoomCurrent > zoomLimit.y) zoomCurrent = zoomLimit.y;
if (zoomCurrent < zoomLimit.x) zoomCurrent = zoomLimit.x;
}
/// <summary>
/// Updating camera's offset from target.
/// </summary>
private void Offset()
{
var offset = _camera.transform.TransformDirection(Vector3.back * zoomCurrent + cameraOffset);
_camera.transform.position = _target.transform.position + offset;
}
private void CameraLookAtTarget()
{
_camera.transform.LookAt(_target.transform);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 31b2c82b03e422e42a9070e8fcf542c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using Sirenix.Utilities;
using UnityEngine;
using VOID.Generic.Triggers;
namespace VOID.Generic.Player
{
[DefaultExecutionOrder(-1)]
public class CameraTarget : MonoBehaviour
{
public static CameraTarget InstantiateNew()
{
var gameObject = new GameObject("Camera Target");
gameObject.layer = LayerManager.CameraIndex;
gameObject.transform.parent = CameraManager.current.transform;
// Collision
var sphereCollider = gameObject.AddComponent<SphereCollider>();
sphereCollider.isTrigger = true;
// RigidBody
var rigidBody = gameObject.AddComponent<Rigidbody>();
rigidBody.useGravity = false;
rigidBody.isKinematic = true;
rigidBody.constraints = RigidbodyConstraints.FreezeAll;
return gameObject.AddComponent<CameraTarget>();
}
private void OnTriggerEnter(Collider other)
{
other.GetComponents<ICameraTrigger>().ForEach(trigger => trigger.OnCameraEnter());
}
private void OnTriggerExit(Collider other)
{
other.GetComponents<ICameraTrigger>().ForEach(trigger => trigger.OnCameraExit());
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ddde850edd5045c7abe55e1099cae195
timeCreated: 1731682012
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4586a20b4abf4504a2ec8bfb4ad2d7fe
timeCreated: 1698607015
@@ -0,0 +1,34 @@
using System;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.CursorOperation
{
public abstract class AbstractCursorOperation
{
/// <summary>
/// <see cref="Type"/> for which this operation will work.
/// </summary>
public abstract Type ForType();
/// <summary>
/// Returns TRUE if this operation can be executed.
/// </summary>
/// <param name="select">Complex information what was selected for this operation</param>
public abstract bool Check(SelectUtilResult select);
/// <summary>
/// Instantly executes default logic. Usually, by ordering currently active unit to do something.<br/>
/// <b>On Scene:</b> single tap, no alternate available (for now)<br/>
/// <b>On UI:</b> double tap, single tap is alternate usage<br/>
/// </summary>
/// <param name="select">Complex information what was selected for this operation</param>
/// <param name="isAlternate">If operation should execute alternate logic</param>
public abstract void DoDefault(SelectUtilResult select, bool isAlternate);
/// <summary>
/// Open context menu with all available action to choose for selected target.
/// </summary>
/// <param name="select">Complex information what was selected for this operation</param>
public abstract void DoContext(SelectUtilResult select);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 09d69b0d1ba94919b6ddac0633be5570
timeCreated: 1698607084
@@ -0,0 +1,44 @@
using System;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
using VOID.ScriptableObjects.Abilities;
namespace VOID.Generic.Player.CursorOperation
{
public class OnAbilityCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(BasicAbility);
public override bool Check(SelectUtilResult select)
{
return select.selectAbility;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var selectAbility = select.selectAbility;
var activeUnit = PlayerController.current.activeUnit;
activeUnit.OrderStop();
activeUnit.Order(new CastingAction(activeUnit, selectAbility));
}
public override void DoContext(SelectUtilResult select)
{
var activeUnit = PlayerController.current.activeUnit;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
ContextMenuUI.current.AddOption("Use Ability", () =>
{
activeUnit.Order(new CastingAction(activeUnit, select.selectAbility));
});
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 11b181e8bf9a4089ba6d589728acb167
timeCreated: 1698690680
@@ -0,0 +1,103 @@
using System;
using VOID.Generic.Objects.Container;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.CursorOperation
{
public class OnContainerCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(ContainerObject);
public override bool Check(SelectUtilResult select)
{
return select.selectObject is ContainerObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var container = (ContainerObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
activeUnit.OrderStop();
if (activeUnit.unitData.canAttack && PlayerInputManager.current.isForceAttack)
{
// Player forced attack action
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
}
else
{
// Default operation is OPEN (+ move closer if needed)
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new OpenContainerAction(activeUnit, container));
}
}
public override void DoContext(SelectUtilResult select)
{
var container = (ContainerObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
var carrier = container.itemState.carriedBy;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
ContextMenuUI.current.AddOption("Open", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new OpenContainerAction(activeUnit, container));
});
if (!select.onUI)
{
if (activeUnit.unitData.canMove)
{
ContextMenuUI.current.AddOption("Move", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position));
});
}
if (activeUnit.unitData.canAttack)
{
ContextMenuUI.current.AddOption("Attack", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
});
}
}
if (activeUnit.unitData.canTake && container.itemData.canBePicked && container.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
ContextMenuUI.current.AddOption("Take", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, container));
});
}
if (carrier == activeUnit)
{
ContextMenuUI.current.AddOption("Drop", () =>
{
activeUnit.Order(new DropAction(activeUnit, container));
});
}
if (activeUnit.unitData.canInspect && container.basicData.canBeInspected)
{
ContextMenuUI.current.AddOption("Inspect", () =>
{
MoveAction moveAction = new MoveAction(activeUnit, select.position, activeUnit.unitData.inspectRange);
moveAction.OnEnd += () => activeUnit.OrderInstantly(new InspectAction(activeUnit, container));
activeUnit.Order(moveAction);
});
}
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fba87a0905344721baf1a917b4171f56
timeCreated: 1698610850
@@ -0,0 +1,86 @@
using System;
using VOID.Generic.Objects.Door;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.CursorOperation
{
public class OnDoorCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(DoorObject);
public override bool Check(SelectUtilResult select)
{
return select.selectObject is DoorObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var door = (DoorObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
activeUnit.OrderStop();
if (activeUnit.unitData.canAttack && PlayerInputManager.current.isForceAttack)
{
// Player forced attack action
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
}
else if (activeUnit.unitData.canUse)
{
// Default operation is USE (+ move closer if needed)
activeUnit.Order(new MoveAction(activeUnit, door, activeUnit.unitData.takeRange));
activeUnit.Order(new UseAction(activeUnit, door));
}
}
public override void DoContext(SelectUtilResult select)
{
var door = (DoorObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
if (activeUnit.unitData.canMove)
{
ContextMenuUI.current.AddOption("Move", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position));
});
}
if (activeUnit.unitData.canAttack)
{
ContextMenuUI.current.AddOption("Attack", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
});
}
if (activeUnit.unitData.canUse)
{
ContextMenuUI.current.AddOption(door.doorState.isOpen ? "Close" : "Open", () =>
{
activeUnit.Order(new MoveAction(activeUnit, door, activeUnit.unitData.useRange));
activeUnit.Order(new UseAction(activeUnit, door));
});
}
if (activeUnit.unitData.canInspect && door.basicData.canBeInspected)
{
ContextMenuUI.current.AddOption("Inspect", () =>
{
MoveAction moveAction = new MoveAction(activeUnit, door, activeUnit.unitData.inspectRange);
moveAction.OnEnd += () => activeUnit.OrderInstantly(new InspectAction(activeUnit, door));
activeUnit.Order(moveAction);
});
}
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d1c09919cc7a4d7ea117cd07aa0e1db0
timeCreated: 1707863006
@@ -0,0 +1,100 @@
using System;
using System.ComponentModel;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.CursorOperation
{
public class OnItemCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(ItemObject);
public override bool Check(SelectUtilResult select)
{
return select.selectObject is ItemObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var item = (ItemObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var carrier = item.itemState.carriedBy;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
activeUnit.OrderStop();
if (activeUnit.unitData.canAttack && PlayerInputManager.current.isForceAttack)
{
// Player forced attack action
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
}
else if (activeUnit.unitData.canTake && item.itemData.canBePicked && item.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
// Default operation is TAKE (+ move closer if needed)
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, item));
}
}
public override void DoContext(SelectUtilResult select)
{
var item = (ItemObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var carrier = item.itemState.carriedBy;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
if (!select.onUI)
{
if (activeUnit.unitData.canMove)
{
ContextMenuUI.current.AddOption("Move", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position));
});
}
if (activeUnit.unitData.canAttack)
{
ContextMenuUI.current.AddOption("Attack", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
});
}
}
if (activeUnit.unitData.canTake && item.itemData.canBePicked && item.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
ContextMenuUI.current.AddOption("Take", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, item));
});
}
if (carrier == activeUnit)
{
ContextMenuUI.current.AddOption("Drop", () =>
{
activeUnit.Order(new DropAction(activeUnit, item));
});
}
if (activeUnit.unitData.canInspect && item.basicData.canBeInspected)
{
ContextMenuUI.current.AddOption("Inspect", () =>
{
MoveAction moveAction = new MoveAction(activeUnit, select.position, activeUnit.unitData.inspectRange);
moveAction.OnEnd += () => activeUnit.OrderInstantly(new InspectAction(activeUnit, item));
activeUnit.Order(moveAction);
});
}
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b5a8f39823274658831f598ba0e710aa
timeCreated: 1698610993
@@ -0,0 +1,42 @@
using System;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.CursorOperation
{
public class OnSceneCursorOperation : AbstractCursorOperation
{
public override Type ForType() => null;
public override bool Check(SelectUtilResult select)
{
return !select.onUI && !select.selectObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
if (activeUnit.unitData.canAttack && PlayerInputManager.current.isForceAttack)
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
return;
}
activeUnit.OrderStop();
activeUnit.Order(new MoveAction(activeUnit, select.position));
}
public override void DoContext(SelectUtilResult select)
{
ContextMenuUI.current.Close();
PlayerController.current.activeUnit.OrderStop();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 450710b09445433cab3979fd013bc333
timeCreated: 1698608270
@@ -0,0 +1,130 @@
using System;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
using VOID.Generic.Util;
namespace VOID.Generic.Player.CursorOperation
{
public class OnUnitCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(UnitObject);
public override bool Check(SelectUtilResult select)
{
return select.selectObject is UnitObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
var onPartyUI = select.partyUI != null;
var onPortraitUI = select.unitPortraitUI != null;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
var targetUnit = (UnitObject)select.selectObject;
var attitude = activeUnit.unitAttitude.GetAttitudeWith(targetUnit);
if (isAlternate && onPortraitUI && onPartyUI && targetUnit == PlayerController.current.activeUnit)
{
CameraManager.current.MoveTo(targetUnit.transform.position);
}
else if (isAlternate && onPortraitUI && onPartyUI && targetUnit == PlayerController.current.mainUnit)
{
PlayerController.current.SetMainUnitActive();
}
else if (isAlternate && onPortraitUI && onPartyUI && targetUnit == PlayerController.current.subUnit)
{
PlayerController.current.SetSubUnitActive();
}
else if (isAlternate && onPortraitUI)
{
CameraManager.current.MoveTo(targetUnit.transform.position);
}
else if (!isAlternate && onPortraitUI)
{
CameraManager.current.stickTo = targetUnit.transform;
}
// No action to order when clicking portraits
if (onPortraitUI) return;
activeUnit.OrderStop();
if (targetUnit.basicState.isDead)
{
// Open - when other unit is dead, we open him like container
activeUnit.Order(new MoveAction(activeUnit, targetUnit, activeUnit.unitData.takeRange));
activeUnit.Order(new OpenOtherUnitAction(activeUnit, targetUnit));
}
else if (activeUnit.unitData.canAttack && (PlayerInputManager.current.isForceAttack || attitude <= AttitudeType.Cautious))
{
// Attack - when this unit can Attack AND forced attack OR target unit is hostile/cautious
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
}
else
{
// Talk - when this unit can Talk AND target unit is neutral/friendly
activeUnit.Order(new MoveAction(activeUnit, targetUnit, activeUnit.unitData.talkRange));
if (activeUnit.unitData.canTalk && targetUnit.unitData.canBeTalked) activeUnit.Order(new TalkAction(activeUnit, targetUnit));
}
}
public override void DoContext(SelectUtilResult select)
{
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
var targetUnit = (UnitObject)select.selectObject;
var attitude = activeUnit.unitAttitude.GetAttitudeWith(targetUnit);
if (targetUnit == activeUnit && select.onUI) return;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
if (activeUnit.unitData.canMove)
{
ContextMenuUI.current.AddOption("Move",
() => activeUnit.Order(new MoveAction(activeUnit, select.position)));
}
if (targetUnit.basicState.isDead)
{
ContextMenuUI.current.AddOption("Loot", () =>
{
activeUnit.Order(new MoveAction(activeUnit, targetUnit, activeUnit.unitData.takeRange));
activeUnit.Order(new OpenOtherUnitAction(activeUnit, targetUnit));
});
}
if (activeUnit.unitData.canAttack)
{
ContextMenuUI.current.AddOption("Attack", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
});
}
if (attitude >= AttitudeType.Neutral && activeUnit.unitData.canTalk && targetUnit.unitData.canBeTalked)
{
ContextMenuUI.current.AddOption("Talk", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TalkAction(activeUnit, targetUnit));
});
}
if (activeUnit.unitData.canInspect && targetUnit.basicData.canBeInspected)
{
ContextMenuUI.current.AddOption("Inspect", () =>
{
MoveAction moveAction = new MoveAction(activeUnit, select.position, activeUnit.unitData.inspectRange);
moveAction.OnEnd += () => activeUnit.OrderInstantly(new InspectAction(activeUnit, targetUnit));
activeUnit.Order(moveAction);
});
}
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6dd2501221e74d348fbfe05dd5602955
timeCreated: 1698610483
@@ -0,0 +1,114 @@
using System;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Usable;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.CursorOperation
{
public class OnUsableCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(UsableObject);
public override bool Check(SelectUtilResult select)
{
return select.selectObject is UsableObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var usable = (UsableObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var carrier = usable.itemState.carriedBy;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
activeUnit.OrderStop();
if (activeUnit.unitData.canAttack && PlayerInputManager.current.isForceAttack)
{
// Player forced attack action
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
}
else if (activeUnit.unitData.canTake && usable.itemData.canBePicked && usable.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
// Default operation is TAKE (+ move closer if needed)
activeUnit.Order(new MoveAction(activeUnit, usable.transform.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, usable));
}
else if(activeUnit.unitData.canUse)
{
// If can't be taken then... USE (+ move closer if needed)
activeUnit.Order(new MoveAction(activeUnit, usable.transform.position, activeUnit.unitData.useRange));
activeUnit.Order(new UseAction(activeUnit, usable));
}
}
public override void DoContext(SelectUtilResult select)
{
var usable = (UsableObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
var carrier = usable.itemState.carriedBy;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
if (activeUnit.unitData.canUse)
{
ContextMenuUI.current.AddOption("Use", () =>
{
activeUnit.Order(new MoveAction(activeUnit, usable.transform.position, activeUnit.unitData.takeRange));
activeUnit.Order(new UseAction(activeUnit, usable));
});
}
if (!select.onUI)
{
if (activeUnit.unitData.canMove)
{
ContextMenuUI.current.AddOption("Move", () =>
{
activeUnit.Order(new MoveAction(activeUnit, usable.transform.position));
});
}
if (activeUnit.unitData.canAttack)
{
ContextMenuUI.current.AddOption("Attack", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
});
}
}
if (activeUnit.unitData.canTake && usable.itemData.canBePicked && usable.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
ContextMenuUI.current.AddOption("Take", () =>
{
activeUnit.Order(new MoveAction(activeUnit, usable.transform.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, usable));
});
}
if (carrier == activeUnit)
{
ContextMenuUI.current.AddOption("Drop", () =>
{
activeUnit.Order(new DropAction(activeUnit, usable));
});
}
if (activeUnit.unitData.canInspect && usable.basicData.canBeInspected)
{
ContextMenuUI.current.AddOption("Inspect", () =>
{
MoveAction moveAction = new MoveAction(activeUnit, usable.transform.position, activeUnit.unitData.inspectRange);
moveAction.OnEnd += () => activeUnit.OrderInstantly(new InspectAction(activeUnit, usable));
activeUnit.Order(moveAction);
});
}
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b9236a03e16a438aa090d6c823601dd1
timeCreated: 1698613067
@@ -0,0 +1,133 @@
using System;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.CursorOperation
{
public class OnWearableCursorOperation : AbstractCursorOperation
{
public override Type ForType() => typeof(WearableObject);
public override bool Check(SelectUtilResult select)
{
return select.selectObject is WearableObject;
}
public override void DoDefault(SelectUtilResult select, bool isAlternate)
{
if (isAlternate) return;
var wearable = (WearableObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var carrier = wearable.itemState.carriedBy;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
activeUnit.OrderStop();
if (activeUnit.unitData.canAttack && PlayerInputManager.current.isForceAttack)
{
// Player forced attack action
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
}
else if (activeUnit.unitData.canTake && wearable.itemData.canBePicked && wearable.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
// Default operaion is Take
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, wearable));
}
else if (wearable.wearableState.wearerUnit == activeUnit)
{
// Try UNEQUIP (if currently wearing)
activeUnit.Order(new UnEquipAction(activeUnit, wearable));
}
else if (wearable.itemState.carriedBy == activeUnit)
{
// Try EQUIP (if in backpack)
activeUnit.Order(new EquipAction(activeUnit, wearable));
}
}
public override void DoContext(SelectUtilResult select)
{
var wearable = (WearableObject)select.selectObject;
var activeUnit = PlayerController.current.activeUnit;
var attackAbility = activeUnit.unitAbilityBook.attackAbility;
var carrier = wearable.itemState.carriedBy;
var wearer = wearable.wearableState.wearerUnit;
ContextMenuUI.current.Prepare();
ContextMenuUI.current.AddBeforeClick(() => activeUnit.OrderStop());
if (!select.onUI)
{
if (activeUnit.unitData.canMove)
{
ContextMenuUI.current.AddOption("Move", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position));
});
}
if (activeUnit.unitData.canAttack)
{
ContextMenuUI.current.AddOption("Attack", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, attackAbility.range));
activeUnit.Order(new AbilityAction(activeUnit, attackAbility, select.position));
});
}
}
if ((carrier == null) && wearer == null && activeUnit.unitData.canTake && wearable.itemData.canBePicked && wearable.itemData.canBeMoved)
{
ContextMenuUI.current.AddOption("Equip", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, wearable));
activeUnit.Order(new EquipAction(activeUnit, wearable));
});
}
if ((carrier == activeUnit) && wearer == null)
{
ContextMenuUI.current.AddOption("Equip", () =>
{
activeUnit.Order(new EquipAction(activeUnit, wearable));
});
}
if (carrier == activeUnit && wearer == activeUnit)
{
ContextMenuUI.current.AddOption("UnEquip", () =>
{
activeUnit.Order(new UnEquipAction(activeUnit, wearable));
});
}
if (activeUnit.unitData.canTake && wearable.itemData.canBePicked && wearable.itemData.canBeMoved && (carrier == null || carrier.basicState.isDead))
{
ContextMenuUI.current.AddOption("Take", () =>
{
activeUnit.Order(new MoveAction(activeUnit, select.position, activeUnit.unitData.takeRange));
activeUnit.Order(new TakeAction(activeUnit, wearable));
});
}
if (carrier == activeUnit)
{
ContextMenuUI.current.AddOption("Drop", () =>
{
activeUnit.Order(new DropAction(activeUnit, wearable));
});
}
if (activeUnit.unitData.canInspect && wearable.basicData.canBeInspected)
{
ContextMenuUI.current.AddOption("Inspect", () =>
{
MoveAction moveAction = new MoveAction(activeUnit, select.position, activeUnit.unitData.inspectRange);
moveAction.OnEnd += () => activeUnit.OrderInstantly(new InspectAction(activeUnit, wearable));
activeUnit.Order(moveAction);
});
}
ContextMenuUI.current.Open();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e42674a58344cadbef2fad57aa3de17
timeCreated: 1698611491
@@ -0,0 +1,223 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using VOID.Generic.Objects.Item;
using VOID.Generic.Player.DraggingOperation;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
using VOID.Generic.Util;
using VOID.ScriptableObjects.Abilities;
namespace VOID.Generic.Player
{
[DefaultExecutionOrder(-1)]
public class DraggingManager : MonoBehaviour
{
public static DraggingManager current {get; private set;}
// References
private PlayerController _playerController;
private PlayerInputManager _playerInputManager;
private GameUI _gameUI;
private DraggingUI _draggingUI;
// Configuration
[SerializeField] private float startDraggingAfter = 0.2f;
// Private properties
private List<AbstractDraggingOperation> _draggingOperations;
private SelectUtilResult _sourceSelect;
private SelectUtilResult _targetSelect;
private bool _isDragging;
private bool _isPreparing;
// Submodule that visualize player's dragging
private DraggingVisualizer _draggingVisualizer;
// Transform from those GameObjects used as start and end for trajectory
private GameObject _draggingFrom;
private GameObject _draggingTo;
private void Awake()
{
current = this;
var thisTransform = transform;
_draggingFrom = new GameObject("Dragging From");
_draggingFrom.transform.parent = thisTransform;
_draggingTo = new GameObject("Dragging To");
_draggingTo.transform.parent = thisTransform;
_draggingOperations = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(AbstractDraggingOperation)) && type.IsClass)
.Select(Activator.CreateInstance)
.Cast<AbstractDraggingOperation>()
.ToList();
}
private void Start()
{
_playerInputManager = PlayerInputManager.current;
_playerInputManager.OnDraggingPrepare += PrepareDragging;
_playerInputManager.OnDraggingStart += StartDragging;
_playerInputManager.OnDraggingEnd += EndDragging;
_playerController = PlayerController.current;
_gameUI = GameUI.current;
_draggingUI = DraggingUI.current;
}
private void FixedUpdate()
{
Dragging();
}
/// <summary>
/// Checks that the operation can be performed and prepares the data for use
/// </summary>
private void PrepareDragging()
{
if (_isPreparing || _isDragging) Clean();
var sourceSelect = SelectUtil.Select();
// Dragging only when ability or item selected (and can be dragged)
if (!sourceSelect.selectObject && !sourceSelect.selectAbility) return;
if (sourceSelect.selectObject is not null and not ItemObject) return;
var selectItem = (ItemObject)sourceSelect.selectObject;
if (selectItem && !selectItem.itemData.canBeMoved) return;
_draggingFrom.transform.position = sourceSelect.position;
_draggingTo.transform.position = sourceSelect.position;
_sourceSelect = sourceSelect;
_isPreparing = true;
}
/// <summary>
/// Initiate draging visualisation
/// Requied: PrepapreDragging to be done before
/// </summary>
private void StartDragging()
{
if(!_isPreparing) return;
_isDragging = true;
if(_sourceSelect.selectObject is ItemObject) StartDraggingItem((ItemObject)_sourceSelect.selectObject);
else if(_sourceSelect.selectAbility) StartDraggingAbility(_sourceSelect.selectAbility);
}
private void StartDraggingItem(ItemObject item)
{
// Prepare for Scene dragging
_draggingVisualizer = DraggingVisualizer.Create(_draggingFrom.transform, _draggingTo.transform, item);
// Prepare for UI dragging
_draggingUI.Set(item);
}
private void StartDraggingAbility(BasicAbility ability)
{
_draggingUI.Set(ability);
_draggingUI.Show();
}
private void Dragging()
{
if (!_isDragging) return;
if (_sourceSelect.selectObject && !_gameUI.isCursorOverUI) DraggingItemOnScene();
else if (_sourceSelect.selectObject && _gameUI.isCursorOverUI) DraggingItemOnUI();
else if (_sourceSelect.selectAbility) DraggingAbility();
}
private void DraggingItemOnScene()
{
_draggingUI.Hide();
var hit = SelectUtil.SelectHit();
_draggingTo.transform.position = hit.point;
// Dragging only onto STATIC objects (like floor)
if (hit.collider.gameObject.layer is not LayerManager.StaticIndex)
{
_draggingVisualizer.Hide();
return;
}
var isInRange = RangeUtil.IsInRange(
_draggingFrom.transform.position,
_draggingTo.transform.position,
_playerController.activeUnit.unitData.takeRange*2,
false
);
// Dragging only when in player's unit range (2 * take range)
if (!isInRange)
{
_draggingVisualizer.Hide();
return;
}
_draggingVisualizer.Show();
}
private void DraggingItemOnUI()
{
_draggingUI.Show();
_draggingVisualizer.Hide();
}
private void DraggingAbility()
{
}
/// <summary>
/// This function completes the transfer process. It contains the main logic responsible for moving an object from one place to another
/// Required: StartDragging to be done before
/// </summary>
private void EndDragging()
{
if (!_isDragging)
{
Clean();
return;
}
_targetSelect = SelectUtil.Select();
if (_gameUI.isCursorOverUI && _targetSelect.slotUI?.slotType == null)
{
Debug.LogWarning("Dragged into invalid place over UI");
Clean();
return;
}
var operation = _draggingOperations.FirstOrDefault(op => op.Check(_sourceSelect, _targetSelect));
if (operation != null)
{
operation.Perform(_playerController.activeUnit, _sourceSelect, _targetSelect);
Clean();
return;
}
Debug.LogWarning("Dragging between unsupported places: " +
$"'{_sourceSelect.slotUI?.slotType}' -> '{_targetSelect.slotUI?.slotType}'");
Clean();
}
private void Clean()
{
if (_draggingVisualizer)
{
Destroy(_draggingVisualizer.gameObject);
_draggingVisualizer = null;
}
_isDragging = false;
_isPreparing = false;
_sourceSelect = null;
_targetSelect = null;
_draggingUI.Hide();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 42dea46a1a334842b66e86709530231a
timeCreated: 1690015713
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c5a5a8e341fd43f0b3f047a1bd04048a
timeCreated: 1698769829
@@ -0,0 +1,20 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class AbilityBookToActionBarDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.AbilityBookSlot
&& targetSelect.slotUI?.slotType == SlotType.ActionBarSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
unit.unitActionBar.Set(targetSelect.slotUI.slotIndex, sourceSelect.selectAbility);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6f4635567dc04393a64a263e88e6e7f3
timeCreated: 1698786458
@@ -0,0 +1,11 @@
using VOID.Generic.Objects.Unit;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public abstract class AbstractDraggingOperation
{
public abstract bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect);
public abstract void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d2de581ca754d01b320bd5de933251a
timeCreated: 1698770059
@@ -0,0 +1,25 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Usable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class ActionBarToActionBarDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ActionBarSlot
&& targetSelect.slotUI?.slotType == SlotType.ActionBarSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
unit.unitActionBar.UnSet(sourceSelect.slotUI.slotIndex);
if (sourceSelect.selectAbility)
unit.unitActionBar.Set(targetSelect.slotUI.slotIndex, sourceSelect.selectAbility);
if (sourceSelect.selectObject && sourceSelect.selectObject is UsableObject usable)
unit.unitActionBar.Set(targetSelect.slotUI.slotIndex, usable);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ddf93bae19b34fe08aeeedc7006276cb
timeCreated: 1698786284
@@ -0,0 +1,20 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class ActionBarToSceneDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ActionBarSlot
&& targetSelect.slotUI?.slotType == null;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
sourceSelect.slotUI.Clear();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f58f5af0bc224a32ac91a73d75df2008
timeCreated: 1698786224
@@ -0,0 +1,22 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Usable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class BackpackToActionBarDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.BackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.ActionBarSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not UsableObject usable) return;
unit.unitActionBar.Set(targetSelect.slotUI.slotIndex, usable);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 64274bb465a54118bdb30fe1ecab7184
timeCreated: 1698784366
@@ -0,0 +1,32 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class BackpackToBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.BackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.BackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
var itemFrom = sourceSelect.slotUI.item;
var itemTo = targetSelect.slotUI.item;
if (itemFrom.CanStackWith(itemTo))
{
itemFrom.StackWith(itemTo);
return;
}
unit.unitBackpack.Swap(
sourceSelect.slotUI.slotIndex,
targetSelect.slotUI.slotIndex
);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b9ca5a17d69447c3af5b238b960de390
timeCreated: 1698784246
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class BackpackToContainerDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.BackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.ContainerSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
var container = targetSelect.containerUI.container;
if (container.itemState.carriedBy == unit)
{
var otherItem = container.containerContent.items[targetSelect.slotUI.slotIndex];
unit.unitBackpack.Drop(item);
if (otherItem)
{
container.containerContent.MoveOut(otherItem, unit);
unit.unitBackpack.Take(sourceSelect.slotUI.slotIndex, otherItem);
}
container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, item, unit);
}
else
{
unit.OrderStop();
var moveAction = new MoveAction(unit, container, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
var otherItem = container.containerContent.items[targetSelect.slotUI.slotIndex];
if (otherItem)
{
var dropAction = new DropAction(unit, item);
dropAction.OnBeforePerform += () => container.containerContent.MoveOut(otherItem, unit);
dropAction.OnAfterPerform += () => container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, item, unit);
var takeAction = new TakeAction(unit, otherItem, sourceSelect.slotUI.slotIndex);
orderChain.Add(dropAction);
orderChain.Add(takeAction);
}
else
{
var dropAction = new DropAction(unit, item);
dropAction.OnAfterPerform += () => container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, item, unit);
orderChain.Add(dropAction);
}
unit.OrderChain(orderChain);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a918e5b15659447fa7c7c43edfeaf895
timeCreated: 1698784406
@@ -0,0 +1,24 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class BackpackToEquipmentDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.BackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.EquipmentSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
unit.OrderStop();
unit.Order(new EquipAction(unit, wearable, targetSelect.slotUI.slotIndex));
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8fa7fe6f66f94bd29e7b32b0c897e226
timeCreated: 1698784316
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class BackpackToOtherUnitBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.BackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
var otherUnit = GameUI.current.PickComponentUI<OtherUnitBackpackUI>().unit;
unit.OrderStop();
var moveAction = new MoveAction(unit, otherUnit, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
var otherItem = otherUnit.unitBackpack.items[targetSelect.slotUI.slotIndex];
if (otherItem)
{
var dropAction = new DropAction(unit, item);
dropAction.OnAfterPerform += () => new ForcedDropAction(otherUnit, otherItem).DoIt();
orderChain.Add(dropAction);
var canStack = item.CanStackWith(otherItem, out var itemWillBeRemoved);
if (canStack) dropAction.OnAfterPerform += () => item.StackWith(otherItem);
if (!canStack || !itemWillBeRemoved)
{
dropAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, targetSelect.slotUI.slotIndex).DoIt();
orderChain.Add(new TakeAction(unit, otherItem, sourceSelect.slotUI.slotIndex));
}
}
else
{
var dropAction = new DropAction(unit, item);
dropAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, targetSelect.slotUI.slotIndex).DoIt();
orderChain.Add(dropAction);
}
unit.OrderChain(orderChain);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 715441676cf0426997ddf7105a46f32a
timeCreated: 1717963868
@@ -0,0 +1,25 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class BackpackToSceneDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.BackpackSlot
&& targetSelect.slotUI?.slotType == null;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, targetSelect.position, unit.unitData.takeRange));
unit.Order(new DropAction(unit, item, targetSelect.position));
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1c6d639801884d18b380e5b887121275
timeCreated: 1698784050
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class ContainerToBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ContainerSlot
&& targetSelect.slotUI?.slotType == SlotType.BackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
var container = sourceSelect.slotUI.item.itemState.inContainer;
var sourceIndex = sourceSelect.slotUI.slotIndex;
var targetIndex = targetSelect.slotUI.slotIndex;
if (container.itemState.carriedBy == unit)
{
var otherItem = unit.unitBackpack.items[targetIndex];
container.containerContent.MoveOut(item, unit);
unit.unitBackpack.Take(targetIndex, item);
if (otherItem) container.containerContent.MoveIn(targetIndex, otherItem, unit);
}
else
{
var otherItem = unit.unitBackpack.items[targetIndex];
var moveAction = new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
if (otherItem)
{
var dropAction = new DropAction(unit, otherItem);
var takeAction = new TakeAction(unit, item, targetIndex);
takeAction.OnBeforePerform += () => container.containerContent.MoveOut(item, unit);
takeAction.OnAfterPerform += () => container.containerContent.MoveIn(sourceIndex, otherItem, unit);
orderChain.Add(dropAction);
orderChain.Add(takeAction);
}
else
{
var takeAction = new TakeAction(unit, item, targetIndex);
takeAction.OnBeforePerform += () => container.containerContent.MoveOut(item, unit);
orderChain.Add(takeAction);
}
unit.OrderChain(orderChain);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 76702c7ae83e47dfa9d2a9f0ede91563
timeCreated: 1698785372
@@ -0,0 +1,96 @@
using System.Collections.Generic;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class ContainerToContainerDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ContainerSlot
&& targetSelect.slotUI?.slotType == SlotType.ContainerSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
var fromContainer = sourceSelect.slotUI.item.itemState.inContainer;
var fromContainerCarrier = fromContainer.itemState.carriedBy;
var fromIndex = sourceSelect.slotUI.slotIndex;
var toContainer = GameUI.current.PickComponentUI<ContainerUI>().container;
var toContainerCarrier = toContainer.itemState.carriedBy;
var toIndex = targetSelect.slotUI.slotIndex;
if (fromContainer == toContainer)
{
fromContainer.containerContent.Swap(fromIndex, toIndex);
}
else if (fromContainerCarrier == toContainerCarrier)
{
var otherItem = toContainer.containerContent.items[toIndex];
fromContainer.containerContent.MoveOut(item, unit);
if (otherItem) toContainer.containerContent.MoveOut(otherItem, unit);
toContainer.containerContent.MoveIn(toIndex, item, unit);
if (otherItem) fromContainer.containerContent.MoveIn(fromIndex, otherItem, unit);
}
else if (fromContainerCarrier == unit && toContainerCarrier == null)
{
unit.OrderStop();
var moveAction = new MoveAction(unit, toContainer, unit.unitData.takeRange);
var dropAction = new DropAction(unit, item);
dropAction.OnBeforePerform += () => fromContainer.containerContent.MoveOut(item, unit);
dropAction.OnAfterPerform += () => toContainer.containerContent.MoveIn(toIndex, item, unit);
var orderChain = new List<AbstractAction>{ moveAction, dropAction };
var otherItem = toContainer.containerContent.items[toIndex];
if (otherItem)
{
var takeAction = new TakeAction(unit, otherItem, sourceSelect.slotUI.slotIndex);
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(otherItem);
takeAction.OnAfterPerform += () => fromContainer.containerContent.MoveIn(fromIndex, otherItem, unit);
orderChain.Add(takeAction);
}
unit.OrderChain(orderChain);
}
else if (fromContainerCarrier == null && toContainerCarrier == unit)
{
unit.OrderStop();
var otherItem = unit.unitBackpack.items[toIndex];
var moveAction = new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
if (otherItem)
{
var dropAction = new DropAction(unit, otherItem);
dropAction.OnBeforePerform += () => toContainer.containerContent.MoveOut(otherItem, unit);
var takeAction = new TakeAction(unit, item);
takeAction.OnBeforePerform += () => fromContainer.containerContent.MoveOut(item, unit);
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(item);
takeAction.OnAfterPerform += () => toContainer.containerContent.MoveIn(toIndex, item, unit);
takeAction.OnAfterPerform += () => fromContainer.containerContent.MoveIn(fromIndex, otherItem, unit);
orderChain.Add(dropAction);
orderChain.Add(takeAction);
}
else
{
var takeAction = new TakeAction(unit, item, toIndex);
takeAction.OnBeforePerform += () => fromContainer.containerContent.MoveOut(item, unit);
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(item);
takeAction.OnAfterPerform += () => fromContainer.containerContent.MoveOut(item, unit);
orderChain.Add(takeAction);
}
unit.OrderChain(orderChain);
}
else
{
var fromName = fromContainer.basicData.finalName;
var toName = toContainer.basicData.finalName;
Debug.LogWarning($"Dragging between {fromName} -> {toName} not supported!", unit);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 417a87bcf85f44dea63127e220bc37a2
timeCreated: 1698786031
@@ -0,0 +1,40 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class ContainerToEquipmentDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ContainerSlot
&& targetSelect.slotUI?.slotType == SlotType.EquipmentSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
unit.OrderStop();
var container = sourceSelect.slotUI.item.itemState.inContainer;
if (container.itemState.carriedBy == unit)
{
var equipAction = new EquipAction(unit, wearable);
equipAction.OnBeforePerform += () => container.containerContent.MoveOut(wearable, unit);
unit.Order(equipAction);
}
else
{
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var takeAction = new TakeAction(unit, wearable);
takeAction.OnBeforePerform += () => container.containerContent.MoveOut(wearable, unit);
var equipAction = new EquipAction(unit, wearable);
equipAction.runAfterAction = takeAction;
unit.Order(takeAction);
unit.Order(equipAction);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7732a40b30894aeca5551047706b3d4c
timeCreated: 1698785718
@@ -0,0 +1,79 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class ContainerToOtherUnitBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ContainerSlot
&& targetSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
var fromContainer = sourceSelect.slotUI.item.itemState.inContainer;
var carriedBy = sourceSelect.slotUI.item.itemState.carriedBy;
var fromIndex = sourceSelect.slotUI.slotIndex;
var toIndex = targetSelect.slotUI.slotIndex;
var otherUnit = GameUI.current.PickComponentUI<OtherUnitBackpackUI>().unit;
var otherItem = otherUnit.unitBackpack.items[toIndex];
if (carriedBy != null)
{
unit.OrderStop();
var orderChain = new List<AbstractAction>();
orderChain.Add(new MoveAction(unit, otherUnit, unit.unitData.takeRange));
var dropAction = new DropAction(unit, item);
dropAction.OnBeforePerform += () => fromContainer.containerContent.MoveOut(item, unit);
dropAction.OnBeforePerform += () => unit.unitBackpack.Take(item);
orderChain.Add(dropAction);
if (otherItem)
{
var takeAction = new TakeAction(unit, otherItem, sourceSelect.slotUI.slotIndex);
takeAction.OnBeforePerform += () => new ForcedDropAction(otherUnit, otherItem).DoIt();
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(otherItem);
takeAction.OnAfterPerform += () => fromContainer.containerContent.MoveIn(fromIndex, otherItem, unit);
takeAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, toIndex).DoIt();
orderChain.Add(takeAction);
}
else
{
dropAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, toIndex).DoIt();
}
unit.OrderChain(orderChain);
}
else if (carriedBy == null)
{
unit.OrderStop();
var moveAction = new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
if (otherItem)
{
var moveItemAction = new MoveItemAction(unit, item, otherUnit.transform.position);
moveItemAction.OnBeforePerform += () => fromContainer.containerContent.MoveOut(item, unit);
moveItemAction.OnBeforePerform += () => new ForcedDropAction(otherUnit, otherItem).DoIt();
moveItemAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, toIndex).DoIt();
moveItemAction.OnAfterPerform += () => fromContainer.containerContent.MoveIn(fromIndex, otherItem, unit);
orderChain.Add(moveItemAction);
}
else
{
var moveItemAction = new MoveItemAction(unit, item, otherUnit.transform.position);
moveItemAction.OnBeforePerform += () => fromContainer.containerContent.MoveOut(item, unit);
moveItemAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, toIndex).DoIt();
orderChain.Add(moveItemAction);
}
unit.OrderChain(orderChain);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: afc596d37ace4ab69f58589a6b4b3a1c
timeCreated: 1718033491
@@ -0,0 +1,42 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class ContainerToSceneDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.ContainerSlot
&& targetSelect.slotUI?.slotType == null;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
var container = sourceSelect.slotUI.item.itemState.inContainer;
if (container.itemState.carriedBy == unit)
{
unit.Order(new MoveAction(unit, targetSelect.position, unit.unitData.takeRange));
var dropAction = new DropAction(unit, item);
dropAction.OnBeforePerform += () => container.containerContent.MoveOut(item, unit);
dropAction.OnBeforePerform += () => unit.unitBackpack.Take(item);
var moveItemAction = new MoveItemAction(unit, item, targetSelect.position);
moveItemAction.runAfterAction = dropAction;
unit.Order(dropAction);
unit.Order(moveItemAction);
}
else
{
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var moveItemAction = new MoveItemAction(unit, item, targetSelect.position);
moveItemAction.OnBeforePerform += () => container.containerContent.MoveOut(item, unit);
unit.Order(moveItemAction);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a84d1f27e714c4a822c7144f9f54a0d
timeCreated: 1698785210
@@ -0,0 +1,27 @@
using System;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class EquipmentToBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.EquipmentSlot
&& targetSelect.slotUI?.slotType == SlotType.BackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
unit.OrderStop();
var unEquipAction = new UnEquipAction(unit, wearable);
unEquipAction.OnAfterPerform += () => unit.unitBackpack.Swap(Array.IndexOf(unit.unitBackpack.items, wearable), targetSelect.slotUI.slotIndex);
unit.Order(unEquipAction);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d8b3e528d0744c15a772c0c5337527fa
timeCreated: 1698784995
@@ -0,0 +1,44 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class EquipmentToContainerDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.EquipmentSlot
&& targetSelect.slotUI?.slotType == SlotType.ContainerSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
unit.OrderStop();
var container = targetSelect.containerUI.container;
if (container.itemState.carriedBy == unit)
{
var unEquipAction = new UnEquipAction(unit, wearable);
unEquipAction.OnAfterPerform += () =>
container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, wearable, unit);
unit.Order(unEquipAction);
}
else
{
unit.Order(new MoveAction(unit, targetSelect.position, unit.unitData.takeRange));
var dropAction = new DropAction(unit, wearable);
var moveItemAction = new MoveItemAction(unit, wearable, container.transform.position);
moveItemAction.runAfterAction = dropAction;
moveItemAction.OnAfterPerform += () =>
container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, wearable, unit);
unit.Order(dropAction);
unit.Order(moveItemAction);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 47f70dcfb78941dca1a8943275501788
timeCreated: 1698785122
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class EquipmentToEquipmentDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.EquipmentSlot
&& targetSelect.slotUI?.slotType == SlotType.EquipmentSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
if (sourceSelect.slotUI.slotIndex == targetSelect.slotUI.slotIndex) return;
if (!unit.unitEquipment.CanEquipInSlot(targetSelect.slotUI.slotIndex, wearable)) return;
unit.OrderStop();
var orderChain = new List<AbstractAction>();
var otherItem = targetSelect.slotUI.item as WearableObject;
if (otherItem) orderChain.Add(new UnEquipAction(unit, otherItem));
orderChain.Add(new UnEquipAction(unit, wearable));
if (otherItem) orderChain.Add(new EquipAction(unit, otherItem, sourceSelect.slotUI.slotIndex));
orderChain.Add(new EquipAction(unit, wearable, targetSelect.slotUI.slotIndex));
unit.OrderChain(orderChain);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a66f7a7673d94067a286fb2a72ed4f47
timeCreated: 1698785061
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class EquipmentToOtherUnitBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.EquipmentSlot
&& targetSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
unit.OrderStop();
var otherUnit = GameUI.current.PickComponentUI<OtherUnitBackpackUI>().unit;
var orderChain = new List<AbstractAction>();
orderChain.Add(new MoveAction(unit, targetSelect.position, unit.unitData.takeRange));
var dropAction = new DropAction(unit, wearable);
dropAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, wearable, targetSelect.slotUI.slotIndex).DoIt();
orderChain.Add(dropAction);
unit.OrderChain(orderChain);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 26d992915bbd4c59b9ebbe95975f3bc0
timeCreated: 1718031952
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class EquipmentToSceneDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.EquipmentSlot
&& targetSelect.slotUI?.slotType == null;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not WearableObject wearable) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, targetSelect.position, unit.unitData.takeRange));
unit.OrderChain(new List<AbstractAction>
{
new UnEquipAction(unit, wearable),
new DropAction(unit, wearable, targetSelect.position)
});
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 27be82d70f594b0a9d6175de70fe6596
timeCreated: 1698784802
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class OtherUnitBackpackToBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.BackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject otherItem) return;
var otherUnit = otherItem.itemState.carriedBy;
var thisItem = targetSelect.slotUI.item;
unit.OrderStop();
var moveAction = new MoveAction(unit, otherUnit, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
var takeAction = new TakeAction(unit, otherItem, targetSelect.slotUI.slotIndex);
if (thisItem && otherItem.CanStackWith(thisItem))
takeAction.OnAfterPerform += () => otherItem.StackWith(thisItem);
orderChain.Add(takeAction);
unit.OrderChain(orderChain);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eaf6bc7196e74b768a4f75aa8de10664
timeCreated: 1718038380
@@ -0,0 +1,86 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class OtherUnitBackpackToContainerDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.ContainerSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
var toContainer = GameUI.current.PickComponentUI<ContainerUI>().container;
var toContainerCarrier = toContainer.itemState.carriedBy;
var fromIndex = sourceSelect.slotUI.slotIndex;
var toIndex = targetSelect.slotUI.slotIndex;
var otherUnit = item.itemState.carriedBy;
var otherItem = toContainer.containerContent.items[toIndex];
if (toContainerCarrier != null)
{
unit.OrderStop();
var orderChain = new List<AbstractAction>();
orderChain.Add(new MoveAction(unit, otherUnit, unit.unitData.takeRange));
if (otherItem)
{
var takeAction = new TakeAction(unit, item);
takeAction.OnAfterPerform += () => toContainer.containerContent.MoveOut(otherItem, unit);
takeAction.OnAfterPerform += () => unit.unitBackpack.Take(otherItem);
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(item);
takeAction.OnAfterPerform += () => toContainer.containerContent.MoveIn(toIndex, item, unit);
var dropAction = new DropAction(unit, otherItem);
dropAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, otherItem).DoIt();
orderChain.Add(takeAction);
orderChain.Add(dropAction);
}
else
{
var takeAction = new TakeAction(unit, item);
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(item);
takeAction.OnAfterPerform += () => toContainer.containerContent.MoveIn(toIndex, item, unit);
orderChain.Add(takeAction);
}
unit.OrderChain(orderChain);
}
else if (toContainerCarrier == null)
{
unit.OrderStop();
var moveAction = new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange);
var orderChain = new List<AbstractAction> { moveAction };
if (otherItem)
{
var moveItemAction = new MoveItemAction(unit, item, toContainer.transform.position);
moveItemAction.OnBeforePerform += () => new ForcedDropAction(otherUnit, item).DoIt();
moveItemAction.OnAfterPerform += () => toContainer.containerContent.MoveOut(otherItem, unit);
moveItemAction.OnAfterPerform += () => toContainer.containerContent.MoveIn(toIndex, item, unit);
moveItemAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, otherItem, fromIndex).DoIt();
orderChain.Add(moveItemAction);
}
else
{
var moveItemAction = new MoveItemAction(unit, item, toContainer.transform.position);
moveItemAction.OnBeforePerform += () => new ForcedDropAction(otherUnit, item).DoIt();
moveItemAction.OnAfterPerform += () => toContainer.containerContent.MoveIn(toIndex, item, unit);
orderChain.Add(moveItemAction);
}
unit.OrderChain(orderChain);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 25c8a7fb404c410e9e47bc5324b6250b
timeCreated: 1718040161
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class OtherUnitBackpackToEquipmentDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.EquipmentSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
var otherUnit = item.itemState.carriedBy;
var fromIndex = sourceSelect.slotUI.slotIndex;
var toIndex = targetSelect.slotUI.slotIndex;
var otherWearable = unit.unitEquipment.GetEquipped(toIndex);
unit.OrderStop();
var orderChain = new List<AbstractAction>();
orderChain.Add(new MoveAction(unit, otherUnit, unit.unitData.takeRange));
orderChain.Add(new TakeAction(unit, item));
if (otherWearable)
{
var dropAction = new DropAction(unit, otherWearable);
dropAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, fromIndex).DoIt();
orderChain.Add(dropAction);
}
if (item is WearableObject wearable)
{
orderChain.Add(new EquipAction(unit, wearable, targetSelect.slotUI.slotIndex));
}
unit.OrderChain(orderChain);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b4e62c66a06455e92d726822af1e02b
timeCreated: 1718039368
@@ -0,0 +1,50 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class OtherUnitBackpackToOtherUnitBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot
&& targetSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject fromItem) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var fromDeadUnit = fromItem.itemState.carriedBy;
var toDeadUnit = GameUI.current.PickComponentUI<OtherUnitBackpackUI>().unit;
var fromIndex = sourceSelect.slotUI.slotIndex;
var toIndex = targetSelect.slotUI.slotIndex;
var toItem = toDeadUnit.unitBackpack.items[toIndex];
if (toItem)
{
var moveItemAction = new MoveItemAction(unit, fromItem, toDeadUnit.transform.position);
moveItemAction.OnBeforePerform += () => new ForcedDropAction(fromDeadUnit, fromItem).DoIt();
moveItemAction.OnBeforePerform += () => new ForcedDropAction(toDeadUnit, toItem).DoIt();
var canStack = fromItem.CanStackWith(toItem, out var itemWillBeRemoved);
if (canStack) moveItemAction.OnBeforePerform += () => fromItem.StackWith(toItem);
moveItemAction.OnAfterPerform += () => new ForcedTakeAction(toDeadUnit, fromItem, toIndex).DoIt();
if (!itemWillBeRemoved) moveItemAction.OnAfterPerform += () => new ForcedTakeAction(fromDeadUnit, toItem, fromIndex).DoIt();
unit.Order(moveItemAction);
}
else
{
var moveItemAction = new MoveItemAction(unit, fromItem, toDeadUnit.transform.position);
moveItemAction.OnBeforePerform += () => new ForcedDropAction(fromDeadUnit, fromItem).DoIt();
moveItemAction.OnAfterPerform += () => new ForcedTakeAction(toDeadUnit, fromItem, toIndex).DoIt();
unit.Order(moveItemAction);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 81f800d435364c459cab3e01c4236c58
timeCreated: 1718043824
@@ -0,0 +1,29 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class OtherUnitBackpackToSceneDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot
&& targetSelect.slotUI?.slotType == null;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var otherUnit = item.itemState.carriedBy;
var moveItemAction = new MoveItemAction(unit, item, targetSelect.position);
moveItemAction.OnBeforePerform += () => new ForcedDropAction(otherUnit, item).DoIt();
unit.Order(moveItemAction);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 38ede8e0c3df41d8a47e74d72e55bb02
timeCreated: 1718037826
@@ -0,0 +1,29 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Usable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class SceneToActionBarDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == null
&& targetSelect.slotUI?.slotType == SlotType.ActionBarSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var takeAction = new TakeAction(unit, item);
if (sourceSelect.selectObject is UsableObject usable)
takeAction.OnAfterPerform += () => unit.unitActionBar.Set(targetSelect.slotUI.slotIndex, usable);
unit.Order(takeAction);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f69b5ebe04f440c9469f4d782068417
timeCreated: 1698783893
@@ -0,0 +1,29 @@
using System;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class SceneToBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == null
&& targetSelect.slotUI?.slotType == SlotType.BackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var takeAction = new TakeAction(unit, item);
takeAction.OnAfterPerform += () =>
unit.unitBackpack.Swap(Array.IndexOf(unit.unitBackpack.items, item), targetSelect.slotUI.slotIndex);
unit.Order(takeAction);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 46c073e148f34906b94428dc5701449b
timeCreated: 1698783569
@@ -0,0 +1,42 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class SceneToContainerDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == null
&& targetSelect.slotUI?.slotType == SlotType.ContainerSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var container = GameUI.current.PickComponentUI<ContainerUI>().container;
if (container.itemState.carriedBy == unit)
{
var takeAction = new TakeAction(unit, item);
takeAction.OnAfterPerform += () => unit.unitBackpack.Drop(item);
takeAction.OnAfterPerform += () =>
container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, item, unit);
unit.Order(takeAction);
}
else
{
var moveAction = new MoveItemAction(unit, item, container.transform.position);
moveAction.OnAfterPerform += () =>
container.containerContent.MoveIn(targetSelect.slotUI.slotIndex, item, unit);
unit.Order(moveAction);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3b905f13c67c42068ca94b4729afbb66
timeCreated: 1698783960
@@ -0,0 +1,31 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class SceneToEquipmentDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == null
&& targetSelect.slotUI?.slotType == SlotType.EquipmentSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var takeAction = new TakeAction(unit, item);
unit.Order(takeAction);
if (sourceSelect.selectObject is not WearableObject wearable) return;
var equipAction = new EquipAction(unit, wearable);
equipAction.runAfterAction = takeAction;
unit.Order(equipAction);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3312e4749bd94a94a67b79c9d0afdf32
timeCreated: 1698783820
@@ -0,0 +1,31 @@
using VOID.Generic.Dict;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
using VOID.UserInterface;
using VOID.UserInterface.Game;
namespace VOID.Generic.Player.DraggingOperation
{
public class SceneToOtherUnitBackpackDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == null
&& targetSelect.slotUI?.slotType == SlotType.OtherUnitBackpackSlot;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
var otherUnit = GameUI.current.PickComponentUI<OtherUnitBackpackUI>().unit;
var moveAction = new MoveItemAction(unit, item, otherUnit.transform.position);
moveAction.OnAfterPerform += () => new ForcedTakeAction(otherUnit, item, targetSelect.slotUI.slotIndex).DoIt();
unit.Order(moveAction);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9385b685493d436187c735c921884f15
timeCreated: 1717970430
@@ -0,0 +1,24 @@
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Player.Util;
namespace VOID.Generic.Player.DraggingOperation
{
public class SceneToSceneDraggingOperation : AbstractDraggingOperation
{
public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
return sourceSelect.slotUI?.slotType == null
&& targetSelect.slotUI?.slotType == null;
}
public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
{
if (sourceSelect.selectObject is not ItemObject item) return;
unit.OrderStop();
unit.Order(new MoveAction(unit, sourceSelect.position, unit.unitData.takeRange));
unit.Order(new MoveItemAction(unit, item, targetSelect.position));
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 532ed242e6534be3b4ef0a34d1ed3ce5
timeCreated: 1698780991
@@ -0,0 +1,97 @@
using System.Linq;
using Sirenix.OdinInspector;
using Sirenix.Utilities;
using UnityEngine;
using UnityEngine.Rendering;
using VOID.Generic.Objects.Item;
using VOID.Generic.Trajectory;
namespace VOID.Generic.Player
{
[DefaultExecutionOrder(-1)]
public class DraggingVisualizer : MonoBehaviour
{
[ShowInInspector] private Transform _transformStart;
[ShowInInspector] private Transform _transformEnd;
private Vector3 _positionStart;
private Vector3 _positionEnd;
private Vector3 _lastPositionStart;
private Vector3 _lastPositionEnd;
private LineRenderer _lineRenderer;
private ParabolicTrajectory _trajectory = new();
public static DraggingVisualizer Create(Transform transformStart, Transform transformEnd, ItemObject item)
{
// Prepare for scene dragging
var go = Instantiate(item.gameObject);
go.name = "Dragging Visualizer Dummy - " + go.name;
go.transform.localPosition = Vector3.zero;
go.transform.rotation = Quaternion.Euler(0, go.transform.rotation.eulerAngles.y, 0);
// Remove everything except rendering components
go.GetComponentsInChildren<Component>()
.Where(component => component is not Transform and not MeshFilter and not MeshRenderer)
.ForEach(component => Destroy(component));
// Make sure that our dummy don't copy highlight/outlines
go.GetComponentsInChildren<Component>()
.FilterCast<MeshRenderer>()
.ForEach(meshRenderer =>
meshRenderer.sharedMaterials = meshRenderer.sharedMaterials
.Where(material => !HighlightManager.current.shaders.Contains(material.shader))
.ToArray());
var draggingVisualizer = go.AddComponent<DraggingVisualizer>();
draggingVisualizer._transformStart = transformStart;
draggingVisualizer._transformEnd = transformEnd;
// Nice trajectory how item move
draggingVisualizer._lineRenderer = go.AddComponent<LineRenderer>();
draggingVisualizer._lineRenderer.startWidth = 0.1f;
draggingVisualizer._lineRenderer.endWidth = 0.1f;
draggingVisualizer._lineRenderer.shadowCastingMode = ShadowCastingMode.Off;
draggingVisualizer._trajectory.height = 1f;
return draggingVisualizer;
}
private void FixedUpdate()
{
if (!_transformStart || !_transformEnd) return;
_positionStart = _transformStart.position;
_positionEnd = _transformEnd.position;
if (_positionStart == _lastPositionStart && _positionEnd == _lastPositionEnd) return;
_lastPositionStart = _positionStart;
_lastPositionEnd = _positionEnd;
transform.position = _positionEnd;
if (gameObject.activeSelf) UpdateTrajectory();
}
private void UpdateTrajectory()
{
_trajectory.Init(_positionStart, _positionEnd);
var pointsNeeded = Mathf.Max(1, Mathf.FloorToInt(_trajectory.trajectoryDistance)) * 10;
var points = _trajectory.GetPositions(pointsNeeded);
_lineRenderer.positionCount = points.Length;
_lineRenderer.SetPositions(points);
}
public void Show()
{
gameObject.SetActive(true);
}
public void Hide()
{
gameObject.SetActive(false);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 48da54c8e4b741669616cbbd41c08923
timeCreated: 1696799345
@@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using QuickOutline;
using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Abstract;
using VOID.Generic.Objects.Item;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Player.Input;
using VOID.Generic.Player.Util;
using VOID.Generic.Triggers;
using VOID.UserInterface.Game.Party;
using VOID.Generic.Util;
using VOID.Generic.World;
namespace VOID.Generic.Player
{
/// <summary>
/// Manages Highlights and Outlines of <see cref="UnitObject"/>s and <see cref="ItemObject"/>s in 2 modes:<br/>
/// - When cursor is over specific object - highlight that object<br/>
/// - When button is pressed - highlight all objects in range<br/>
/// <br/>
/// <see cref="UnitObject"/> can be selected from SCENE or <see cref="UnitPortraitUI"/>
/// </summary>
[DefaultExecutionOrder(-1)]
public class HighlightManager : MonoBehaviour, IDynamicTrigger
{
public static HighlightManager current { get; private set; }
[Title("Shaders used")]
[SerializeField] public Shader[] shaders;
[Title("Colors")]
[SerializeField] private Color _enemyColor;
[SerializeField] private Color _cautiousColor;
[SerializeField] private Color _neutralColor;
[SerializeField] private Color _friendlyColor;
[SerializeField] private Color _companionColor;
[SerializeField] private Color _selfColor;
[SerializeField] private Color _itemColor;
[Title("Outline")]
[SerializeField] private float _outlineWidth;
[SerializeField] private Outline.Mode _outlineMode;
[Title("Group Outline")]
[SerializeField] private float _range = Area.Size;
// Runtime
private GameObject _highlightGameObject;
private SphereCollider _collider;
private Transform _stickTo;
private readonly List<UnitObject> _unitsInRange = new();
// private readonly List<AbstractObject> _objectsInRange = new();
private AbstractObject _objectUnderCursor;
private void Awake()
{
current = this;
_highlightGameObject = new GameObject("Highlight Range");
_highlightGameObject.transform.parent = gameObject.transform;
_highlightGameObject.layer = LayerManager.TriggerIndex;
_collider = _highlightGameObject.AddComponent<SphereCollider>();
_collider.radius = _range;
_collider.isTrigger = true;
}
private void Start()
{
PlayerController.current.OnActiveUnitChange += OnActiveUnitChange;
PlayerInputManager.current.OnHighlightStart += ShowHighlightForAllInRange;
PlayerInputManager.current.OnHighlightEnd += HideHighlightForAllInRange;
}
private void FixedUpdate()
{
StickTo();
HighlightUnderCursor();
}
private void StickTo()
{
if (_stickTo) _highlightGameObject.transform.position = _stickTo.position;
}
private void HighlightUnderCursor()
{
// Find whats under cursor, we allow only ItemObject (from scene) and UnitObject (from scene and portraits)
var select = SelectUtil.Select();
// There is nothing under cursor, but something was previous frame!
if (!select.selectObject && _objectUnderCursor)
{
HideHighlight(_objectUnderCursor);
_objectUnderCursor = null;
}
// Nothing to highlight
if (!select.selectObject) return;
// This one was already under cursor and is highlighted previously
if (select.selectObject == _objectUnderCursor) return;
// There is something new under cursor - hide previous object highlight and continue
if (_objectUnderCursor) HideHighlight(_objectUnderCursor);
_objectUnderCursor = select.selectObject;
ShowHighlight(_objectUnderCursor);
}
private void OnActiveUnitChange(UnitObject unitObject)
{
_stickTo = unitObject.transform;
}
public void OnObjectEnter(AbstractObject obj)
{
if (obj is not UnitObject unit) return;
_unitsInRange.Add(unit);
if (PlayerInputManager.current.isHighlight) ShowHighlight(unit);
}
public void OnObjectExit(AbstractObject obj)
{
if (obj is not UnitObject unit) return;
_unitsInRange.Remove(unit);
if (PlayerInputManager.current.isHighlight) HideHighlight(unit);
}
private void ShowHighlight(AbstractObject obj)
{
// Highlighting only when object allow that on itself
if (!obj.basicData.canBeSelected) return;
var outline = obj.gameObject.GetComponent<Outline>();
if (!outline) outline = obj.gameObject.AddComponent<Outline>();
if (obj is UnitObject unit) outline.OutlineColor = GetColorForUnit(unit);
else outline.OutlineColor = _itemColor;
outline.OutlineMode = _outlineMode;
outline.OutlineWidth = _outlineWidth;
outline.enabled = true;
}
private void HideHighlight(AbstractObject obj)
{
if (PlayerInputManager.current.isHighlight && obj is UnitObject unit && _unitsInRange.Contains(unit)) return;
if (obj.TryGetComponent<Outline>(out var outline)) outline.enabled = false;
}
private void ShowHighlightForAllInRange()
{
_unitsInRange.ForEach(ShowHighlight);
}
private void HideHighlightForAllInRange()
{
_unitsInRange.ForEach(HideHighlight);
}
private Color GetColorForUnit(UnitObject unit)
{
if (!PlayerController.current.activeUnit) return _neutralColor;
if (unit == PlayerController.current.activeUnit) return _selfColor;
var attitudeType = PlayerController.current.activeUnit.unitAttitude.GetAttitudeWith(unit);
return attitudeType switch
{
AttitudeType.Hostile => _enemyColor,
AttitudeType.Cautious => _cautiousColor,
AttitudeType.Neutral => _neutralColor,
AttitudeType.Friendly => _friendlyColor,
AttitudeType.Companion => _companionColor,
_ => throw new ArgumentOutOfRangeException(nameof(attitudeType), attitudeType, null)
};
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab5f83ac9fae46889336831f67ed4807
timeCreated: 1724089074
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2a400186bc224ca09f215e95a7397a0e
timeCreated: 1698606025
@@ -0,0 +1,96 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace VOID.Generic.Player.Input
{
[DefaultExecutionOrder(1)]
public class CameraInputManager : MonoBehaviour
{
public static CameraInputManager current {get; private set;}
private Inputs _inputs;
// Input actions for camera controlling
public InputAction movement {get; private set;}
public InputAction movementFaster {get; private set;}
public InputAction rotatingAndTiltingStart {get; private set;}
public InputAction rotatingAndTilting {get; private set;}
public InputAction zooming {get; private set;}
// States
public bool isMoving {get; private set;}
public bool isMovingFaster {get; private set;}
public bool isRotatingAndTilting {get; private set;}
public bool isZooming {get; private set;}
// Deltas
public Vector2 movementDelta { get; private set; }
public Vector2 rotateAndTiltDelta { get; private set; }
public float zoomDelta { get; private set; }
private void Awake()
{
current = this;
_inputs = new Inputs();
// CameraMovement
movement = _inputs.CameraControls.Movement;
movement.started += _ => isMoving = true;
movement.performed += _ => OnCameraMovement();
movement.canceled += _ => isMoving = false;
// CameraMovementFaster
movementFaster = _inputs.CameraControls.MovementFaster;
movementFaster.started += _ => isMovingFaster = true;
movementFaster.canceled += _ => isMovingFaster = false;
// CameraRotatingAndTiltingStart
rotatingAndTiltingStart = _inputs.CameraControls.RotatingAndTiltingStart;
rotatingAndTiltingStart.started += _ => isRotatingAndTilting = true;
rotatingAndTiltingStart.canceled += _ => isRotatingAndTilting = false;
// CameraRotatingAndTilting
rotatingAndTilting = _inputs.CameraControls.RotatingAndTilting;
rotatingAndTilting.performed += _ => OnCameraRotateAndTilt();
// CameraZooming
zooming = _inputs.CameraControls.Zooming;
zooming.performed += _ => OnCameraZoom();
zooming.performed += _ => isZooming = true;
}
private void OnEnable()
{
movement.Enable();
movementFaster.Enable();
rotatingAndTiltingStart.Enable();
rotatingAndTilting.Enable();
zooming.Enable();
}
private void OnDisable()
{
movement.Disable();
movementFaster.Disable();
rotatingAndTiltingStart.Disable();
rotatingAndTilting.Disable();
zooming.Disable();
}
private void FixedUpdate()
{
// Reset delta after all ->FixedUpdate()
isZooming = false;
if (!isMoving) movementDelta = Vector2.zero;
rotateAndTiltDelta = Vector2.zero;
zoomDelta = 0f;
}
private void OnCameraMovement() => movementDelta = movement.ReadValue<Vector2>();
private void OnCameraRotateAndTilt() => rotateAndTiltDelta += rotatingAndTilting.ReadValue<Vector2>();
private void OnCameraZoom() => zoomDelta += zooming.ReadValue<Vector2>().y;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 63e6969e576443818d870e9cc367f015
timeCreated: 1687555087
@@ -0,0 +1,44 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace VOID.Generic.Player.Input
{
[DefaultExecutionOrder(1)]
public class CastingInputManager : MonoBehaviour
{
public static CastingInputManager current {get; private set;}
private Inputs _inputs;
// Input actions for player controlling
public InputAction confirm {get; private set;}
public InputAction cancel {get; private set;}
private void Awake()
{
current = this;
_inputs = new Inputs();
// PlayerDefaultUse
confirm = _inputs.CastingControls.Confirm;
cancel = _inputs.CastingControls.Cancel;
}
private void Start()
{
enabled = false;
}
private void OnEnable()
{
confirm.Enable();
cancel.Enable();
}
private void OnDisable()
{
confirm.Disable();
cancel.Disable();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1386fc5960bb4b0ebdc9d5ac0de3cdfb
timeCreated: 1687556100
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
using UnityEngine.UIElements;
using VOID.UserInterface;
namespace VOID.Generic.Player.Input
{
[DefaultExecutionOrder(1)]
public class PlayerInputManager : MonoBehaviour
{
public static PlayerInputManager current { get; private set; }
private Inputs _inputs;
// Input actions for player controlling
private InputAction _defaultUse;
private InputAction _contextUse;
private InputAction _defaultUseOnUI;
private InputAction _forceAttack;
private InputAction _forceMove;
private InputAction _dragging;
private InputAction _highlight;
// Events
public event Action OnDefaultUse;
public event Action OnContextUse;
public event Action<Vector2, List<VisualElement>> OnDefaultUseUI;
public event Action<Vector2, List<VisualElement>> OnDefaultAlternateUseUI;
public event Action OnForceAttackStart;
public event Action OnForceAttackEnd;
public event Action OnForceMoveStart;
public event Action OnForceMoveEnd;
public event Action OnDraggingPrepare;
public event Action OnDraggingStart;
public event Action OnDraggingEnd;
public event Action OnHighlightStart;
public event Action OnHighlightEnd;
// States
public bool isForceAttack { get; private set; }
public bool isForceMove { get; private set; }
public bool isDragging { get; private set; }
public bool isHighlight { get; private set; }
// Cache - position and VisualElement when clicking on UI started
private Vector2 _cursorPositionOnUI;
private List<VisualElement> _elementsUnderCursor;
private void Awake()
{
current = this;
_inputs = new Inputs();
// Default on SCENE
_defaultUse = _inputs.PlayerControls.DefaultUse;
_defaultUse.performed += _ => OnDefaultUse?.Invoke();
// Context on SCENE
_contextUse = _inputs.PlayerControls.ContextUse;
_contextUse.performed += _ => OnContextUse?.Invoke();
// Default on UI (or alternate default)
_defaultUseOnUI = _inputs.PlayerControls.DefaultUseOnUI;
_defaultUseOnUI.started += callback =>
{
if (callback.interaction is not MultiTapInteraction) return;
_cursorPositionOnUI = default;
_elementsUnderCursor = default;
if (GameUI.current.isCursorOverUI == false) return;
_cursorPositionOnUI = GameUI.current.cursorPositionOnUI;
_elementsUnderCursor = GameUI.current.elementsUnderCursor.ToList();
};
_defaultUseOnUI.performed += callback =>
{
if (_cursorPositionOnUI == default) return;
if (callback.interaction is MultiTapInteraction) OnDefaultUseUI?.Invoke(_cursorPositionOnUI, _elementsUnderCursor);
else OnDefaultAlternateUseUI?.Invoke(_cursorPositionOnUI, _elementsUnderCursor);
};
// PlayerForceAttack
_forceAttack = _inputs.PlayerControls.ForceAttack;
_forceAttack.started += _ => isForceAttack = true;
_forceAttack.started += _ => OnForceAttackStart?.Invoke();
_forceAttack.canceled += _ => isForceAttack = false;
_forceAttack.canceled += _ => OnForceAttackEnd?.Invoke();
// PlayerForceMove
_forceMove = _inputs.PlayerControls.ForceMove;
_forceMove.started += _ => isForceMove = true;
_forceMove.started += _ => OnForceMoveStart?.Invoke();
_forceMove.canceled += _ => isForceMove = false;
_forceMove.canceled += _ => OnForceMoveEnd?.Invoke();
// PlayerDragging
_dragging = _inputs.PlayerControls.Dragging;
_dragging.started += _ => isDragging = true;
_dragging.started += _ => OnDraggingPrepare?.Invoke();
_dragging.performed += _ => OnDraggingStart?.Invoke();
_dragging.canceled += _ => isDragging = false;
_dragging.canceled += _ => OnDraggingEnd?.Invoke();
// Highlight
_highlight = _inputs.PlayerControls.Highlight;
_highlight.started += _ => isHighlight = true;
_highlight.started += _ => OnHighlightStart?.Invoke();
_highlight.canceled += _ => isHighlight = false;
_highlight.canceled += _ => OnHighlightEnd?.Invoke();
}
private void OnEnable()
{
_defaultUse.Enable();
_defaultUseOnUI.Enable();
_contextUse.Enable();
_forceAttack.Enable();
_forceMove.Enable();
_dragging.Enable();
_highlight.Enable();
}
private void OnDisable()
{
_defaultUse.Disable();
_defaultUseOnUI.Disable();
_contextUse.Disable();
_forceAttack.Disable();
_forceMove.Disable();
_dragging.Disable();
_highlight.Disable();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3950a7fded2c3564ca37845076f8c112
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,161 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace VOID.Generic.Player.Input
{
[DefaultExecutionOrder(1)]
public class ShortcutsInputManager : MonoBehaviour
{
public static ShortcutsInputManager current {get; private set;}
private Inputs _inputs;
public InputAction menu {get; private set;}
public InputAction inventory {get; private set;}
public InputAction equipment {get; private set;}
public InputAction abilityBook {get; private set;}
public InputAction logBook {get; private set;}
public InputAction map {get; private set;}
public InputAction actionBarNext {get; private set;}
public InputAction actionBarPrevious {get; private set;}
public InputAction actionBarSlot1 {get; private set;}
public InputAction actionBarSlot2 {get; private set;}
public InputAction actionBarSlot3 {get; private set;}
public InputAction actionBarSlot4 {get; private set;}
public InputAction actionBarSlot5 {get; private set;}
public InputAction actionBarSlot6 {get; private set;}
public InputAction actionBarSlot7 {get; private set;}
public InputAction actionBarSlot8 {get; private set;}
public InputAction actionBarSlot9 {get; private set;}
public InputAction actionBarSlot10 {get; private set;}
public InputAction actionBarSlot11 {get; private set;}
public InputAction actionBarSlot12 {get; private set;}
public InputAction actionBarSlot13 {get; private set;}
public InputAction actionBarSlot14 {get; private set;}
public InputAction actionBarSlot15 {get; private set;}
public InputAction actionBarSlot16 {get; private set;}
public InputAction actionBarSlot17 {get; private set;}
public InputAction actionBarSlot18 {get; private set;}
public InputAction actionBarSlot19 {get; private set;}
public InputAction actionBarSlot20 {get; private set;}
public InputAction actionBarSlot21 {get; private set;}
public InputAction actionBarSlot22 {get; private set;}
public InputAction actionBarSlot23 {get; private set;}
public InputAction actionBarSlot24 {get; private set;}
public InputAction actionBarSlot25 {get; private set;}
private void Awake()
{
current = this;
_inputs = new Inputs();
menu = _inputs.ShortcutsControls.Menu;
inventory = _inputs.ShortcutsControls.Inventory;
equipment = _inputs.ShortcutsControls.Equipment;
abilityBook = _inputs.ShortcutsControls.AbilityBook;
logBook = _inputs.ShortcutsControls.LogBook;
map = _inputs.ShortcutsControls.Map;
actionBarNext = _inputs.ShortcutsControls.ActionBarNext;
actionBarPrevious = _inputs.ShortcutsControls.ActionBarPrevious;
actionBarSlot1 = _inputs.ShortcutsControls.ActionBarSlot1;
actionBarSlot2 = _inputs.ShortcutsControls.ActionBarSlot2;
actionBarSlot3 = _inputs.ShortcutsControls.ActionBarSlot3;
actionBarSlot4 = _inputs.ShortcutsControls.ActionBarSlot4;
actionBarSlot5 = _inputs.ShortcutsControls.ActionBarSlot5;
actionBarSlot6 = _inputs.ShortcutsControls.ActionBarSlot6;
actionBarSlot7 = _inputs.ShortcutsControls.ActionBarSlot7;
actionBarSlot8 = _inputs.ShortcutsControls.ActionBarSlot8;
actionBarSlot9 = _inputs.ShortcutsControls.ActionBarSlot9;
actionBarSlot10 = _inputs.ShortcutsControls.ActionBarSlot10;
actionBarSlot11 = _inputs.ShortcutsControls.ActionBarSlot11;
actionBarSlot12 = _inputs.ShortcutsControls.ActionBarSlot12;
actionBarSlot13 = _inputs.ShortcutsControls.ActionBarSlot13;
actionBarSlot14 = _inputs.ShortcutsControls.ActionBarSlot14;
actionBarSlot15 = _inputs.ShortcutsControls.ActionBarSlot15;
actionBarSlot16 = _inputs.ShortcutsControls.ActionBarSlot16;
actionBarSlot17 = _inputs.ShortcutsControls.ActionBarSlot17;
actionBarSlot18 = _inputs.ShortcutsControls.ActionBarSlot18;
actionBarSlot19 = _inputs.ShortcutsControls.ActionBarSlot19;
actionBarSlot20 = _inputs.ShortcutsControls.ActionBarSlot20;
actionBarSlot21 = _inputs.ShortcutsControls.ActionBarSlot21;
actionBarSlot22 = _inputs.ShortcutsControls.ActionBarSlot22;
actionBarSlot23 = _inputs.ShortcutsControls.ActionBarSlot23;
actionBarSlot24 = _inputs.ShortcutsControls.ActionBarSlot24;
actionBarSlot25 = _inputs.ShortcutsControls.ActionBarSlot25;
}
private void OnEnable()
{
menu.Enable();
inventory.Enable();
equipment.Enable();
abilityBook.Enable();
logBook.Enable();
map.Enable();
actionBarNext.Enable();
actionBarPrevious.Enable();
actionBarSlot1.Enable();
actionBarSlot2.Enable();
actionBarSlot3.Enable();
actionBarSlot4.Enable();
actionBarSlot5.Enable();
actionBarSlot6.Enable();
actionBarSlot7.Enable();
actionBarSlot8.Enable();
actionBarSlot9.Enable();
actionBarSlot10.Enable();
actionBarSlot11.Enable();
actionBarSlot12.Enable();
actionBarSlot13.Enable();
actionBarSlot14.Enable();
actionBarSlot15.Enable();
actionBarSlot16.Enable();
actionBarSlot17.Enable();
actionBarSlot18.Enable();
actionBarSlot19.Enable();
actionBarSlot20.Enable();
actionBarSlot21.Enable();
actionBarSlot22.Enable();
actionBarSlot23.Enable();
actionBarSlot24.Enable();
actionBarSlot25.Enable();
}
private void OnDisable()
{
menu.Disable();
inventory.Disable();
equipment.Disable();
abilityBook.Disable();
logBook.Disable();
map.Disable();
actionBarNext.Disable();
actionBarPrevious.Disable();
actionBarSlot1.Disable();
actionBarSlot2.Disable();
actionBarSlot3.Disable();
actionBarSlot4.Disable();
actionBarSlot5.Disable();
actionBarSlot6.Disable();
actionBarSlot7.Disable();
actionBarSlot8.Disable();
actionBarSlot9.Disable();
actionBarSlot10.Disable();
actionBarSlot11.Disable();
actionBarSlot12.Disable();
actionBarSlot13.Disable();
actionBarSlot14.Disable();
actionBarSlot15.Disable();
actionBarSlot16.Disable();
actionBarSlot17.Disable();
actionBarSlot18.Disable();
actionBarSlot19.Disable();
actionBarSlot20.Disable();
actionBarSlot21.Disable();
actionBarSlot22.Disable();
actionBarSlot23.Disable();
actionBarSlot24.Disable();
actionBarSlot25.Disable();
}
}
}

Some files were not shown because too many files have changed in this diff Show More