I'm very new to C# so please excuse me if i'm asking stupid question or i'm making my question incorrectly.
Here is my code:
using UnityEngine;
using System;
namespace DuloGames.UI
{
[Serializable]
public class UISpellInfo
{
public int ID;
public string Name;
public Sprite Icon;
public string Description;
public float Range;
public float Cooldown;
public float CastTime;
public float PowerCost;
public float test;
[BitMask(typeof(UISpellInfo_Flags))]
public UISpellInfo_Flags Flags;
}
}
Here is my UIspellDatabase class:
using UnityEngine;
namespace DuloGames.UI
{
public class UISpellDatabase : ScriptableObject {
#region singleton
private static UISpellDatabase m_Instance;
public static UISpellDatabase Instance
{
get
{
if (m_Instance == null)
m_Instance = Resources.Load("Databases/SpellDatabase") as UISpellDatabase;
return m_Instance;
}
}
#endregion
public UISpellInfo[] spells;
/// <summary>
/// Get the specified SpellInfo by index.
/// </summary>
/// <param name="index">Index.</param>
public UISpellInfo Get(int index)
{
return (spells[index]);
}
/// <summary>
/// Gets the specified SpellInfo by ID.
/// </summary>
/// <returns>The SpellInfo or NULL if not found.</returns>
/// <param name="ID">The spell ID.</param>
public UISpellInfo GetByID(int ID)
{
for (int i = 0; i < this.spells.Length; i++)
{
if (this.spells[i].ID == ID)
return this.spells[i];
}
return null;
}
}
}
Here is how i foreach the existing instances of UISpellInfo:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WorldServer;
using Spells;
using DuloGames.UI;
public class Character : MonoBehaviour
{
private void SeeAllInstances()
{
foreach (var item in UISpellDatabase.Instance.spells)
{
Debug.Log("ID->" + item.ID + " name: " + item.Name);
}
}
I can clearly see all the instances i have for this class UISpellInfo.
What i want to achieve is just to add more instances to array UISpellInfo[] spells;.
As far as i understand all the instances of the class UISpellInfo are loaded here UISpellInfo[] spells; then on the foreach i do in SeeAllInstances() i can see all the instances and the data hold for every instance.
My question if i'm even asking correctly is how to add more instances in UISpellInfo[] spells; ?
Can someone help me on this ?