slimecing

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 8c36c89648ffeb1087f525bef0719de229220fe6
parent 4a5cb87e4fb9e585bde16a0fc6e0715ca51422c4
Author: PlutoTank <qwolkensperg@gmail.com>
Date:   Sat, 18 Apr 2020 20:34:10 -0400

trigger edits and better orbitals

Diffstat:
MAssets/Prefabs/Slimes/Slime.prefab | 12+++++++++---
MAssets/Scripts/Slimecing/Abilities/Ability.cs | 8+-------
MAssets/Scripts/Slimecing/Dependency/Ellipse.cs | 9+++++++++
MAssets/Scripts/Slimecing/Swords/DropBehaviour/DropBehaviours/RigidbodyDropLogic.cs | 2++
MAssets/Scripts/Slimecing/Swords/Orbitals/IOrbitalTickEveryFrame.cs | 2+-
RAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs -> Assets/Scripts/Slimecing/Swords/Orbitals/Orbital.cs | 0
MAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogic.cs | 15++++++++-------
MAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs | 79++++++++++++++++++++++++++++++++++---------------------------------------------
MAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs | 45+++++++++++++++++++--------------------------
DAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs.meta | 11-----------
DAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalStats.cs | 37-------------------------------------
DAssets/Scripts/Slimecing/Swords/Orbitals/OrbitalStats.cs.meta | 11-----------
MAssets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset | 1-
DAssets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats.meta | 8--------
DAssets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/InputOrbitalStats.asset | 18------------------
DAssets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/InputOrbitalStats.asset.meta | 8--------
DAssets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/TimerOrbitalStats.asset | 18------------------
DAssets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/TimerOrbitalStats.asset.meta | 8--------
MAssets/Scripts/Slimecing/Swords/Orbitals/TakesOrbitals.cs | 125++++++++++++++-----------------------------------------------------------------
DAssets/Scripts/Slimecing/Triggers/SimpleTrigger.cs | 10----------
DAssets/Scripts/Slimecing/Triggers/SimpleTrigger.cs.meta | 11-----------
MAssets/Scripts/Slimecing/Triggers/Trigger.cs | 13++++++++++++-
MAssets/Scripts/Slimecing/Triggers/TriggerInput.cs | 13+++++++------
DAssets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs.meta | 11-----------
RAssets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs -> Assets/Scripts/Slimecing/Triggers/TriggerLogic/InputTriggerPolling.cs | 0
MAssets/Scripts/Slimecing/Triggers/TriggerLogic/TimerTrigger.cs | 10+++++-----
MAssets/_Scenes/Testing/SLope.unity | 12+++++++++---
27 files changed, 138 insertions(+), 359 deletions(-)

