Commit 4393e73e authored by 15박보승's avatar 15박보승

Implementing skill system. Debug a bug related with ScriptableObject assets. Minor changes.

parent ff9eca1b
......@@ -12,6 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1cfb2ac990cea404494c0e55af055d62, type: 3}
m_Name: HeadShot
m_EditorClassIdentifier:
tier: 0
index: 0
m_tier: 0
m_index: 0
m_skillImage: {fileID: 21300000, guid: 4c85b737d44119f4f828910c3bd26659, type: 3}
cooltime: 0
damageTimes: 2
This diff is collapsed.
......@@ -118,7 +118,7 @@ public class Enemy : Actor
public override void OnSelected()
{
throw new System.NotImplementedException();
//throw new System.NotImplementedException();
}
public override void OnUnselected()
......
......@@ -16,12 +16,23 @@ public abstract class PlayableCharacter : Actor
{
[SerializeField]
private WeaponBehaviour weaponBehaviour = null;
public bool isSelected = false;
#region Character Status Booleans
private bool isOnlySelected = false;
private bool isSelected = false;
#endregion
public Enemy Target { private get; set; }
public bool isAutoTargeting = false;
public LayerMask enemyMask;
[SerializeField]
private Skill[] m_skills = new Skill[4];
public Skill[] Skills { get { return m_skills; } }
protected override void Start()
{
base.Start();
......@@ -29,6 +40,11 @@ public abstract class PlayableCharacter : Actor
weaponBehaviour = GetComponent<WeaponBehaviour>();
if (selectRing == null)
selectRing = transform.Find("SelectRing").gameObject;
for (int i = 0; i < 4; i++)
{
m_skills[i] = Instantiate(m_skills[i]);
m_skills[i].Init(this);
}
}
protected virtual void Update()
......@@ -60,7 +76,19 @@ public abstract class PlayableCharacter : Actor
{
isSelected = false;
selectRing?.SetActive(false);
weaponBehaviour.OnDeselected();
weaponBehaviour.OnUnselected();
if (isOnlySelected)
{
IngameUIManager.inst.DisableCharacterStatusUI();
isOnlySelected = false;
}
}
public void OnOnlySelected()
{
OnSelected();
isOnlySelected = true;
IngameUIManager.inst.EnableCharacterStatusUI(this);
}
public override void MoveTo(Vector2 destination)
......@@ -109,6 +137,12 @@ public abstract class PlayableCharacter : Actor
transform.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.up, target.position - transform.position));
}
public void UseSkill(int index)
{
if (isOnlySelected && m_skills[index].IsReady)
m_skills[index].Aiming();
}
protected abstract void DefaultControl();
protected abstract void AimingControl();
}
......@@ -22,6 +22,7 @@ public class EnemyEditor : Editor
Vector3 newPosition = Handles.FreeMoveHandle(enemy.RoamingPath[i], Quaternion.identity, 1f, Vector3.one, Handles.CircleHandleCap);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(enemy, "Prev Roaming");
enemy.RoamingPath[i] = newPosition;
}
}
......
......@@ -7,7 +7,8 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager>
{
public RectTransform dragUI;
public GameObject characterStatusUI;
public Image[] skillUIs = new Image[4];
// Start is called before the first frame update
void Start()
......@@ -51,4 +52,26 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager>
{
PlayerController.inst.SelectCharacter(index);
}
public void EnableCharacterStatusUI(PlayableCharacter character)
{
characterStatusUI.SetActive(true);
for(int i = 0; i < 4; i++)
{
skillUIs[i].sprite = character.Skills[i].SkillImage;
UpdateSkillUI(character.Skills[i]);
}
}
public void DisableCharacterStatusUI()
{
characterStatusUI.SetActive(false);
}
public void UpdateSkillUI(Skill skill)
{
Image skillUI = skillUIs[skill.Tier];
skillUI.GetComponentInChildren<Text>().text = skill.RemainedCooltime.ToString("F1");
skillUI.fillAmount = skill.CooltimeRatio;
}
}
......@@ -17,6 +17,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
[SerializeField]
private List<PlayableCharacter> characters = new List<PlayableCharacter>();
private Vector3 lastMousePos;
[SerializeField]
......@@ -50,6 +51,14 @@ public class PlayerController : SingletonBehaviour<PlayerController>
characters[i].OnSelected();
}
}
if (Input.GetKeyDown(KeyCode.Q))
{
foreach (var character in characters)
{
character.UseSkill(0);
}
}
}
public void MouseControl()
......@@ -96,12 +105,22 @@ public class PlayerController : SingletonBehaviour<PlayerController>
{
foreach(var character in characters)
{
if (selectedCharacters.Contains(character))
continue;
character.OnUnselected();
}
}
foreach(var character in selectedCharacters)
if (selectedCharacters.Count == 1)
{
selectedCharacters[0].OnOnlySelected();
}
else
{
character.OnSelected();
foreach (var character in selectedCharacters)
{
character.OnSelected();
}
}
}
else if (selectedEnemies.Count < 1)
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public class BouncingShot : Skill
public sealed class BouncingShot : Skill
{
public GameObject bouncyBulletPrefab;
public int bounceCount = 3;
......@@ -26,7 +26,7 @@ public class BouncingShot : Skill
}
}
public override void Use()
protected override void Use()
{
}
......
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class HeadShot : Skill
public sealed class HeadShot : Skill
{
public float damageTimes;
private Collider2D target;
......@@ -19,28 +19,29 @@ public class HeadShot : Skill
public override void Aiming()
{
throw new System.NotImplementedException();
weaponBehaviour.StartCoroutine(AimingRoutine());
}
private IEnumerator AimingRoutine()
{
while (true)
{
if (Input.GetMouseButtonDown(0))
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target = Physics2D.OverlapPoint(mouseWorldPosition, 1 << LayerMask.NameToLayer("Enemy"));
if (Input.GetMouseButtonDown(0))
{
Use();
break;
}
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target = Physics2D.OverlapPoint(mouseWorldPosition, LayerMask.NameToLayer("Enemy"));
yield return null;
}
}
public override void Use()
protected override void Use()
{
if (!target)
return;
Debug.Log("A");
target.GetComponent<Enemy>().Health -= Mathf.CeilToInt(weaponBehaviour.weapon.damage * damageTimes);
}
}
......@@ -7,8 +7,31 @@ public abstract class Skill : ScriptableObject
protected PlayableCharacter character;
protected WeaponBehaviour weaponBehaviour;
public int tier;
public int index;
[SerializeField]
private int m_tier;
public int Tier { get { return m_tier; } }
[SerializeField]
private int m_index;
public int Index { get { return m_index; } }
[SerializeField]
private Sprite m_skillImage;
public Sprite SkillImage { get { return m_skillImage; } }
[SerializeField]
private float cooltime;
protected float m_remainedCooltime = 0;
public float RemainedCooltime { get { return m_remainedCooltime; } }
public bool IsReady { get { return m_remainedCooltime <= 0; } }
public float CooltimeRatio { get { return m_remainedCooltime / cooltime; } }
public virtual void UpdateSkill(float deltaTime)
{
m_remainedCooltime = Mathf.Max(0, m_remainedCooltime - deltaTime);
IngameUIManager.inst.UpdateSkillUI(this);
}
public virtual void Init(PlayableCharacter character)
{
......@@ -17,5 +40,5 @@ public abstract class Skill : ScriptableObject
}
public abstract void Aiming();
public abstract void Use();
protected abstract void Use();
}
......@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;
public sealed class WeaponBehaviour : MonoBehaviour
{
......@@ -23,14 +24,23 @@ public sealed class WeaponBehaviour : MonoBehaviour
private float shotRadius = 0;
[SerializeField]
private Light2D gunFireLight;
private void Start()
{
for (int i = 0; i < weapons.Count; i++)
{
weapons[i] = Instantiate(weapons[i]);
}
ChangeWeapon(weaponIndex);
}
private void Update()
{
weapon.UpdateWeapon(Time.deltaTime);
gunFireLight.intensity = Mathf.Max(0, gunFireLight.intensity - 50 * Time.deltaTime);
}
public void Init(Weapon weapon)
......@@ -52,6 +62,7 @@ public sealed class WeaponBehaviour : MonoBehaviour
public void EmitBulletParticle()
{
bulletParticle.Emit(1);
gunFireLight.intensity = 3;
}
public void DrawWeaponRange()
......@@ -79,7 +90,7 @@ public sealed class WeaponBehaviour : MonoBehaviour
shotRangeRenderer.enabled = true;
}
public void OnDeselected()
public void OnUnselected()
{
shotRangeRenderer.enabled = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment