I’m trying to create an AnimationSystem for uv-animation with a custom editor for my animations class settings. However, the components (and their members) seem to get created a new on starting the game, which means that the constructor for my UVAnimationSystem and it’s members are called, which throws away all editor choices.
Do i need to override a clone() or copy() function or create a copy constructor for that to work? sorry to ask such a dumb question, but i couldn’t find any documentation to that problem. Standard datatypes (float, int, …) seem to work, but for custom classes you seem to have to do something additional to make it work
beneath are snippets of my current classes
thanks for any help
class UVAnimationSystem extends MonoBehaviour
{
public function UVAnimationSystem()
{
...
}
private var animations:Array = new Array();
// array holds UVAnimation instances
}
class UVAnimation
{
public function UVAnimation()
{
anim = AnimId.ANIM_NONE;
mode = CounterMode.MODE_LOOP;
}
private var anim:AnimId;
private var mode:CounterMode;
...
+ set/get
}
// editor
@CustomEditor(UVAnimationSystem)
class UVAnimationSystemEditor extends Editor
{
public function OnInspectorGUI()
{
var animSystem:UVAnimationSystem = target;
var animations:Array = animSystem.GetAnimations();
var lastAnimationsLength:int = animations.length;
var animationCount:int = animations.length;
EditorGUILayout.BeginHorizontal();
animationCount = EditorGUILayout.IntField("AnimationCount", animationCount);
animations.length = (animationCount > 0)?animationCount:0;
EditorGUILayout.EndHorizontal();
var i:int;
for (i = 0; i < animations.length; i++)
{
if (animations[i] == null)
{
animations[i] = new UVAnimation();
}
EditorGUILayout.BeginHorizontal();
animations[i].SetAnim(EditorGUILayout.EnumPopup("Animation", animations[i].GetAnim()));
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
animations[i].SetMode(EditorGUILayout.EnumPopup("Mode", animations[i].GetMode()));
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
}
}
}
no idea anyone? i’m grateful for any direction you can point me. as reward i’ll be putting the animationssystem online once that is worked out (it’s really the last stone that’s missing…)
cheers, manni
okay, to make it a bit easier, here is a shorter version for testing. still the array length of MyComponent gets set to zero on starting. Is there a need for a copy constructor? clone function? any ideas? or am i getting something wrong with the editor?
thx
class MyComponent extends MonoBehaviour
{
public function MyComponent()
{
}
public var myClassArray:Array = new Array();
}
class MyClass extends Object
{
public function MyClass()
{
}
public var a:int = 4;
public var b:int = 3;
}
@CustomEditor(MyComponent)
class MyComponentEditor extends Editor
{
public function OnInspectorGUI()
{
var myComponent:MyComponent = target;
var myArray:Array = myComponent.myClassArray;
var arrayLength:int = myArray.length;
EditorGUILayout.BeginHorizontal();
myComponent.myClassArray.length = EditorGUILayout.IntField("MyClassA", arrayLength);
EditorGUILayout.EndHorizontal();
var i:int;
if (arrayLength != myComponent.myClassArray.length)
{
for (i = 0 ; i <myComponent.myClassArray.length; i++)
{
myComponent.myClassArray[i] = new MyClass();
}
Repaint();
}
for (i = 0 ; i <myComponent.myClassArray.length; i++)
{
EditorGUILayout.BeginHorizontal();
myComponent.myClassArray[i].a = EditorGUILayout.IntField("MyClass-a"+i, myComponent.myClassArray[i].a);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
myComponent.myClassArray[i].b = EditorGUILayout.IntField("MyClass-b"+i, myComponent.myClassArray[i].b);
EditorGUILayout.EndHorizontal();
}
}
}
I think the problem is that Unity does not store the Array in MyComponent. You can force Unity to do this by giving it the @SerializeField attribute.
If this does not work try using the other array declaration, as this is editable in the default inspector:
var myClassArray : MyClass[];
I think as a rule of thumb you can say that all fields that aren’t editable in the default inspector, do not get saved.
@Serialize didn’t help, because it was already public
using the other array definition did solve the problem however. I’ll post the animsystem as soon as i’m finished, perhaps someone can use it.
here is my code, drag the uvAnimationSystem on a gameobject, edit the settings and add the animations
then in the gamecode use
var animSystem:Animation = SystemgameObject.getComponent(AnimationSystem);
animSystem.PlayAnimation(AnimId.ANIM_MOVE_LOOP); to play the animation
cheerio, comments will be added later 
272630–9804–$uvanimation_666.unitypackage (5.33 KB)