In the actual classes, not the trivial example above, they are much different from each other. Neither sharing a class nor inheritance makes any sense. These are helper classes and their scope should be limited. It’s what namespaces are for. But how namespaces and Unity’s JavaScript work is not clear or documented as far as I know.
It’d also be convenient if user-defined classes were in a different namespace than built-in Unity classes. I ran into problems when I inadvertently named a script the same as a built-in class.
In C# you can create a class within your class that inherits from MonoBehaviour, and its scope is contained in there. So it is possible to have a class in ClassA called the same thing as a separate class inside of ClassB. In Unity’s Javascript, your helper classes seem to be on the same scope as the implicit MonoBehaviour inheriting class created with the script. All I’m asking if there is any way to mimic what can be done with C# in this case.
ClassA.cs...
public class ClassA : MonoBehaviour {
[System.Serializable]
public class Helper {
public float bar;
}
public Helper foo;
}
ClassB.cs...
public class ClassB : MonoBehaviour {
[System.Serializable]
public class Helper {
public float foo;
public float bar;
}
public Helper foo;
}
ClassA.Helper and ClassB.Helper can peacefully coexist. Again, just an example here. Using namespace Foo { … } in C# isn’t the topic, here.