ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [게임엔진활용] 7강 게임 시스템 구성
    [DSU] 게임엔진활용 2026. 6. 8. 00:45
    728x90

    기존 방식 (Hierachy > 우클릭 Create Empty > RenderView 명명 > Add Component : RenderView.cs) 에서,

    RenderView클래스를 상속받은 새로운 클래스에서 load / free / draw / mouse로 직관적으로 코드를 작성할 수 있도록 수정.

    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    public class RenderView : MonoBehaviour
    {
        public virtual void load() { }
        public virtual void free() { }
        public virtual void draw(float dt) { }
        public virtual void mouse(int state, float x, float y) { }
     
        public MainCamera mc;
     
        void Start()
        {
            mc = FindFirstObjectByType<MainCamera>();
            ...
     
            load();
            MainCamera.methodMouse = mouse;        
        }
     
        ~RenderView()
        {
            free();
        }
     
        void OnGUI()
        {
            if (Event.current.type != EventType.Repaint)
                return;
     
            ...
     
            GL.Clear(truetrue, Color.clear);
            draw(Time.deltaTime);// do something ...
     
            ...
        }
    }
     
    public class MainCamera : MonoBehaviour
    {
        void Start()
        {
            ...
            setGame("GameScene");// GameScene / GameCollision / GamePS / GameCombo
        }
        static GameObject rv = null;
        public static void setGame(string nameScene)
        {
            GameObject go = new GameObject(nameScene);
            System.Type t = System.Type.GetType(nameScene);
            go.AddComponent(t);
     
            if (rv != null)
            {
                GameObject.Destroy(rv);
                Resources.UnloadUnusedAssets();
            }
            rv = go;
        }
        public delegate void MethodMouse(int state, float x, float y);
        public static MethodMouse methodMouse = null;
    }
     
     
    cs

     

     

    메인 카메라에서 setGame("GameScene"); 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
    public class GameScene : RenderView
    {
        public override void load()
        {
            // 리소스 로딩
        }
     
        public override void free()
        {
            // 리소스 해제
        }
     
        public override void draw(float dt)
        {
            // 그리기
            // 키보드 제어
        }
     
        public override void mouse(int state, float x, float y)
        {
            // 마우스 제
        }
    }
     
    cs

     

    매일매일 열심히 게임 개발하고 있습니다

Designed by Tistory.