Hello, just to make things clear, Color is now serializable in Unity 4.5.
Issuing Debug.Log(System.Attribute.IsDefined(typeof(Color), typeof(System.SerializableAttribute))); returns true, Yay!
I’ve successfully done it with a simple test, but for some reason it isn’t working in my real-case scenario. Here is a code excerpt. The error I am getting is Type UnityEngine.Color is not marked as Serializable. But it should work… I think the problem is in my functions, or the constructor. I am new to serialising data in Unity, so the problem is probably me
[System.Serializable]
public class Stats {
public int id;
public bool parentIsHead = false;
public float[] floatStats;// agility, thrust, thrustMag, thrustMagFreq, armour, hp;
public Color mainColor;// colorMain, colorSecondary;
public Color secondColor;
public Stats()
{
floatStats = new float[6];
mainColor = new Color(1,1,1);
secondColor = new Color(0,0,0);
Debug.Log(System.Attribute.IsDefined(typeof(Color), typeof(System.SerializableAttribute)));
}
public void initEmpty()
{
for (int i = 0; i < floatStats.Length; ++i)
floatStats *= 1;*
// mainColor = new Color(0,0,0);
// secondColor = new Color(0,0,0);
-
}*
-
public void initRandom()*
-
{*
-
for (int i = 0; i < floatStats.Length; ++i)*
_ floatStats = myRandom();_
* // TODO: Nice random colors*
// mainColor = new Color(myRandomColor(), myRandomColor(), myRandomColor());
// secondColor = new Color(myRandomColor(), myRandomColor(), myRandomColor());
* }*
* float myRandom()*
* {*
* return Random.Range(5, 10);*
* }*
* float myRandomColor()*
* {*
* // We don’t want values close to .5, cause its ugly!*
* return Random.Range(0.0f, 1.0f);*
* }*
}
Thanks in advance for any help!