From Unity to Unigine. GameObject and Node

Opportunity uniform when creating a project, there is a choice between Api in C # and C ++. For a simple comparison, C# will be used (all examples will be equivalent for C++).

All game objects in the scene Unity are represented as a hierarchy of game objects of type GameObject. IN uniform every “game object” in the world is represented as a Node hierarchy.

world positioning

Each node in uniform (like the game object in Unity) can be located globally/locally, or be a parent/child node of another object.

IN uniform world positioning is represented as a Transformation Matrix. The matrix is ​​a 3*4 table.

The first three columns show the directions of the local axes and the size relative to the origin.  The last column is a position relative to world coordinates.
The first three columns show the directions of the local axes and the size relative to the origin. The last column is a position relative to world coordinates.

More about Matrix Transforms

Unity

uniform

transform.position(transform.localPosition)

node.WorldPosition(node.Position)

transform.rotation(transform.localRotation)

node.GetWorldRotation(node.GetRotation)

transform.localScale

node.WorldScale (node.Scale)

//Пример изменения позиции ноды с поворотом в направлении перемещения с использованием Матрицы Преобразования
node.WorldTransform = MathLib.SetTo(newPosition, newPosition + direction, vec3.UP, MathLib.AXIS.Y);

Parent and child nodes

Each node keeps a list of child nodes as well as a link to the parent node, which creates a hierarchy in the world.

Unity

uniform

transform.childCount

node.NumChildren

transform parent

node.Parent

transform.GetChild(index)

node.GetChild(index)

transform.SetParent(transform)

node.SetWorldParent(node)

Node hierarchy
Node hierarchy
//Пример удаления всех дочерних нод
for(int i = 0; i < node.NumChildren; i++)
  node.GetChild(i).DeleteLater();

More on Parent/Child Transforms

Component system

Nodes come in different types, but each contains a list of changing components. Each component must inherit from the Component class and during the program cycle, all the main methods of the component (Init, Update, Shutdown) will be called in the order they were added to Node Components.

List of components of a node of type PlayerActor
List of components of a node of type PlayerActor

The component system can be turned on and off while the application is running. In the C# SDK, the component system enabled by defaultbut disabled in C++.

Unigine::ComponentSystem::get()->initialize(); //Включает Компонентную систему C++
Unigine.ComponentSystem.SetEnabled(false); //Выключает Компонентную систему C#

Node components, like a game object in Unity, are accessed using the GetComponent() method, where T is the component type. It is also possible to add components to the node using the AddComponent() method and remove the RemoveComponent() method.

//Пример взаимодействия с компонентами
node.AddComponent<TestComponent>();

TestComponent testComponent = node.GetComponent<TestComponent>();
testComponent.TestMethod( DateTime.UtcNow );

node.RemoveComponent<TestComponent>();

More about the Component System

Finding Nodes and Components

There are times when, during the execution of an application, it is necessary to find a node according to certain criteria. This approach NOT RECOMMENDED when searching in a world where there are many nodes.

Unity

uniform

GameObject Find(string)

World.GetNodeByName(string)

GameObject.FindObjectsOfType

FindComponentsInWorld

transform Find(string)

node.FindNode(string)

//Поиск компонента в мире
CharacterController characterController = FindComponentInWorld<CharacterController>();
characterController.SetPlayer( node as Player );

Creating and deleting nodes

Creating a new node is done in two ways: creating a node from scratch or creating an instance of it.

Unity

uniform

GameObject.Instantiate(GameObject)

node.Clone() or World.LoadNode(string)

GameObject.Destroy(GameObject)

node.DeleteLater()

//Пример клонирования ноды
Node cloneNode = node.Clone();

for(int i = 0; i < cloneNode.NumChildren; i++)
  cloneNode.GetChild(i).DeleteLater();

Unigine official site

Documentation

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *