romeu.thiago Posted March 21, 2014 Share Posted March 21, 2014 Hello, I would like to learn more about how to create classes coneito works ... I'm trying to create a class derived from Actor light to enter the scene with my property .... I still do not understand what it is for the. Cpp file and. H I'm trying to create an object of class ASpotLight I tried to create an object ASpotLight xlight; returned is more time talking about the construction of the object error .... Does anyone have any file running some modification on some object for me to understand how it works? Thank you! Link to comment
azagniy Posted April 10, 2014 Share Posted April 10, 2014 Hi, you can create user class derived from external class in a unigine script like this: #include <unigine.h> class MyObject : ObjectDummy { int variable; MyObject() : ObjectDummy() { variable = 10; } void setPosition(Vec3 pos) { log.message(__FUNC__ + ": %s\n",string(pos)); } }; int init() { MyObject object = new MyObject(); log.message(__FUNC__ + ": %d\n",object.variable); object.setPosition(Vec3_zero); return 1; } And you can define some methods like "setPosition" or others. But this class still a user class and you cant work with this class as external class. Also you cant work with it in a editor. So, this is a bad way to extend external classes. See more https://developer.unigine.com/en/docs/1.0/scripting/language/oop#inheritance_c If you really need extend external classes you can make a wrap user defined class which identical to external class like Unigine::Widgets (https://developer.unigine.com/en/docs/1.0/scripting/scripts/systems/unigine_widgets) You can do it like this: #include <unigine.h> class MyObject { ObjectDummy object; int variable; MyObject() { object = new ObjectDummy(); variable = 10; } void setPosition(Vec3 pos) { log.message(__FUNC__ + ": %s\n",string(pos)); object.setPosition(pos); } void setProperty(string name) { // do something // ... // object.setProperty(name); } }; int init() { MyObject my_object = new MyObject(); // add node to editor engine.editor.addNode(node_remove(my_object.object)); log.message(__FUNC__ + ": %d\n",my_object.variable); my_object.setPosition(Vec3_zero); return 1; } Link to comment
Recommended Posts