Commit 1594787d authored by Sebastian Frey's avatar Sebastian Frey
Browse files

GameEvent sind jetzt cooler und heißen ElementGameEvents

parent 8356d4ea
fileFormatVersion: 2
guid: 83b2ccd8caab22846876189bc6815151
guid: d08078c315d7ac545834bfee9dc018a5
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
......@@ -9,6 +9,6 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ea24d0e4eff9b514184d2081be52c833, type: 3}
m_Name: OnFireInfused
m_Script: {fileID: 11500000, guid: 9c49b9c852d102f46917ed068a87a1df, type: 3}
m_Name: InfusedElementGameEvent
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: ca31b08da78cb134086d7688bbb50628
guid: 7e5b80a8353af1846a878c3a997bdb4a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
......
%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: ea24d0e4eff9b514184d2081be52c833, type: 3}
m_Name: OnAirInfused
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: b0928121a3619584c9612f68610a97a5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
%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: ea24d0e4eff9b514184d2081be52c833, type: 3}
m_Name: OnEarthInfused
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: 59d96edea2ecb434999c09413da7449a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f553df1a50d464e48837fbb6cb99b7e5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
%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: ea24d0e4eff9b514184d2081be52c833, type: 3}
m_Name: OnWaterInfused
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: 45dc3cd47d608cf449e822b512001707
guid: 5782222d4c9b9424ea96676650e643a8
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
......@@ -12,10 +12,7 @@ namespace _Game.Scripts.Player
[SerializeField] private PlayerState state;
[SerializeField] private GameEvent onAirInfused;
[SerializeField] private GameEvent onEarthInfused;
[SerializeField] private GameEvent onFireInfused;
[SerializeField] private GameEvent onWaterInfused;
[SerializeField] private ElementGameEvent onElementInfused;
private void Update()
{
......@@ -24,23 +21,24 @@ namespace _Game.Scripts.Player
switch (_currentObject.tag)
{
case "Air":
state.currentInfusedElement = InfusedElement.Air;
onAirInfused.Raise();
state.UpdateElement(InfusedElement.Air);
onElementInfused.Raise(InfusedElement.Air);
break;
case "Earth":
state.currentInfusedElement = InfusedElement.Earth;
onEarthInfused.Raise();
state.UpdateElement(InfusedElement.Earth);
onElementInfused.Raise(InfusedElement.Earth);
break;
case "Fire":
state.currentInfusedElement = InfusedElement.Fire;
onFireInfused.Raise();
state.UpdateElement(InfusedElement.Fire);
onElementInfused.Raise(InfusedElement.Fire);
break;
case "Water":
state.currentInfusedElement = InfusedElement.Water;
onWaterInfused.Raise();
state.UpdateElement(InfusedElement.Water);
onElementInfused.Raise(InfusedElement.Water);
break;
default:
state.currentInfusedElement = InfusedElement.None;
state.UpdateElement(InfusedElement.None);
onElementInfused.Raise(InfusedElement.None);
break;
}
_targetScript.InfuseElement();
......
......@@ -3,25 +3,25 @@ using UnityEngine;
namespace _Game.Scripts.Scriptable_Object
{
[CreateAssetMenu(fileName = "New Game Event", menuName = "Game Event", order = 52)]
public class GameEvent : ScriptableObject
[CreateAssetMenu(fileName = "New Element Game Event", menuName = "Element Game Event", order = 52)]
public class ElementGameEvent : ScriptableObject
{
private readonly List<GameEventListener> _listeners = new List<GameEventListener>();
private readonly List<ElementGameEventListener> _listeners = new List<ElementGameEventListener>();
public void Raise()
public void Raise(InfusedElement element)
{
for (var i = _listeners.Count - 1; i >= 0; i--)
{
_listeners[i].OnEventRaised();
_listeners[i].OnEventRaised(element);
}
}
public void RegisterListener(GameEventListener listener)
public void RegisterListener(ElementGameEventListener listener)
{
_listeners.Add(listener);
}
public void UnregisterListener(GameEventListener listener)
public void UnregisterListener(ElementGameEventListener listener)
{
_listeners.Remove(listener);
}
......
fileFormatVersion: 2
guid: ea24d0e4eff9b514184d2081be52c833
guid: 9c49b9c852d102f46917ed068a87a1df
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using System;
using UnityEngine;
using UnityEngine.Events;
namespace _Game.Scripts.Scriptable_Object
{
public class ElementGameEventListener : MonoBehaviour
{
[SerializeField] private ElementGameEvent gameEvent;
[SerializeField] private UnityEvent airResponse;
[SerializeField] private UnityEvent earthResponse;
[SerializeField] private UnityEvent fireResponse;
[SerializeField] private UnityEvent waterResponse;
[SerializeField] private UnityEvent defaultResponse;
private void OnEnable()
{
gameEvent.RegisterListener(this);
}
private void OnDisable()
{
gameEvent.UnregisterListener(this);
}
public void OnEventRaised(InfusedElement element)
{
switch (element)
{
case InfusedElement.Air:
airResponse.Invoke();
break;
case InfusedElement.Earth:
earthResponse.Invoke();
break;
case InfusedElement.Fire:
fireResponse.Invoke();
break;
case InfusedElement.Water:
waterResponse.Invoke();
break;
case InfusedElement.None:
defaultResponse.Invoke();
break;
default:
throw new ArgumentOutOfRangeException("element", element, null);
}
}
}
}
fileFormatVersion: 2
guid: fd036739fa0d41c459c107fb93ca47c4
guid: cd35dc826bb88514993730d585216e35
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
using UnityEngine.Events;
namespace _Game.Scripts.Scriptable_Object
{
public class GameEventListener : MonoBehaviour
{
[SerializeField]
private GameEvent gameEvent;
[SerializeField]
private UnityEvent response;
private void OnEnable()
{
gameEvent.RegisterListener(this);
}
private void OnDisable()
{
gameEvent.UnregisterListener(this);
}
public void OnEventRaised()
{
response.Invoke();
}
}
}
......@@ -9,7 +9,7 @@ namespace _Game.Scripts.Scriptable_Object
[CreateAssetMenu(fileName = "New Player State", menuName = "Player State", order = 51)]
public class PlayerState : ScriptableObject
{
[SerializeField] public InfusedElement currentInfusedElement;
[SerializeField] private InfusedElement currentInfusedElement;
[SerializeField] private MovementState currentMoveState;
......@@ -27,27 +27,32 @@ namespace _Game.Scripts.Scriptable_Object
[SerializeField] private float currentMass;
[SerializeField] private float currentGravity;
public void UpdateMoveState(InfusedElement newElement)
public void UpdateElement(InfusedElement newElement)
{
switch (newElement)
{
case InfusedElement.Air:
currentInfusedElement = InfusedElement.Air;
currentMoveState = airMoveState;
UpdateMovementState();
break;
case InfusedElement.Earth:
currentInfusedElement = InfusedElement.Earth;
currentMoveState = earthMoveState;
UpdateMovementState();
break;
case InfusedElement.Fire:
currentInfusedElement = InfusedElement.Fire;
currentMoveState = fireMoveState;
UpdateMovementState();
break;
case InfusedElement.Water:
currentInfusedElement = InfusedElement.Water;
currentMoveState = waterMoveState;
UpdateMovementState();
break;
case InfusedElement.None:
currentInfusedElement = InfusedElement.None;
currentMoveState = defaultMoveState;
UpdateMovementState();
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment