在這次的範例裡,主要是說明IUnit
如何取用ActionAbility
的使用
這邊的AbilityEditor
是用來擺放技能的地方,只要擺上對應的技能就可以在遊戲裡被使用
AbilityEditor.cs
public class AbilityEditor : Ability
{
[SerializeField] private CALAbility[] m_ActionAbilitys;
[SerializeField] private CALAbility m_MoveAbility;
public CALAbility[] ActionAbilitys { get => m_ActionAbilitys; set => m_ActionAbilitys = value; }
public CALAbility MoveAbility { get => m_MoveAbility; set => m_MoveAbility = value; }
在Inspector介面就可以放相對應的技能在裡面
而IUnit
中,UseActionAbility
這function主要實作此技能的部分是在ActionAbility
裡面,本身只是作為讓其它系統可以使用此ActionAbility
的地方
IUnit.cs
using LuLuBearStudio.CALAbilities;
namespace LinXuan.TBSF.Units
{
public abstract class IUnit : MonoBehaviour
{
[SerializeField] private AbilityEditor m_AbilityEditor;
public virtual void UseActionAbility()
{
}
}
}
而PlayerUnit
與EnemyUnit
就是主要實作UseActionAbility
功能的部分
PlayerUnit.cs
using Assets.Scripts.GUI.GUITool;
using LinXuan.TBSF.Enums;
using UnityEngine;
namespace LinXuan.TBSF.Units
{
public class PlayerUnit : IUnit
{
[SerializeField] private PlayerUnitType m_PlayerUnitType;
public override void UseActionAbility()
{
base.UseActionAbility();
m_AbilityEditor.ActionAbilitys[0].CALHumanExecute(UIInputObserver.CellGrid);
//Other PlayerUnit ActionAbility setting...
}
}
}
EnemyUnit.cs
using Assets.Scripts.GUI.GUITool;
using LinXuan.TBSF.Enums;
using UnityEngine;
namespace LinXuan.TBSF.Units
{
public class EnemyUnit : IUnit
{
[SerializeField] private EnemyUnitType m_EnemyUnitType;
public override void UseActionAbility()
{
base.UseActionAbility();
m_AbilityEditor.ActionAbilitys[0].AIExecute(UIInputObserver.CellGrid);
//Other EnemyUnit ActionAbility setting...
}
}
}
不過這邊的程式碼目前還只是思考的階段,所以還沒有真的去做實際測試,這邊就不提供實際輸出的部分了
設計模式與遊戲開發的完美結合(暢銷回饋版)
Turn Based Strategy Framework
流離之歌