-
Notifications
You must be signed in to change notification settings - Fork 23
Voting and polling
The Unity plugin does support a way to do voting or polling via dynamic button creation. And example of voting would be if you have a choose your own adventure or a trivia game. In the case of the Trivia game, the simplest way to accomplish this would be to create one scene in Interactive Studio with buttons representing your poll choices. You can use set the InteractiveButtonControl.ButtonText property to update the text on those buttons when the question in the trivia game changes.
But what if you don't have a set number of button choices? You could create a different scene in Interactive Studio for each possible set of button choices. However, that may be difficult to manage if you have lots of different permutations.
A better solution could be dynamic scene creation. This feature allows you to create new scenes, update buttons on a scene on the fly. The way to do dynamic scene creation is:
-
Use the MixerInteractive.SendInteractiveMessage API to send the "updateScenes" message. This message takes the ID of the scene you want to update, the list of controls, and their properties. You can find the format for that message in the Protocol document.
-
If you want to, you can also listen for replies from the service that your scene update was successful by registering an event handler with the MixerInteractive.OnInteractiveMessageEvent event handler.
The following is an example of creating a button dynamically in code:
string message =
"{" +
" \"type\": \"method\"," +
" \"id\": 123," +
" \"method\": \"createControls\"," +
" \"params\": {" +
" \"sceneID\": \"default\"," +
" \"controls\": [{" +
" \"kind\": \"button\"," +
" \"controlID\": \"myAwesomeButton\"," +
" \"position\": [" +
" {" +
" \"size\": \"small\"," +
" \"x\": 10," +
" \"y\": 17," +
" \"width\": 13," +
" \"height\": 4" +
" }," +
" {" +
" \"size\": \"medium\"," +
" \"x\": 15," +
" \"y\": 9," +
" \"width\": 15," +
" \"height\": 4" +
" }," +
" {" +
" \"size\": \"large\"," +
" \"x\": 27," +
" \"y\": 5," +
" \"width\": 20," +
" \"height\": 8" +
" }" +
" ]," +
" \"text\": \"Hello World!\"," +
" \"cost\": 1" +
" }]" +
" }" +
"}";
MixerInteractive.SendInteractiveMessage(message);