this is the periodic table class
using UnityEngine;
public class PeriodicTable
{
[SerializeField]
private Element _thisElement;
public PeriodicTable (string symbol)
{
_thisElement = (Element)ScriptableObject.CreateInstance<Element>();
_thisElement = new Element(symbol);
_thisElement.Symbol=symbol;
//_element.ID=id;
}
public PeriodicTable (Element element)
{
this._thisElement=element;
ValenceElectronsBySymbol(element.Symbol);
AtomicNumberBySymbol(element.Symbol);
}
public Element ThisElement
{
get{return _thisElement;}
set{_thisElement = value;}
}
private void ValenceElectronsBySymbol (string symbol)
{
int e=1;
string[] collums=new string[] {"H","Li","Na","K","Rb","Cs","Fr",
"-","Be","Mg","Ca","Sr","Ba","Ra","-","B","-","C","Si",
"-","N","P","As","-","O","S","Se","Te","-","F","Cl",
"Br","I","At","-","He","Ne","Ar","Kr","Xe","Rn"};
for(var j=0; j<collums.Length; j++)
{
if(collums[j]=="-")e++;
if(symbol==collums[j])
{
_thisElement.ValenceElectrons=e;
_thisElement.NonMetal=true;
}
}
}
private void AtomicNumberBySymbol (string symbol)
{
int c=0;
int r=0;
string[] collums=new string[]
{
"-","H","Li","Na","K","Rb","Cs","Fr",
"-","Be","Mg","Ca","Sr","Ba","Ra",
"-","Sc","Y","La","Ac",
"-","Ti","Zr","Hf","Rf",
"-","V","Nb","Ta","Db",
"-","Cr","Mo","W","Sg",
"-","Mn","Tc","Re","Bh",
"-","Fe","Ru","Os","Hs",
"-","Co","Rh","Ir","Mt",
"-","Ni","Pd","Pt","Ds",
"-","Cu","Ag","Au","Rg",
"-","Zn","Cd","Hg","Cn",
"-","B","Al","Ga","In","Tl","Uut",
"-","C","Si","Ge","Sn","Pb","Fl",
"-","N","P","As","Sb","Bi","Uup",
"-","O","S","Se","Te","Po","Lv",
"-","F","Cl","Br","I","At","Uus",
"-","He","Ne","Ar","Kr","Xe","Rn","Uuo"
};
for(int i=0; i<collums.Length; i++)
{
if(collums[i]=="-")c++;
if(symbol==collums[i])Debug.Log (c);
}
string[] rows=new string[]
{
"-","H","He",
"-","Li","Be","B","C","N","O","F","Ne",
"-","Na","Mg","Al","Si","P","S","Cl","Ar",
"-","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr",
"-","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe",
"-","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu",
"Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
"-","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr",
"Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Cn","Uut","Fl","Uup","Lv","Uus","Uuo"
};
for(int ii=0; ii<collums.Length; ii++)
{
if(collums[ii]=="-")r++;
if(symbol==collums[ii])Debug.Log (r);
}
string[] atomNumber=new string[]
{
"-","H","He",
"Li","Be","B","C","N","O","F","Ne",
"Na","Mg","Al","Si","P","S","Cl","Ar",
"K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr",
"Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe",
"Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu",
"Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
"Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr",
"Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Cn","Uut","Fl","Uup","Lv","Uus","Uuo"
};
for(int n=0; n<atomNumber.Length; n++)
{
if(symbol==atomNumber[n])_thisElement.AtomicNumber=n;
}
}
}
and the Element class:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Element : KeyItem
{
[SerializeField]
private int _atomicNumber;
[SerializeField]
private string _symbol;
[SerializeField]
private int _valenceElectrons;
[SerializeField]
private bool _nonMetal;
[SerializeField]
private int _electroNegativity;
[SerializeField]
private int _atomicRadius;
[SerializeField]
private Color _atomColor;
[SerializeField]
private int _capacity;
public Element (string symbol)
{
this._symbol = symbol;
new PeriodicTable(this);
}
#region get/set
public int AtomicNumber
{
get{return _atomicNumber;}
set{_atomicNumber = value;}
}
public string Symbol
{
get{return _symbol;}
set{_symbol = value;}
}
public int ValenceElectrons
{
get{return _valenceElectrons;}
set{_valenceElectrons = value;}
}
public bool NonMetal
{
get{return _nonMetal;}
set{_nonMetal = value;}
}
public int ElectroNegativity
{
get{return _electroNegativity;}
set{_electroNegativity = value;}
}
public int AtomicRadius
{
get{return _atomicRadius;}
set{_atomicRadius = value;}
}
public Color AtomColor
{
get{return _atomColor;}
set{_atomColor = value;}
}
public int Capacity
{
get{return _capacity;}
set{_capacity = value;}
}
#endregion
}
this is the result:
