commit 81c5ef34681243fa045a294b4bbdd5ac6a0bce3c parent a44a99066ca3aad65eb410a5a336581a71319125 Author: PlutoTank <qwolkensperg@gmail.com> Date: Thu, 16 Apr 2020 03:03:56 -0400 Added Orbitals Diffstat:
14 files changed, 235 insertions(+), 48 deletions(-)
diff --git a/Assets/Scripts/Slimecing/Dependency/Ellipse.cs b/Assets/Scripts/Slimecing/Dependency/Ellipse.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace Slimecing.Dependency +{ + public class Ellipse + { + private readonly float _xAxis; + private readonly float _yAxis; + + public Ellipse(float xAxis, float yAxis) + { + _xAxis = xAxis; + _yAxis = yAxis; + } + + public Vector2 EvaluateEllipse(float pos) + { + float angle = Mathf.Deg2Rad * 360f * pos; + float x = Mathf.Sin(angle) * _xAxis; + float y = Mathf.Cos(angle) * _yAxis; + + return new Vector2(x, y); + } + } +} diff --git a/Assets/Scripts/Slimecing/Dependency/Ellipse.cs.meta b/Assets/Scripts/Slimecing/Dependency/Ellipse.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 300ce6bbb856b7d42ae3cb106e1dbbec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/SimpleComponents/TimerBehaviour.cs b/Assets/Scripts/Slimecing/SimpleComponents/TimerBehaviour.cs @@ -1,46 +0,0 @@ -using System; -using Slimecing.Dependency; -using UnityEngine; -using UnityEngine.Events; - -namespace Slimecing.SimpleComponents -{ - public class TimerBehaviour : MonoBehaviour - { - [SerializeField] private float durationOfTick = 1f; - [SerializeField] private float loopFor = 0f; - [SerializeField] private bool loopInfinite = false; - [SerializeField] private UnityEvent onTimerEnd = null; - - private Timer _timer; - - private Timer Timer - { - get - { - if (_timer != null) - { - return _timer; - } - //_timer = new Timer(durationOfTick, loopFor, loopInfinite); - return _timer; - } - } - - private void Start() - { - Timer.OnTimerEnd += WhenTimerEnd; - } - - private void Update() - { - Timer.Tick(Time.deltaTime); - } - - private void WhenTimerEnd() - { - onTimerEnd.Invoke(); - } - - } -} diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs @@ -0,0 +1,60 @@ +using System; +using Slimecing.Dependency; +using Slimecing.Triggers; +using Slimecing.Triggers.TriggerLogic; +using UnityEngine; +using Random = UnityEngine.Random; + +namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts +{ + [CreateAssetMenu(fileName = "TimerOrbitalLogic", menuName = "Swords/Orbitals/OrbitalLogic/TimerOrbitalLogic")] + public class TimerOrbitalLogic : OrbitalLogic + { + [SerializeField] private bool randomProgress; + [SerializeField] private float orbitalProgress; + + private Ellipse _orbitPath; + + private void OnEnable() + { + _orbitPath = new Ellipse(XAxis, ZAxis); + } + + public override void Initialize(GameObject owner, GameObject orbital) + { + if (randomProgress) orbitalProgress = Random.Range(0.0f, 1.0f); + SetOrbitalPos(owner, orbital); + } + public override void Tick(GameObject owner, GameObject orbital) + { + if (Mathf.Abs(RotSpeed) < 0.1) + { + RotSpeed = 0.1f; + } + Rotate(owner, orbital); + SetLook(owner, orbital); + } + + private void SetOrbitalPos(GameObject owner, GameObject orbital) + { + Vector2 orbitPos = _orbitPath.EvaluateEllipse(orbitalProgress); + Vector3 pos = new Vector3(orbitPos.x, YOffset, orbitPos.y); + orbital.transform.position = pos + owner.transform.position; + } + + private void SetLook(GameObject owner, GameObject orbital) + { + Vector3 position = orbital.transform.position; + Vector3 ownerPos = owner.transform.position; + orbital.transform.LookAt(2 * position - new Vector3(ownerPos.x, position.y, ownerPos.z)); + } + + private void Rotate(GameObject owner, GameObject orbital) + { + float orbitSpeed = 1f / RotSpeed; + orbitalProgress += Time.deltaTime * orbitSpeed; + orbitalProgress %= 1f; + SetOrbitalPos(owner, orbital); + } + } +} diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a01e1cbc5c4e6e7418ba67b90bf0fce4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalPackage.cs @@ -0,0 +1,46 @@ +using System; +using UnityEngine; + +namespace Slimecing.Swords.Orbitals +{ + [Serializable] + public class OrbitalPackage + { + + [SerializeField] private GameObject orbital; + [SerializeField] private OrbitalLogic orbitalLogic; + [SerializeField] private bool sticky; + + public bool orbitalSticky + { + get => sticky; + set => sticky = value; + } + + public OrbitalPackage(GameObject orbital, OrbitalLogic orbitalLogic) + { + 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; + } + + public GameObject orbitalObject + { + get => orbital; + set => orbital = value; + } + + public OrbitalLogic OrbitalLogic + { + get => orbitalLogic; + set => orbitalLogic = value; + } + } +} diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 165ad3f9f5efb464c851cefac26a9a2e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/TimerOrbitalLogic.asset b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/TimerOrbitalLogic.asset @@ -0,0 +1,20 @@ +%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: a01e1cbc5c4e6e7418ba67b90bf0fce4, type: 3} + m_Name: TimerOrbitalLogic + m_EditorClassIdentifier: + rotSpeed: 4 + yOffset: 1 + xAxis: 2.2 + zAxis: 2.2 + randomProgress: 1 + orbitalProgress: 0.83612007 diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/TimerOrbitalLogic.asset.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/TimerOrbitalLogic.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f604a09f73d9b3e4a8d515810e94c6d9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Triggers/SOTrigger/TimerTrigger.asset b/Assets/Scripts/Slimecing/Triggers/SOTrigger/TimerTrigger.asset @@ -0,0 +1,15 @@ +%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: 4495a47862cdaf1458d2815b5afe89b9, type: 3} + m_Name: TimerTrigger + m_EditorClassIdentifier: + duration: 0.1 diff --git a/Assets/Scripts/Slimecing/Triggers/SOTrigger/TimerTrigger.asset.meta b/Assets/Scripts/Slimecing/Triggers/SOTrigger/TimerTrigger.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 98b5ad532e3b1ce43ba2ab5d9fafb06f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Triggers/SimpleTrigger.cs b/Assets/Scripts/Slimecing/Triggers/SimpleTrigger.cs @@ -0,0 +1,10 @@ +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/TriggerPackage.cs b/Assets/Scripts/Slimecing/Triggers/TriggerPackage.cs @@ -2,12 +2,12 @@ namespace Slimecing.Triggers { - public struct InputTriggerPackage + public struct TriggerPackage { public TriggerState triggerState { get; set; } public GameObject user { get; set; } - public InputTriggerPackage(TriggerState triggerState, GameObject user) + public TriggerPackage(TriggerState triggerState, GameObject user) { this.triggerState = triggerState; this.user = user; diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerPackage.cs.meta b/Assets/Scripts/Slimecing/Triggers/TriggerPackage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7ccb55568d3d58f4ca5ad86a2724e932 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: