commit 22ac4ed11ee7304b963f3469f304bd64179013ae
parent 8c36c89648ffeb1087f525bef0719de229220fe6
Author: PlutoTank <qwolkensperg@gmail.com>
Date: Sat, 18 Apr 2020 20:34:33 -0400
round 2 trigger edits orbtials
Diffstat:
4 files changed, 202 insertions(+), 25 deletions(-)
diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/Orbital.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/Orbital.cs
@@ -1,15 +1,59 @@
using System;
+using System.Collections.Generic;
+using Slimecing.Dependency;
+using Slimecing.Swords.DropBehaviour;
+using UnityEditor;
using UnityEngine;
namespace Slimecing.Swords.Orbitals
{
[Serializable]
- public class OrbitalPackage
+ public class Orbital
{
-
+
+ [SerializeField] private GameObject owner;
[SerializeField] private GameObject orbital;
[SerializeField] private OrbitalLogic orbitalLogic;
+ [SerializeField] private float orbitalSpeed;
+ [SerializeField] private float yOffset;
+ [SerializeField] private float xAxis;
+ [SerializeField] private float yAxis;
[SerializeField] private bool sticky;
+ [SerializeField] private LayerMask dropLayer;
+
+ private List<Collider> _ignoredCollisions;
+ private bool _hasDropBehaviour;
+
+ private GameObject _cachedOwner;
+ private GameObject _cachedOrbital;
+ private OrbitalLogic _cachedOrbitalLogic;
+ public Collider orbitalCollider { get; private set; }
+ public Collider ownerCollider { get; private set; }
+ public float orbitalProgress { get; set; }
+ public Ellipse orbitPath { get; set; }
+ public float rotationSpeed
+ {
+ get => orbitalSpeed;
+ set => orbitalSpeed = value;
+ }
+
+ public float verticalOffset
+ {
+ get => yOffset;
+ set => yOffset = value;
+ }
+
+ public float radiusX
+ {
+ get => xAxis;
+ set => xAxis = value;
+ }
+
+ public float radiusY
+ {
+ get => yAxis;
+ set => yAxis = value;
+ }
public bool orbitalSticky
{
@@ -17,18 +61,10 @@ namespace Slimecing.Swords.Orbitals
set => sticky = value;
}
- public OrbitalPackage(GameObject orbital, OrbitalLogic orbitalLogic)
+ public GameObject ownerObject
{
- this.orbital = orbital;
- this.orbitalLogic = orbitalLogic;
- sticky = false;
- }
-
- public OrbitalPackage(GameObject orbital, OrbitalLogic orbitalLogic, bool sticky)
- {
- this.orbital = orbital;
- this.orbitalLogic = orbitalLogic;
- this.sticky = sticky;
+ get => owner;
+ set => owner = value;
}
public GameObject orbitalObject
@@ -42,5 +78,110 @@ namespace Slimecing.Swords.Orbitals
get => orbitalLogic;
set => orbitalLogic = value;
}
+
+ public Orbital()
+ {
+ orbitPath = new Ellipse(radiusX, radiusY);
+ }
+
+ public Orbital(GameObject owner, GameObject orbital, OrbitalLogic orbitalLogic, float orbitalSpeed,
+ float yOffset, float xAxis, float yAxis, bool sticky)
+ {
+ this.owner = owner;
+ this.orbital = orbital;
+ this.orbitalLogic = orbitalLogic;
+ this.orbitalSpeed = orbitalSpeed;
+ this.yOffset = yOffset;
+ this.xAxis = xAxis;
+ this.yAxis = yAxis;
+ this.sticky = sticky;
+ orbitPath = new Ellipse(radiusX, radiusY);
+ }
+
+ public void Initialize()
+ {
+ orbitPath = new Ellipse(radiusX, radiusY);
+ InitializeOrbitalObject();
+ InitializeOrbitalLogic();
+ }
+
+ private void InitializeOrbitalObject()
+ {
+ SetCollider();
+ if (orbitalObject.GetComponent<DropLogic>() != null) _hasDropBehaviour = true;
+ _cachedOrbital = orbitalObject;
+ _cachedOwner = ownerObject;
+ }
+
+ private void InitializeOrbitalLogic()
+ {
+ currentOrbitalLogic = currentOrbitalLogic.GetOrbital();
+ _cachedOrbitalLogic = currentOrbitalLogic;
+ currentOrbitalLogic.Initialize(this);
+ }
+
+ private void SetCollider()
+ {
+ orbitalCollider = orbital.gameObject.GetComponent<Collider>();
+ ownerCollider = owner.gameObject.GetComponent<Collider>();
+ if (ownerCollider == null || orbitalCollider == null) return;
+ SetIgnoreCollisions(ownerCollider);
+ }
+
+ public void SetIgnoreCollisions(Collider toIgnore)
+ {
+ if (_ignoredCollisions == null)
+ {
+ _ignoredCollisions = new List<Collider>();
+ }
+ Physics.IgnoreCollision(orbitalCollider, toIgnore);
+ _ignoredCollisions.Add(toIgnore);
+ }
+
+ public void UpdateTick()
+ {
+ if (currentOrbitalLogic is IOrbitalTickEveryFrame inputOrbitalLogic)
+ {
+ inputOrbitalLogic.TickUpdate(this);
+ }
+ }
+ public void Tick()
+ {
+ currentOrbitalLogic.Tick(this);
+ }
+
+ public bool Validate()
+ {
+ bool isValid = true;
+ if (_cachedOrbital != orbitalObject || _cachedOwner != ownerObject)
+ {
+ DisableOrbital();
+ InitializeOrbitalObject();
+ isValid = false;
+ }
+
+ if (_cachedOrbitalLogic != currentOrbitalLogic)
+ {
+ InitializeOrbitalLogic();
+ isValid = false;
+ }
+
+ return isValid;
+ }
+
+ public void DisableOrbital()
+ {
+ if (_cachedOrbital == null) return;
+ _cachedOrbital.layer = dropLayer;
+ foreach (var col in _ignoredCollisions)
+ {
+ Physics.IgnoreCollision(orbitalCollider, col,false);
+ }
+
+ if (_hasDropBehaviour)
+ {
+ _cachedOrbital.GetComponent<DropLogic>().Drop();
+ }
+ }
}
}
diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/Orbital.cs.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/Orbital.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9a7d83bd9d2ec714ca732a376bb878d6
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/InputTriggerPolling.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/InputTriggerPolling.cs
@@ -1,26 +1,40 @@
-using UnityEngine;
+using System;
+using UnityEngine;
using UnityEngine.InputSystem;
namespace Slimecing.Triggers.TriggerLogic
{
[CreateAssetMenu(fileName = "AxisInputTrigger(Polling)", menuName = "Triggers/InputTriggers/AxisInputTrigger(Polling)")]
- public class AxisInputTriggerPolling : TriggerInput
+ public class InputTriggerPolling : Trigger
{
- protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx)
+ [SerializeField] private InputActionReference inputActionReference;
+
+ public InputActionReference currentActionReference
{
-
+ get => inputActionReference;
+ set => inputActionReference = value;
}
-
- protected override void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx)
+
+ public InputAction action { get; set; }
+ public PlayerInput currentPlayerInput { get; set; }
+ public override void EnableTrigger(GameObject target)
{
- currentTriggerState = TriggerState.Performed;
- inputContext = ctx;
+ currentPlayerInput = target.GetComponent<PlayerInput>();
+ if (currentPlayerInput == null) return;
+
+ foreach (var a in currentPlayerInput.actions)
+ {
+ if (!currentActionReference.action.name.Equals(a.name)) continue;
+ a.Enable();
+ action = a;
+ }
+
}
- protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx)
+ public override T ReadCurrentValue<T>()
{
- currentTriggerState = TriggerState.Canceled;
- inputContext = ctx;
- }
+ return (T) Convert.ChangeType(action, typeof(T));
+ }
+
}
}
diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/InputTriggerPolling.cs.meta b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/InputTriggerPolling.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b724fbf88219cb4459211c90795c6464
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: