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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Player_Manager : MonoBehaviour
{
    private CUtility Utility = new CUtility();
 
    [SerializeField] private SpriteRenderer PlayerSprite;
 
    enum eAnimationType     { Idle, Run, Attack, End };
    [SerializeField] private eAnimationType m_eCurAnimType      = eAnimationType.Run;
    [SerializeField] private List<Sprite>[] AnimationSprite     = new List<Sprite>[(int)eAnimationType.End];
 
    public float m_fBaseSingleTime = 0.05f;
    [SerializeField] public ST_AnimFrame m_tFrame;
    public List<Sprite> temp;
    private void Start()
    {
        Initialize();
    }
 
    private void Update()
    {
        UpdateLogic();
    }
 
    /// <summary>
    /// 씬 시작 후 초기화
    /// </summary>
    private void Initialize()
    {
        m_tFrame.fSingleTime = 0.2f;
 
        for (int i = 0; i < (int)eAnimationType.End; ++i)
        {
            AnimationSprite[i] = new List<Sprite>();
        }
        ChangeCharacterImage("2.Image/Character Sprite");
    }
 
    /// <summary>
    /// 기본 주소를 넣어주면 모든 애니메이션 파일 세팅
    /// </summary>
    /// <param name="strSpritePath">애니메이션 파일이 있는 경로</param>
    private void ChangeCharacterImage(string strSpritePath)
    {
        for (int i = 0; i < (int)eAnimationType.End; ++i)
        {
            SettingAnimationSprite((eAnimationType)i, strSpritePath);
        }
    }
 
    /// <summary>
    /// AnimationSprite에 Multiple Sprite를 넣어준다.
    /// </summary>
    /// <param name="eType">애니메이션 타입</param>
    /// <param name="strFullPath">애니메이션 파일이 있는 경로</param>
    private void SettingAnimationSprite(eAnimationType eType, string strFullPath)
    {
        switch (eType)
        {
            case eAnimationType.Idle:
                strFullPath += "/Idle";
                break;
            case eAnimationType.Run:
                strFullPath += "/Run";
                break;
            case eAnimationType.Attack:
                strFullPath += "/Attack";
                break;
            default:
                Debug.Log("SettingAnimationSprite : switch Error");
                break;
        }
 
        AnimationSprite[(int)eType].Clear();
 
        Sprite[] AnimSprites = Utility.LoadSprites(strFullPath);
        foreach (var sprites in AnimSprites)
        {
            AnimationSprite[(int)eType].Add(sprites);
        }
 
        Debug.Log(AnimationSprite[(int)eType].Count);
    }
 
    /// <summary>
    /// 업데이트 로직
    /// </summary>
    private void UpdateLogic()
    {
        m_tFrame.fNowTime += 1.0f * Time.deltaTime;
 
        if (m_tFrame.fSingleTime <= m_tFrame.fNowTime)
        {
            m_tFrame.fNowTime = 0.0f;
 
            m_tFrame.iNowFrame += 1;
            if(m_tFrame.IsFrameFinished() || AnimationSprite[(int)m_eCurAnimType].Count <= m_tFrame.iNowFrame)
            {
                m_tFrame.iNowFrame = m_tFrame.iMinFrame;
 
                if(eAnimationType.Attack == m_eCurAnimType)
                {
                    m_eCurAnimType = eAnimationType.Run;
                    m_tFrame.Reset(0, AnimationSprite[(int)m_eCurAnimType].Count, m_fBaseSingleTime);
                }
            }
            PlayerSprite.sprite = AnimationSprite[(int)m_eCurAnimType][m_tFrame.iNowFrame];
        }
 
        Attack();
    }
 
    /// <summary>
    /// A키 : 공격 Animation 변경
    /// </summary>
    private void Attack()
    {
        if(Input.GetKeyDown(KeyCode.A) && eAnimationType.Attack != m_eCurAnimType)
        {
            m_eCurAnimType      = eAnimationType.Attack;
            m_tFrame.Reset(0, AnimationSprite[(int)m_eCurAnimType].Count, m_fBaseSingleTime);
        }
    }
}
 
cs


06bcdb27eae639aa658084e54483746f716919477921807cd590460b99e9687f930a9a7eca816b761ea4f610





간단하게 런닝게임 만들어보려고했는데
Collection부터 초기화까지 문법 하나도 기억안남;

옛날 책 다시 꺼내야겠다