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: ...@@ -12,6 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1cfb2ac990cea404494c0e55af055d62, type: 3} m_Script: {fileID: 11500000, guid: 1cfb2ac990cea404494c0e55af055d62, type: 3}
m_Name: HeadShot m_Name: HeadShot
m_EditorClassIdentifier: m_EditorClassIdentifier:
tier: 0 m_tier: 0
index: 0 m_index: 0
m_skillImage: {fileID: 21300000, guid: 4c85b737d44119f4f828910c3bd26659, type: 3}
cooltime: 0
damageTimes: 2 damageTimes: 2
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -118,7 +118,7 @@ public class Enemy : Actor ...@@ -118,7 +118,7 @@ public class Enemy : Actor
public override void OnSelected() public override void OnSelected()
{ {
throw new System.NotImplementedException(); //throw new System.NotImplementedException();
} }
public override void OnUnselected() public override void OnUnselected()
......
...@@ -16,12 +16,23 @@ public abstract class PlayableCharacter : Actor ...@@ -16,12 +16,23 @@ public abstract class PlayableCharacter : Actor
{ {
[SerializeField] [SerializeField]
private WeaponBehaviour weaponBehaviour = null; 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 Enemy Target { private get; set; }
public bool isAutoTargeting = false; public bool isAutoTargeting = false;
public LayerMask enemyMask; public LayerMask enemyMask;
[SerializeField]
private Skill[] m_skills = new Skill[4];
public Skill[] Skills { get { return m_skills; } }
protected override void Start() protected override void Start()
{ {
base.Start(); base.Start();
...@@ -29,6 +40,11 @@ public abstract class PlayableCharacter : Actor ...@@ -29,6 +40,11 @@ public abstract class PlayableCharacter : Actor
weaponBehaviour = GetComponent<WeaponBehaviour>(); weaponBehaviour = GetComponent<WeaponBehaviour>();
if (selectRing == null) if (selectRing == null)
selectRing = transform.Find("SelectRing").gameObject; 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() protected virtual void Update()
...@@ -60,7 +76,19 @@ public abstract class PlayableCharacter : Actor ...@@ -60,7 +76,19 @@ public abstract class PlayableCharacter : Actor
{ {
isSelected = false; isSelected = false;
selectRing?.SetActive(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) public override void MoveTo(Vector2 destination)
...@@ -109,6 +137,12 @@ public abstract class PlayableCharacter : Actor ...@@ -109,6 +137,12 @@ public abstract class PlayableCharacter : Actor
transform.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.up, target.position - transform.position)); 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 DefaultControl();
protected abstract void AimingControl(); protected abstract void AimingControl();
} }
...@@ -22,6 +22,7 @@ public class EnemyEditor : Editor ...@@ -22,6 +22,7 @@ public class EnemyEditor : Editor
Vector3 newPosition = Handles.FreeMoveHandle(enemy.RoamingPath[i], Quaternion.identity, 1f, Vector3.one, Handles.CircleHandleCap); Vector3 newPosition = Handles.FreeMoveHandle(enemy.RoamingPath[i], Quaternion.identity, 1f, Vector3.one, Handles.CircleHandleCap);
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject(enemy, "Prev Roaming");
enemy.RoamingPath[i] = newPosition; enemy.RoamingPath[i] = newPosition;
} }
} }
......
...@@ -7,7 +7,8 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager> ...@@ -7,7 +7,8 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager>
{ {
public RectTransform dragUI; public RectTransform dragUI;
public GameObject characterStatusUI;
public Image[] skillUIs = new Image[4];
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -51,4 +52,26 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager> ...@@ -51,4 +52,26 @@ public class IngameUIManager : SingletonBehaviour<IngameUIManager>
{ {
PlayerController.inst.SelectCharacter(index); 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> ...@@ -17,6 +17,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
[SerializeField] [SerializeField]
private List<PlayableCharacter> characters = new List<PlayableCharacter>(); private List<PlayableCharacter> characters = new List<PlayableCharacter>();
private Vector3 lastMousePos; private Vector3 lastMousePos;
[SerializeField] [SerializeField]
...@@ -50,6 +51,14 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -50,6 +51,14 @@ public class PlayerController : SingletonBehaviour<PlayerController>
characters[i].OnSelected(); characters[i].OnSelected();
} }
} }
if (Input.GetKeyDown(KeyCode.Q))
{
foreach (var character in characters)
{
character.UseSkill(0);
}
}
} }
public void MouseControl() public void MouseControl()
...@@ -96,14 +105,24 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -96,14 +105,24 @@ public class PlayerController : SingletonBehaviour<PlayerController>
{ {
foreach(var character in characters) foreach(var character in characters)
{ {
if (selectedCharacters.Contains(character))
continue;
character.OnUnselected(); character.OnUnselected();
} }
} }
foreach(var character in selectedCharacters)
if (selectedCharacters.Count == 1)
{
selectedCharacters[0].OnOnlySelected();
}
else
{
foreach (var character in selectedCharacters)
{ {
character.OnSelected(); character.OnSelected();
} }
} }
}
else if (selectedEnemies.Count < 1) else if (selectedEnemies.Count < 1)
{ {
foreach (var character in characters) foreach (var character in characters)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class BouncingShot : Skill public sealed class BouncingShot : Skill
{ {
public GameObject bouncyBulletPrefab; public GameObject bouncyBulletPrefab;
public int bounceCount = 3; public int bounceCount = 3;
...@@ -26,7 +26,7 @@ public class BouncingShot : Skill ...@@ -26,7 +26,7 @@ public class BouncingShot : Skill
} }
} }
public override void Use() protected override void Use()
{ {
} }
......
...@@ -3,7 +3,7 @@ using System.Collections.Generic; ...@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
public class HeadShot : Skill public sealed class HeadShot : Skill
{ {
public float damageTimes; public float damageTimes;
private Collider2D target; private Collider2D target;
...@@ -19,28 +19,29 @@ public class HeadShot : Skill ...@@ -19,28 +19,29 @@ public class HeadShot : Skill
public override void Aiming() public override void Aiming()
{ {
throw new System.NotImplementedException(); weaponBehaviour.StartCoroutine(AimingRoutine());
} }
private IEnumerator AimingRoutine() private IEnumerator AimingRoutine()
{ {
while (true) while (true)
{ {
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target = Physics2D.OverlapPoint(mouseWorldPosition, 1 << LayerMask.NameToLayer("Enemy"));
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0))
{ {
Use(); Use();
break; break;
} }
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target = Physics2D.OverlapPoint(mouseWorldPosition, LayerMask.NameToLayer("Enemy"));
yield return null; yield return null;
} }
} }
public override void Use() protected override void Use()
{ {
if (!target) if (!target)
return; return;
Debug.Log("A");
target.GetComponent<Enemy>().Health -= Mathf.CeilToInt(weaponBehaviour.weapon.damage * damageTimes); target.GetComponent<Enemy>().Health -= Mathf.CeilToInt(weaponBehaviour.weapon.damage * damageTimes);
} }
} }
...@@ -7,8 +7,31 @@ public abstract class Skill : ScriptableObject ...@@ -7,8 +7,31 @@ public abstract class Skill : ScriptableObject
protected PlayableCharacter character; protected PlayableCharacter character;
protected WeaponBehaviour weaponBehaviour; protected WeaponBehaviour weaponBehaviour;
public int tier; [SerializeField]
public int index; 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) public virtual void Init(PlayableCharacter character)
{ {
...@@ -17,5 +40,5 @@ public abstract class Skill : ScriptableObject ...@@ -17,5 +40,5 @@ public abstract class Skill : ScriptableObject
} }
public abstract void Aiming(); public abstract void Aiming();
public abstract void Use(); protected abstract void Use();
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;
public sealed class WeaponBehaviour : MonoBehaviour public sealed class WeaponBehaviour : MonoBehaviour
{ {
...@@ -23,14 +24,23 @@ public sealed class WeaponBehaviour : MonoBehaviour ...@@ -23,14 +24,23 @@ public sealed class WeaponBehaviour : MonoBehaviour
private float shotRadius = 0; private float shotRadius = 0;
[SerializeField]
private Light2D gunFireLight;
private void Start() private void Start()
{ {
for (int i = 0; i < weapons.Count; i++)
{
weapons[i] = Instantiate(weapons[i]);
}
ChangeWeapon(weaponIndex); ChangeWeapon(weaponIndex);
} }
private void Update() private void Update()
{ {
weapon.UpdateWeapon(Time.deltaTime); weapon.UpdateWeapon(Time.deltaTime);
gunFireLight.intensity = Mathf.Max(0, gunFireLight.intensity - 50 * Time.deltaTime);
} }
public void Init(Weapon weapon) public void Init(Weapon weapon)
...@@ -52,6 +62,7 @@ public sealed class WeaponBehaviour : MonoBehaviour ...@@ -52,6 +62,7 @@ public sealed class WeaponBehaviour : MonoBehaviour
public void EmitBulletParticle() public void EmitBulletParticle()
{ {
bulletParticle.Emit(1); bulletParticle.Emit(1);
gunFireLight.intensity = 3;
} }
public void DrawWeaponRange() public void DrawWeaponRange()
...@@ -79,7 +90,7 @@ public sealed class WeaponBehaviour : MonoBehaviour ...@@ -79,7 +90,7 @@ public sealed class WeaponBehaviour : MonoBehaviour
shotRangeRenderer.enabled = true; shotRangeRenderer.enabled = true;
} }
public void OnDeselected() public void OnUnselected()
{ {
shotRangeRenderer.enabled = false; 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