싱글톤 패턴
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class GameManager : MonoBehaviour
   public static GameManager Instance { get; private set; } 
   private void Awake() 
   { 
      if (Instance == null
      { 
         Instance = this
         DontDestroyOnLoad(gameObject); 
      } else { 
         Destroy(gameObject); 
      } 
   } 
}  
cs


옵저버 패턴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public interface IObserver 
   void OnNotify(); 
public class Subject : MonoBehaviour 
   private List<IObserver> _observers = new List<IObserver>(); 
 
   public void RegistObserver(IObserver observer) 
   { 
      _observers.Add(observer); 
   } 
 
   public void UnregistObserver(IObserver observer) 
   { 
      _observers.Remove(observer); 
   } 
 
   public void NotifyObservers() 
   { 
      foreach (IObserver observer in _observers) 
      { 
         observer.OnNotify(); 
      } 
   } 
cs
레지스터가 디시 금칙어라 레지스트라고 바꿈




커맨드 패턴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public interface ICommand
{
    void Execute();
    void Undo();
}
 
 
public class JumpCommand : ICommand
{
    private Player _player;
    private float _jumpForce;
 
 
    public JumpCommand(Player player, float jumpForce)
    {
        _player = player;
        _jumpForce = jumpForce;
    }
 
 
    public void Execute()
    {
        _player.Jump(_jumpForce);
    }
 
 
    public void Undo()
    {
        _player.ResetPosition();
    }
}
cs


스트래티지 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public interface IMovementStrategy
{
    void Move(Character character);
}
 
 
public class WalkMovement : IMovementStrategy
{
    public void Move(Character character)
    {
        // Walk movement logic
    }
}
 
 
public class FlyMovement : IMovementStrategy
{
    public void Move(Character character)
    {
        // Fly movement logic
    }
}
 
 
public class Character : MonoBehaviour
{
    private IMovementStrategy _movementStrategy;
 
 
    public void SetMovementStrategy(IMovementStrategy strategy)
    {
        _movementStrategy = strategy;
    }
 
 
    private void Update()
    {
        _movementStrategy.Move(this);
    }
}
 
cs