I am literally pulling my fricking hair out at this… I do not know what im doing wrong. I want to access a custom class type from the normal script that the editor script attaches to. I figgured i could do it with arrays so why not classes? Nope it talks about "Cannot cast from source type to destination type) Even though it seems though i should be able to achieve what im thinking of, unity is being annoying as usual.
What i realy want is for each class to fall under its own foldout under WeaponTable.
Here is the code anyway…
LootMaster.js
#if UNITY_EDITOR
@script ExecuteInEditMode()
enum LootClass
{
CivilianLow = 0,
CivilianAverage = 1,
CivilianHigh = 2,
MilitaryLow = 3,
MilitaryAverage = 4,
MilitaryHigh = 5,
MedicalLow = 6,
MedicalAverage = 7,
MedicalHigh = 8,
FoodLow = 9,
FoodAverage = 10,
FoodHigh = 11,
}
class LootItem
{
var Item : GameObject;
var Rarity : float;
var LootType : LootClass;
}
private var TempArray : Object[];
var WeaponTable : LootItem[];
var WeaponTableLength : int;
var OldWeaponTableLength : int;
var Medical : Object[];
var Equipment : Object[];
var Addons : Object[];
var Misc : Object[];
function Start()
{
OldWeaponTableLength = WeaponTableLength;
}
function LateUpdate()
{
UpdateWeaponArray();
}
function UpdateWeaponArray()
{
WeaponTable = new LootItem[WeaponTableLength];
}
#endif
And the other script…
@CustomEditor (LootMaster)
class LootMasterEditor extends Editor
{
private var WeaponTableFold : boolean;
function OnInspectorGUI()
{
WeaponTableFold = EditorGUILayout.Foldout(WeaponTableFold, "Weapon Table");
if(WeaponTableFold)
{
target.WeaponTableLength = EditorGUILayout.IntField("Ammount Of Weapons", target.WeaponTableLength);
for(var x = 0; x < target.WeaponTableLength - 1; x++)
{
target.WeaponTable[x].Item = EditorGUILayout.ObjectField("Weapon", target.WeaponTable[x].Item, typeof(GameObject), true);
}
}
}
}
If it is any help, i am trying to achieve a loot table so i can dynamicaly generate loot in containers at the start of every game.