summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Controller/MonsterController.cs
blob: 981e6d4b75f68db515c59cd7d6898376030ee8a6 (plain)
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterController : UnitController
{
    public override UnitType type { get { return UnitType.Monster; } }

    public Vector3 center
    {
        get
        {
            return GetComponentInChildren<Renderer>().bounds.center;
        }
    }

    public override void Initialize(GameObject obj, string folder)
    {
        base.Initialize(obj, folder);

        unitState = gameObject.GetOrAddComponent<MonsterState>();
        unitState.Initialize();

        unitAnimation = gameObject.GetOrAddComponent<MonsterAnimation>();
        unitAnimation.Initialize();
    }

    public override void Update()
    {
        base.Update();
    }

    public override void OnHit(CollisionInfo info)
    {
    }

    public override void OnGetHit(CollisionInfo info)
    {
        ColliderBox hitbox = info.collider.colliderInfo.collider;
        Debug.Assert(hitbox.type == ColliderBox.EColliderType.HitBox);

        if(hitbox.hitResponse == ColliderBox.EHitResponse.Light)
        {
            monsterState.ChangeState(MonsterState.EUnitState.HitLight, new MonsterState.HitLightParam());
        }
        else if(hitbox.hitResponse == ColliderBox.EHitResponse.HitAir)
        {
            monsterState.ChangeState(MonsterState.EUnitState.HitAir, new MonsterState.HitAirParam());
        }

        string path = hitbox.sparkPath;
		GameObject vfx = ResourceManager.Instance.LoadAsset<GameObject>(path);
        if(vfx != null)
        {
            GameObject go = GameObject.Instantiate(vfx);
            go.transform.position = center + hitbox.sparkOffset;
			go.transform.localScale = hitbox.sparkScale;
        }
    }

}