Jump to content

[SOLVED] Unigine basic configurations. On mouse click behavior


photo

Recommended Posts

I am .NET developer and I am very new to Unigine.

Now I trying to understand how works wpf sample from SDK. I was able to deal with some of the things but not all.

Now I trying to figure out how can I change what happens when I click on Unigine viewport. In the SDK sample cursor is fixed on the viewport center and mouse start to control players view direction. When I press Esc cursor is released.

How can I change this behavior? I didn't find it in C# project. Is this in some script somewhere in data folder? Or it is just default behavior and I can change it in my C# project?

Link to comment

Hi!

You guessed right, the behavior of grabbing a cursor by a viewport is implemented in Unigine script.
You can find it in the default "system script" data/core/unigine.usc (it may have a .cpp extension in earlier SDK versions).

"System script" in Unigine terms is a script that has a lifetime of an engine instance.
It is loaded when the engine is initialized and is interpreted all the way through to the engine shutdown.
You cannot provide another system script "on the fly", or at least I don't know any way to do it.
Also, it must always be present, if the engine couldn't find a valid system script it just wouldn't run.
You can make the engine to use your custom system script, via a command-line argument "-system_script <path>".
When you omit this argument, the engine uses the default system script ("-system_script data/core/unigine.usc" is assumed).

I know three ways how to disable default cursor grabbing logic:

1. Write a completely custom system script and provide it to the engine via "-system_script" argument.
This way you discard all the logic provided by the default system script along with the cursor grabbing behavior.
This is a hard way, and most probably you won't do it since there is a lot of other useful stuff in the default system script.

2. Write a custom system script based on the default version and disable mouse grabbing.
This can be done by slightly modifying init() function:

int init()
{
	systemInit();

	// Disable default mouse grab logic.
	// May be called any time after systemInit().
	systemSetMouseUser(1);

	stereoInit();
	wallInit();

	return 1;
}

You, of course, will have to pass "-system_script <your_script>" argument to the engine in this case.

3. Pass "-extern_define MOUSE_USER" command-line argument to the engine.
The default system script will recognize it and disable mouse grab logic.
The difference from the previous method is that in this case, you can't change your mind and enable it back somewhere in the update() function.

You may also want to know that there are a "world script" and an "editor script" in Unigine.
More information about them and their correspondence to C++ and C# "Logic" classes can be found in this article: https://developer.unigine.com/en/docs/2.7.2/code/fundamentals/execution_sequence/app_logic_system?rlang=cpp

  • Like 1
Link to comment

I've just thought of maybe the best way.
You may add this line to AppSystemLogic.init() method:

Unigine.Engine.get().runSystemFunction(new Variable("systemSetMouseUser"), new Variable(1));

Requires no extra command-line arguments!

Link to comment

One more question:

I can not find description for systemSetMouseUser function in online documentation.

I would like to understand what other functions can be used. For example, how to change what happens when you press Esc. 

Is code for systemSetMouseUser function also somewhere in data folder?

Link to comment
  • silent changed the title to [SOLVED] Unigine basic configurations. On mouse click behavior
×
×
  • Create New...