Skip to content

Commit

Permalink
chore: Class hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
jihu0331 committed Nov 12, 2024
1 parent d8bbd78 commit 33ef713
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Assets/SWPPT3/Scripts/Main/Prop/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SWPPT3.Main.Prop
{
public class Door : StateDst
{
protected override void OnSourceStateChanged(bool state)
protected override void OnSourceStateChanged(StateSource src, bool state)
{
//움직임을 어떻게 정의할지

Expand Down
2 changes: 1 addition & 1 deletion Assets/SWPPT3/Scripts/Main/Prop/ElectricWire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void Start()
}
}

protected override void OnSourceStateChanged(bool state)
protected override void OnSourceStateChanged(StateSource src, bool state)
{
if (_objectMaterial != null)
{
Expand Down
2 changes: 0 additions & 2 deletions Assets/SWPPT3/Scripts/Main/Prop/FloorButton.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace SWPPT3.Main.Prop
Expand Down
34 changes: 30 additions & 4 deletions Assets/SWPPT3/Scripts/Main/Prop/MagicCircle.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace SWPPT3.Main.Prop
{
public class MagicCircle : StateDst
{
[SerializeField]
private int stateChangeAmount;
protected override void OnSourceStateChanged(bool state)

private int _progress = 0;
private Dictionary<StateSource, bool> circleStates;

public void Awake()
{
if (this.State == On)
circleStates = new Dictionary<StateSource, bool>();
StateSource[] sources = GetComponentsInChildren<StateSource>();
foreach (var source in sources)
{

circleStates[source] = false;
}
else if (this.State == Off)
}

protected override void OnSourceStateChanged(StateSource src, bool state)
{
circleStates[src] = state;
_progress = 0;
foreach (bool circleState in circleStates.Values)
{
if(circleState) _progress ++;
}

if (_progress >= circleStates.Count)
{
ActivateMagicCircle();
State = On;
}
}

private void ActivateMagicCircle()
{
Debug.Log("Magic Circle Activated");
}
}
}
16 changes: 12 additions & 4 deletions Assets/SWPPT3/Scripts/Main/Prop/StateDst.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace SWPPT3.Main.Prop
{
public abstract class StateDst : StatefulProp
{
[SerializeField]
private StateSource stateSource;
private List<StateSource> stateSources;
private void OnEnable()
{
stateSource.OnStateChanged += OnSourceStateChanged;
foreach (StateSource stateSource in stateSources)
{
stateSource.OnStateChanged += OnSourceStateChanged;
}

}
private void OnDisable()
{
stateSource.OnStateChanged -= OnSourceStateChanged;
foreach (StateSource stateSource in stateSources)
{
stateSource.OnStateChanged -= OnSourceStateChanged;
}
}
protected abstract void OnSourceStateChanged(bool state);
protected abstract void OnSourceStateChanged(StateSource src, bool state);

}
}
4 changes: 2 additions & 2 deletions Assets/SWPPT3/Scripts/Main/Prop/StateSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SWPPT3.Main.Prop
{
public abstract class StateSource: StatefulProp
{
public event Action<bool> OnStateChanged;
public event Action<StateSource,bool> OnStateChanged;
public override bool State
{
get => PropState;
Expand All @@ -13,7 +13,7 @@ public override bool State
if (PropState != value)
{
PropState = value;
OnStateChanged?.Invoke(PropState);
OnStateChanged?.Invoke(this,PropState);
}
}
}
Expand Down

0 comments on commit 33ef713

Please sign in to comment.