diff --git a/Assets/Prefabs/Slimes/Slime.prefab b/Assets/Prefabs/Slimes/Slime.prefab @@ -1136,13 +1136,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6f7780a3c04e17841825f68a82642af4, type: 3} m_Name: m_EditorClassIdentifier: - defaultOrbitalLogic: {fileID: 11400000, guid: f604a09f73d9b3e4a8d515810e94c6d9, - type: 2} orbitals: - - orbital: {fileID: 2311679785310360297, guid: 4e346bd7fa8310847b295522d78bb540, + - owner: {fileID: 1531394410883810673} + orbital: {fileID: 2311679785310360297, guid: 4e346bd7fa8310847b295522d78bb540, type: 3} orbitalLogic: {fileID: 11400000, guid: e77fb33472e993c4fbd1004f42fc4ed2, type: 2} + orbitalSpeed: 20 + yOffset: 1 + xAxis: 2.5 + yAxis: 2.5 sticky: 0 + dropLayer: + serializedVersion: 2 + m_Bits: 1 --- !u!114 &1450437300 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Slimecing/Abilities/Ability.cs b/Assets/Scripts/Slimecing/Abilities/Ability.cs @@ -21,12 +21,6 @@ namespace Slimecing.Abilities AbilityTrigger.currentTriggerState = TriggerState.Canceled; StartAbility(aUser); } - - private TriggerInput GetInputAbilityActionType() - { - if (abilityTrigger == null) return null; - return abilityTrigger as TriggerInput; - } public Trigger AbilityTrigger { get => abilityTrigger; set => abilityTrigger = value; } @@ -34,7 +28,7 @@ namespace Slimecing.Abilities public virtual void Initialize(AbilityUser aUser) { - GetInputAbilityActionType()?.ConfigureInput(aUser.gameObject); + abilityTrigger.EnableTrigger(aUser.gameObject); if (abilitySound == null) abilitySound = AudioClip.Create("void", 1, 1, 1000, false); abilityTrigger.TriggerStateChange += ctx => CheckActivation(aUser, ctx); diff --git a/Assets/Scripts/Slimecing/Dependency/Ellipse.cs b/Assets/Scripts/Slimecing/Dependency/Ellipse.cs @@ -21,5 +21,14 @@ namespace Slimecing.Dependency return new Vector2(x, y); } + + public Vector2 EvaluateEllipse(float prog, float xAxis, float yAxis) + { + float angle = Mathf.Deg2Rad * 360f * prog; + float x = Mathf.Sin(angle) * xAxis; + float y = Mathf.Cos(angle) * yAxis; + + return new Vector2(x, y); + } } } diff --git a/Assets/Scripts/Slimecing/Swords/DropBehaviour/DropBehaviours/RigidbodyDropLogic.cs b/Assets/Scripts/Slimecing/Swords/DropBehaviour/DropBehaviours/RigidbodyDropLogic.cs @@ -18,6 +18,8 @@ namespace Slimecing.Swords.DropBehaviour.DropBehaviours rigidbody.useGravity = true; } + rigidbody.constraints = RigidbodyConstraints.None; + rigidbody.velocity = Vector3.zero; } } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/IOrbitalTickEveryFrame.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/IOrbitalTickEveryFrame.cs @@ -4,6 +4,6 @@ namespace Slimecing.Swords.Orbitals { public interface IOrbitalTickEveryFrame { - void TickUpdate(GameObject owner, GameObject orbital); + void TickUpdate(Orbital orbital); } } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/Orbital.cs diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogic.cs @@ -1,15 +1,16 @@ -using UnityEngine; +using System; +using UnityEngine; namespace Slimecing.Swords.Orbitals { public abstract class OrbitalLogic : ScriptableObject { - [SerializeField] private OrbitalStats orbitalStats; - public OrbitalStats currentOrbitalStats => orbitalStats; - - public abstract void Initialize(GameObject owner, GameObject orbital); - - public abstract void Tick(GameObject owner, GameObject orbital); + public virtual OrbitalLogic GetOrbital() + { + return this; + } + public abstract void Initialize(Orbital orbital); + public abstract void Tick(Orbital orbital); } } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs @@ -2,6 +2,7 @@ using Slimecing.Dependency; using Slimecing.Triggers; using UnityEngine; +using UnityEngine.InputSystem; namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts { @@ -9,48 +10,38 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts public class InputOrbitalLogic : OrbitalLogic, IOrbitalTickEveryFrame { [SerializeField] private Trigger orbitalInputTrigger; - + private Trigger _operatingOrbitalInputTrigger; - private Ellipse _swordEllipse; - private Vector2 _finalSwordTarget; - - private void OnEnable() - { - _swordEllipse = new Ellipse(currentOrbitalStats.radiusX, currentOrbitalStats.radiusY); - _operatingOrbitalInputTrigger = Instantiate(orbitalInputTrigger); - } - - private TriggerInput GetInputAbilityActionType() + + public override OrbitalLogic GetOrbital() { - if (_operatingOrbitalInputTrigger == null) return null; - return _operatingOrbitalInputTrigger as TriggerInput; + return Instantiate(this); } - - public override void Initialize(GameObject owner, GameObject orbital) + + public override void Initialize(Orbital orbital) { - _swordEllipse = new Ellipse(currentOrbitalStats.radiusX, currentOrbitalStats.radiusY); _operatingOrbitalInputTrigger = Instantiate(orbitalInputTrigger); - GetInput(owner, orbital, Vector2.up); - GetInputAbilityActionType()?.ConfigureInput(owner); + GetInput(orbital, Vector2.up); + _operatingOrbitalInputTrigger.EnableTrigger(orbital.ownerObject); } - public override void Tick(GameObject owner, GameObject orbital) + public override void Tick(Orbital orbital) { - Vector3 center = owner.transform.position; + Vector3 center = orbital.ownerObject.transform.position; - float step = Time.fixedDeltaTime * currentOrbitalStats.rotationSpeed; - Vector2 circlePos = _swordEllipse.EvaluateEllipse(_finalSwordTarget.x); - Vector3 targetPos = new Vector3(circlePos.x, currentOrbitalStats.verticalOffset, circlePos.y); - Vector3 smoothPos = Vector3.RotateTowards(orbital.transform.position - center, targetPos, - step, 0f); - Vector3 orbitPos = new Vector3(smoothPos.normalized.x * currentOrbitalStats.radiusX, - currentOrbitalStats.verticalOffset, smoothPos.normalized.z * currentOrbitalStats.radiusY); - if (orbitPos != orbital.transform.position) + float step = Time.fixedDeltaTime * orbital.rotationSpeed; + Vector2 circlePos = orbital.orbitPath.EvaluateEllipse(orbital.orbitalProgress, orbital.radiusX, orbital.radiusY); + Vector3 targetPos = new Vector3(circlePos.x, orbital.verticalOffset, circlePos.y); + Vector3 smoothPos = Vector3.RotateTowards(orbital.orbitalObject.transform.position - center, + targetPos,step, 0f); + Vector3 orbitPos = new Vector3(smoothPos.normalized.x * orbital.radiusX, + orbital.verticalOffset, smoothPos.normalized.z * orbital.radiusY); + if (orbitPos != orbital.orbitalObject.transform.position) { - orbital.transform.position = orbitPos + center; + orbital.orbitalObject.transform.position = orbitPos + center; } - SetLook(owner, orbital); + SetLook(orbital.ownerObject, orbital.orbitalObject); } private static void SetLook(GameObject owner, GameObject orbital) @@ -60,36 +51,34 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts orbital.transform.LookAt(2 * position - new Vector3(ownerPos.x, position.y, ownerPos.z)); } - private void GetInput(GameObject owner, GameObject orbital, Vector2 inputDir) + private void GetInput(Orbital orbital, Vector2 inputDir) { if (inputDir.Equals(Vector2.zero)) return; if (!(Mathf.Abs(inputDir.x) > 0.05f) && !(Mathf.Abs(inputDir.y) > 0.05f)) return; - Vector3 center = owner.transform.position; + Vector3 center = orbital.ownerObject.transform.position; float angle = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg; - var position = orbital.transform.position; - float currentAngle = Mathf.Atan2(position.x - center.x,position.z - center.z) * Mathf.Rad2Deg; - _finalSwordTarget = new Vector2(angle / 360f, currentAngle / 360f); + orbital.orbitalProgress = angle / 360f; } - public void TickUpdate(GameObject owner, GameObject orbital) + public void TickUpdate(Orbital orbital) { - if (!_operatingOrbitalInputTrigger.currentTriggerState.Equals(TriggerState.Performed)) return; - if (!(_operatingOrbitalInputTrigger is TriggerInput orbitalTriggerInput)) return; - - if (orbitalTriggerInput.inputContext.control.device.name.Equals("Mouse")) + InputAction action = _operatingOrbitalInputTrigger.ReadCurrentValue<InputAction>(); + if (action == null) return; + if (!action.triggered) return; + if (action.activeControl.device.name.Equals("Mouse")) { if (UnityEngine.Camera.main != null) { - Plane playerPlane = new Plane(Vector3.up, owner.transform.position); - Vector2 readInput = orbitalTriggerInput.inputContext.ReadValue<Vector2>(); + Plane playerPlane = new Plane(Vector3.up, orbital.ownerObject.transform.position); + Vector2 readInput = action.ReadValue<Vector2>(); Ray ray = UnityEngine.Camera.main.ScreenPointToRay(readInput); if (!playerPlane.Raycast(ray, out var distance)) return; - Vector3 targetPoint = ray.GetPoint(distance) - owner.transform.position; - GetInput(owner, orbital, new Vector2(targetPoint.x, targetPoint.z)); + Vector3 targetPoint = ray.GetPoint(distance) - orbital.ownerObject.transform.position; + GetInput(orbital, new Vector2(targetPoint.x, targetPoint.z)); return; } } - GetInput(owner, orbital, orbitalTriggerInput.inputContext.ReadValue<Vector2>()); + GetInput(orbital, action.ReadValue<Vector2>()); } } } \ No newline at end of file diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs @@ -11,27 +11,20 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts public class TimerOrbitalLogic : OrbitalLogic, IOrbitalTickEveryFrame { [SerializeField] private bool randomProgress; - [SerializeField] private float orbitalProgress; + [SerializeField] private float startOrbitalProgress; - private Ellipse _orbitPath; - - private void OnEnable() - { - _orbitPath = new Ellipse(currentOrbitalStats.radiusX, currentOrbitalStats.radiusY); - } - - public override void Initialize(GameObject owner, GameObject orbital) + public override void Initialize(Orbital orbital) { - if (randomProgress) orbitalProgress = Random.Range(0.0f, 1.0f); - SetOrbitalPos(owner, orbital); + orbital.orbitalProgress = randomProgress ? Random.Range(0.0f, 1.0f) : startOrbitalProgress; + SetOrbitalPos(orbital); } - public override void Tick(GameObject owner, GameObject orbital) { } + public override void Tick(Orbital orbital) { } - private void SetOrbitalPos(GameObject owner, GameObject orbital) + private void SetOrbitalPos(Orbital orbital) { - Vector2 orbitPos = _orbitPath.EvaluateEllipse(orbitalProgress); - Vector3 pos = new Vector3(orbitPos.x, currentOrbitalStats.verticalOffset, orbitPos.y); - orbital.transform.position = pos + owner.transform.position; + Vector2 orbitPos = orbital.orbitPath.EvaluateEllipse(orbital.orbitalProgress, orbital.radiusX, orbital.radiusY); + Vector3 pos = new Vector3(orbitPos.x, orbital.verticalOffset, orbitPos.y); + orbital.orbitalObject.transform.position = pos + orbital.ownerObject.transform.position; } private static void SetLook(GameObject owner, GameObject orbital) @@ -41,22 +34,22 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts orbital.transform.LookAt(2 * position - new Vector3(ownerPos.x, position.y, ownerPos.z)); } - private void Rotate(GameObject owner, GameObject orbital) + private void Rotate(Orbital orbital) { - float orbitSpeed = 1f / currentOrbitalStats.rotationSpeed; - orbitalProgress += Time.deltaTime * orbitSpeed; - orbitalProgress %= 1f; - SetOrbitalPos(owner, orbital); + float orbitSpeed = 1f / orbital.rotationSpeed; + orbital.orbitalProgress += Time.deltaTime * orbitSpeed; + orbital.orbitalProgress %= 1f; + SetOrbitalPos(orbital); } - public void TickUpdate(GameObject owner, GameObject orbital) + public void TickUpdate(Orbital orbital) { - if (Mathf.Abs(currentOrbitalStats.rotationSpeed) < 0.1) + if (Mathf.Abs(orbital.rotationSpeed) < 0.1) { - currentOrbitalStats.rotationSpeed = 0.1f; + orbital.rotationSpeed = 0.1f; } - Rotate(owner, orbital); - SetLook(owner, orbital); + Rotate(orbital); + SetLook(orbital.ownerObject, orbital.orbitalObject); } } } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs.meta @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9a7d83bd9d2ec714ca732a376bb878d6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalStats.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalStats.cs @@ -1,37 +0,0 @@ -using UnityEngine; - -namespace Slimecing.Swords.Orbitals -{ - [CreateAssetMenu(fileName = "OrbitalStats", menuName = "Swords/Orbitals/OrbitalStats")] - public class OrbitalStats : ScriptableObject - { - [SerializeField] private float orbitalSpeed; - [SerializeField] private float yOffset; - [SerializeField] private float xAxis = 5f; - [SerializeField] private float yAxis = 5f; - - 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; - } - } -} diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalStats.cs.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalStats.cs.meta @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0a37f7d239ec14245970c23702857274 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset @@ -12,6 +12,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5d7968acda84baa4fa1a7008b6f01265, type: 3} m_Name: InputOrbitalLogic m_EditorClassIdentifier: - orbitalStats: {fileID: 11400000, guid: 40ca913627790f546a70a7cc2f14ac69, type: 2} orbitalInputTrigger: {fileID: 11400000, guid: 8e538a3d690d3d446aaf393f3d8319f3, type: 2} diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats.meta @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 2062c57f5369f8a4e885d890288f80be -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/InputOrbitalStats.asset b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/InputOrbitalStats.asset @@ -1,18 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0a37f7d239ec14245970c23702857274, type: 3} - m_Name: InputOrbitalStats - m_EditorClassIdentifier: - orbitalSpeed: 20 - yOffset: 1 - xAxis: 2.5 - yAxis: 2.5 diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/InputOrbitalStats.asset.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/InputOrbitalStats.asset.meta @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 40ca913627790f546a70a7cc2f14ac69 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/TimerOrbitalStats.asset b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/TimerOrbitalStats.asset @@ -1,18 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0a37f7d239ec14245970c23702857274, type: 3} - m_Name: TimerOrbitalStats - m_EditorClassIdentifier: - orbitalSpeed: 4 - yOffset: 1 - xAxis: 2.2 - yAxis: 2.2 diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/TimerOrbitalStats.asset.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalStats/TimerOrbitalStats.asset.meta @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ca7798574e6d9ea4aaf5df7ed0081254 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/TakesOrbitals.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/TakesOrbitals.cs @@ -1,37 +1,28 @@ using System; +using System.Collections; using System.Collections.Generic; -using Slimecing.Swords.DropBehaviour; -using Slimecing.Swords.Orbitals.OrbitalLogicScripts; -using Slimecing.Triggers; +using System.Linq; using UnityEngine; namespace Slimecing.Swords.Orbitals { public class TakesOrbitals : MonoBehaviour { - [SerializeField] private OrbitalLogic defaultOrbitalLogic; - [SerializeField] private List<OrbitalPackage> orbitals; - - private Collider _collider; - - private List<GameObject> _spawnedOrbitalObjects = new List<GameObject>(); - private List<OrbitalLogic> _spawnedOrbitalLogic = new List<OrbitalLogic>(); + [SerializeField] private List<Orbital> orbitals; private void OnEnable() { - _collider = GetComponent<Collider>(); SpawnAllOrbitals(); } private void SpawnAllOrbitals() { var thisTransform = transform; - for (int i = 0; i < orbitals.Count; i++) + foreach (var orbital in orbitals) { - GameObject spawnedOrbital = Instantiate(orbitals[i].orbitalObject, thisTransform.position, + orbital.orbitalObject = Instantiate(orbital.orbitalObject, thisTransform.position, Quaternion.identity); - orbitals[i] = new OrbitalPackage(spawnedOrbital, orbitals[i].currentOrbitalLogic); - InitializeOrbital(orbitals[i]); + InitializeCurrentOrbital(orbital); } } @@ -48,59 +39,30 @@ namespace Slimecing.Swords.Orbitals } } - private void InitializeOrbital(OrbitalPackage orbital) - { - AddCollisions(orbital.orbitalObject); - orbital.currentOrbitalLogic = Instantiate(orbital.currentOrbitalLogic); - orbital.currentOrbitalLogic.Initialize(gameObject, orbital.orbitalObject); - ResetSpawnedOrbitalObjects(); - } - - private void ResetSpawnedOrbitalObjects() + private void InitializeCurrentOrbital(Orbital orbital) { - _spawnedOrbitalObjects = new List<GameObject>(); - _spawnedOrbitalLogic = new List<OrbitalLogic>(); - foreach (var t in orbitals) - { - _spawnedOrbitalObjects.Add(t.orbitalObject); - _spawnedOrbitalLogic.Add(t.currentOrbitalLogic); - } + orbital.Initialize(); + SetCollisions(orbital); } - public void AddOrbital(GameObject orbital, OrbitalLogic orbitalLogic, bool stick) + private void ActuallyAddOrbital(Orbital orbital) { - ActuallyAddOrbital(new OrbitalPackage(orbital, orbitalLogic, stick)); + InitializeCurrentOrbital(orbital); + orbitals.Add(orbital); } - public void AddOrbital(GameObject orbital, bool stick) + private void SetCollisions(Orbital orbital) { - ActuallyAddOrbital(new OrbitalPackage(orbital, defaultOrbitalLogic, stick)); - } - - private void ActuallyAddOrbital(OrbitalPackage orbitalPackage) - { - InitializeOrbital(orbitalPackage); - orbitals.Add(orbitalPackage); - } - - private void AddCollisions(GameObject orbital) - { - Collider orbitalCollider = orbital.GetComponent<Collider>(); - if (_collider != null && orbitalCollider != null) + foreach (var orbitalCollider in orbitals.Select(o => + o.orbitalObject.GetComponent<Collider>()).Where(orbitalCollider => orbitalCollider != null)) { - Physics.IgnoreCollision(_collider, orbitalCollider); - foreach (var spawnedOrbital in orbitals) - { - Collider spawnedOrbitalCollider = spawnedOrbital.orbitalObject.GetComponent<Collider>(); - if (spawnedOrbitalCollider == null) continue; - Physics.IgnoreCollision(orbitalCollider, spawnedOrbitalCollider); - } + orbital.SetIgnoreCollisions(orbitalCollider); } } - private void RemoveOrbital(OrbitalPackage orbital) + private void RemoveOrbital(Orbital orbital) { - DropOrbital(orbital.orbitalObject); + orbital.DisableOrbital(); orbitals.Remove(orbital); } @@ -108,64 +70,21 @@ namespace Slimecing.Swords.Orbitals { foreach (var orbital in orbitals) { - if (orbital.currentOrbitalLogic is IOrbitalTickEveryFrame inputOrbitalLogic) - { - inputOrbitalLogic.TickUpdate(gameObject, orbital.orbitalObject); - } + orbital.UpdateTick(); } } public void FixedUpdate() { - ValidateOrbitals(); - foreach (var orbital in orbitals) { - orbital.currentOrbitalLogic.Tick(gameObject, orbital.orbitalObject); + orbital.Tick(); } - } - - private void ValidateOrbitals() - { - float loopCount = _spawnedOrbitalObjects.Count; - bool resetLoop = false; - if (orbitals.Count != _spawnedOrbitalObjects.Count) - { - resetLoop = true; - if (orbitals.Count < _spawnedOrbitalObjects.Count) - { - loopCount = orbitals.Count; - } - } - - for (int i = 0; i < loopCount; i++) - { - if (orbitals[i] == null) - { - orbitals.Remove(orbitals[i]); - } - if (orbitals[i].orbitalObject == _spawnedOrbitalObjects[i] && orbitals[i].currentOrbitalLogic == _spawnedOrbitalLogic[i]) continue; - //DropOrbital(_spawnedOrbitalObjects[i]); - InitializeOrbital(orbitals[i]); - } - - if (resetLoop) + foreach (var orbital in orbitals.Where(orbital => !orbital.Validate())) { - ResetSpawnedOrbitalObjects(); + SetCollisions(orbital); } } - - private void DropOrbital(GameObject orbital) - { - DropLogic dropLogic = orbital.GetComponent<DropLogic>(); - if (dropLogic == null) - { - orbital.SetActive(false); - return; - } - - dropLogic.Drop(); - } } } \ No newline at end of file diff --git a/Assets/Scripts/Slimecing/Triggers/SimpleTrigger.cs b/Assets/Scripts/Slimecing/Triggers/SimpleTrigger.cs @@ -1,10 +0,0 @@ -using UnityEngine; - -namespace Slimecing.Triggers -{ - public abstract class SimpleTrigger : Trigger - { - public abstract void InitializeTrigger(GameObject target); - protected abstract void TriggerPerformed(GameObject target); - } -} diff --git a/Assets/Scripts/Slimecing/Triggers/SimpleTrigger.cs.meta b/Assets/Scripts/Slimecing/Triggers/SimpleTrigger.cs.meta @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 107c17fc89417ce438df6293b59d2e78 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Triggers/Trigger.cs b/Assets/Scripts/Slimecing/Triggers/Trigger.cs @@ -3,12 +3,23 @@ using UnityEngine; namespace Slimecing.Triggers { - public class Trigger : ScriptableObject + public abstract class Trigger : ScriptableObject { public TriggerState currentTriggerState { get; set; } public event Action<TriggerPackage> TriggerStateChange; + public abstract void EnableTrigger(GameObject target); + protected static T CheckRequestedValue<T>(object obj) + { + var result = default(T); + if (obj is T) + { + result = (T) Convert.ChangeType(obj, typeof(T)); + } + return result; + } + public virtual T ReadCurrentValue<T>() => CheckRequestedValue<T>(currentTriggerState); protected virtual void OnTriggerStateChange(TriggerPackage itp) { TriggerStateChange?.Invoke(itp); diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerInput.cs b/Assets/Scripts/Slimecing/Triggers/TriggerInput.cs @@ -11,19 +11,19 @@ namespace Slimecing.Triggers public InputActionReference currentActionReference { get => inputActionReference; set => inputActionReference = value; } - public PlayerInput currentPlayerInput { get; set; } + public PlayerInput currentPlayerInput { get; private set; } - public void ConfigureInput(GameObject player) + public override void EnableTrigger(GameObject target) { - currentPlayerInput = player.GetComponent<PlayerInput>(); + currentPlayerInput = target.GetComponent<PlayerInput>(); if (currentPlayerInput == null) return; foreach (var action in currentPlayerInput.actions) { if (!currentActionReference.action.name.Equals(action.name)) continue; - action.started += ctx => TriggerStarted(player, ctx); - action.performed += ctx => TriggerPerformed(player, ctx); - action.canceled += ctx => TriggerCanceled(player, ctx); + action.started += ctx => TriggerStarted(target, ctx); + action.performed += ctx => TriggerPerformed(target, ctx); + action.canceled += ctx => TriggerCanceled(target, ctx); action.Enable(); } } @@ -40,5 +40,6 @@ namespace Slimecing.Triggers protected abstract void TriggerStarted(GameObject player, InputAction.CallbackContext ctx); protected abstract void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx); protected abstract void TriggerCanceled(GameObject player,InputAction.CallbackContext ctx); + } } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs.meta b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs.meta @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b724fbf88219cb4459211c90795c6464 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/InputTriggerPolling.cs diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/TimerTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/TimerTrigger.cs @@ -5,7 +5,7 @@ using UnityEngine.Serialization; namespace Slimecing.Triggers.TriggerLogic { [CreateAssetMenu(fileName = "TimerTrigger", menuName = "Triggers/SimpleTriggers/TimerTrigger")] - public class TimerTrigger : SimpleTrigger + public class TimerTrigger : Trigger { [SerializeField] private float timerDuration = 0.1f; [SerializeField] private int timerLoops = 0; @@ -29,14 +29,14 @@ namespace Slimecing.Triggers.TriggerLogic get => timerLoops; set => timerLoops = value; } - - public override void InitializeTrigger(GameObject target) + + public override void EnableTrigger(GameObject target) { _timer = new Timer(duration, loops); _timer.OnTimerEnd += ctx => TriggerPerformed(target); } - - protected override void TriggerPerformed(GameObject target) + + private void TriggerPerformed(GameObject target) { currentTriggerState = TriggerState.Performed; OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, target)); diff --git a/Assets/_Scenes/Testing/SLope.unity b/Assets/_Scenes/Testing/SLope.unity @@ -2835,12 +2835,18 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6f7780a3c04e17841825f68a82642af4, type: 3} m_Name: m_EditorClassIdentifier: - defaultOrbitalLogic: {fileID: 11400000, guid: f604a09f73d9b3e4a8d515810e94c6d9, - type: 2} orbitals: - - orbital: {fileID: 621488908} + - owner: {fileID: 1383329372} + orbital: {fileID: 621488908} orbitalLogic: {fileID: 11400000, guid: f604a09f73d9b3e4a8d515810e94c6d9, type: 2} + orbitalSpeed: 10 + yOffset: 1 + xAxis: 3 + yAxis: 3 sticky: 0 + dropLayer: + serializedVersion: 2 + m_Bits: 1 --- !u!1 &1384512436 GameObject: m_ObjectHideFlags: 0