summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/Equips/LightSaber/Equip_LightSaber.cs
blob: 9066884870c018547a137ef99edbf61e2e2d85e2 (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
62
63
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Equip_LightSaber : EquipBase
{
	public override string name => "¹â½£";

	public override string iconPath => "art/ui/equipicon/light_saber";

	public override AutoMode autoMode => AutoMode.Condition;

	private string lightSaberPrefabPath = "prefabs/weapon/light_saber";

	private bool isWielding = false;

	private LightSaber m_LightSaber;

	private TopDownTransform m_TopDownTransform;

	private float m_Dist = 0.2f;

	public override void OnInitialize(GameObject owner)
	{
		m_LightSaber = UnityEngine.Object.Instantiate<LightSaber>(ResourceManager.Instance.Load<LightSaber>(lightSaberPrefabPath));
		m_TopDownTransform = m_LightSaber.gameObject.GetComponent<TopDownTransform>();
		SetLightSaberPositionAndRotation(owner.GetComponent<CrewScript>());
		m_LightSaber.gameObject.SetActive(false);
	}

	public override bool CheckCondition(GameObject owner)
	{
		return true;
	}

	public override void OnTrigger(GameObject owner)
	{
		if (isWielding)
			return;
		isWielding = true;

		m_LightSaber.gameObject.SetActive(true);
	}

	public override void OnStop(GameObject owner)
	{
		isWielding = false;
		m_LightSaber.gameObject.SetActive(false);
	}

	public override void Update(GameObject owner)
	{
		CrewScript crew = owner.GetComponent<CrewScript>();
		SetLightSaberPositionAndRotation(crew);
	}

	void SetLightSaberPositionAndRotation(CrewScript crew)
	{
		m_LightSaber.transform.position = crew.arrow.position + new Vector3(crew.aimDirection.x, crew.aimDirection.y, 0) * m_Dist;
		m_LightSaber.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(crew.aimDirection.y, crew.aimDirection.x) * Mathf.Rad2Deg);
	}

}