카테고리 없음

2018.04.02 수업내용 (데이터 바인딩, 캐릭터 생성)

일등하이 2018. 5. 15. 21:35
반응형
리소스및 데이터 준비 
Path를 정의한 GameConstants클래스 생성 
데이터 로드 
데이터 맵핑 
데이터 변수 값 설정 (Dictionary)
맵 생성
-리소스 로드 
-프리팹 생성 
영웅 생성 
-리소스 로드 
-프리팹 생성 
몬스터 생성 
-리소스 로드 
-프리팹 생성 

맵 프리팹에 위치 설정 (Transform)
Map클래스 생성후 맵 프리팹에 바인딩 
맵 로드 후 Map콤포넌트 가져옴 
Map콤포넌트로부터 캐릭터의 위치(Transform)을 가져옴
Character클래스 생성 
몬스터, 영웅 생성시 동적으로 Character콤포넌트 부착 
몬스터, 영웅의 초기위치 설정 


*리펙토링





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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Character : MonoBehaviour {
 
    public int attackRange = 2;
    public int speed = 1;
    
    private int hp;
    private Character target;
    private Animation anim;
    private string characterName;
 
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
 
    public void Init(string name, int hp)
    {
        this.characterName = name;
        this.hp = hp;
        this.anim = GetComponent<Animation>();
    }
 
    public IEnumerator MoveAttck(Character target)
    {
        this.target = target;
 
        while (true)
        {
            this.anim.Play("run@loop");
            //이동 
            var step = speed * Time.deltaTime;
            this.transform.position = Vector3.MoveTowards(this.transform.position, this.target.transform.position, step);
            this.anim.Play("run@loop");
 
            yield return null;
 
            //탈출구 
            var dis = Vector3.Distance(this.transform.position, this.target.transform.position);
            if (dis < this.attackRange)
            {
                break;
            }
        }
 
 
        //멈추고 때림 
        while (true)
        {
            if (target == null && target.hp <= 0)
            {
                break;
            }
 
            var state = this.anim["attack_sword_01"];
            this.anim.Play("attack_sword_01");
 
            yield return new WaitForSeconds(0.2863f);
 
            this.target.TakeDamage(1);
 
            yield return new WaitForSeconds(state.length - 00.2863f);
 
        }
 
        //대상이 없거나 죽은경우 
        this.anim.Play("idle@loop");
        yield return null;
    }
 
    public void LookAt(Character target)
    {
        this.transform.LookAt(target.transform);
    }
 
    public void TakeDamage(int damage)
    {
        
        this.hp -= damage;
        if (this.hp <= 0)
        {
            this.Die();
        }
        else
        {
            Debug.Log(this.characterName + "이(가) 피해(" + damage + ")를 받았습니다.");
        }
    }
 
    private void Die()
    {
        GameObject.Destroy(this.gameObject);
    }
}
 
cs









반응형