Documentation for the Unity C# Library
Loading...
Searching...
No Matches
SessionController.cs
Go to the documentation of this file.
1using PixoVR.Apex;
2using System;
3using System.Net.Http;
4using UnityEngine;
5using UnityEngine.UI;
6
8{
9 public Button JoinSessionButton;
10 public Button EndSessionButton;
11 public Button SendEventButton;
12 public InputField RawScoreInput;
13 public InputField ScaledScoreInput;
14 public InputField MinScoreInput;
15 public InputField MaxScoreInput;
16 public InputField DurationInput;
17 public InputField EventNameInput;
18 public Toggle CompleteToggle;
19 public Toggle SuccessToggle;
20
21 void Start()
22 {
23 ApexSystem.Instance.OnLoginSuccess.AddListener(OnLoginSuccess);
24 ApexSystem.Instance.OnLoginFailed.AddListener(OnLoginFailed);
25 ApexSystem.Instance.OnJoinSessionSuccess.AddListener(OnSessionJoinedSuccess);
26 ApexSystem.Instance.OnJoinSessionFailed.AddListener(OnSessionJoinedFailed);
27 ApexSystem.Instance.OnCompleteSessionSuccess.AddListener(OnSessionCompletedSuccess);
28 ApexSystem.Instance.OnCompleteSessionFailed.AddListener(OnSessionCompletedFailed);
29 JoinSessionButton.interactable = false;
30 EndSessionButton.interactable = false;
31 SendEventButton.interactable = false;
32 }
33
35 {
36 JoinSessionButton.interactable = true;
37 EndSessionButton.interactable = false;
38 SendEventButton.interactable = false;
39 }
40
41 void OnLoginFailed(FailureResponse failedLoginResponse)
42 {
43 JoinSessionButton.interactable = false;
44 EndSessionButton.interactable = false;
45 SendEventButton.interactable = false;
46 }
47
48 void OnSessionJoinedSuccess(HttpResponseMessage joinResponse)
49 {
50 Debug.Log("We joined a session!");
51 EndSessionButton.interactable = true;
52 SendEventButton.interactable = true;
53 }
54
55 void OnSessionJoinedFailed(FailureResponse failedLoginResponse)
56 {
57 EndSessionButton.interactable = false;
58 SendEventButton.interactable = false;
59 }
60
61 void OnSessionCompletedSuccess(HttpResponseMessage joinResponse)
62 {
63 Debug.Log("We completed a session!");
64 EndSessionButton.interactable = false;
65 SendEventButton.interactable = false;
66 }
67
68 void OnSessionCompletedFailed(FailureResponse failedLoginResponse)
69 {
70 }
71
72 public void JoinSession()
73 {
74 var contextExtension = new PixoVR.Apex.XAPI.Extension();
75 contextExtension.AddSimple("Session Start Time", $"{DateTime.UtcNow}");
76 contextExtension.AddSimple("UserName", $"Hello World");
77 contextExtension.AddSimple("Mode", $"Mode");
78 ApexSystem.JoinSession($"DemoSessionID", contextExtension);
79 }
80
81 public void CompleteSession()
82 {
83 float raw = (float)System.Convert.ToDouble(RawScoreInput.text);
84 float scaled = (float)System.Convert.ToDouble(ScaledScoreInput.text);
85 float min = (float)System.Convert.ToDouble(MinScoreInput.text);
86 float max = (float)System.Convert.ToDouble(MaxScoreInput.text);
87 int duration = System.Convert.ToInt32(DurationInput.text);
88 ApexSystem.CompleteSession(new SessionData(raw, scaled, min, max, duration, CompleteToggle.isOn, SuccessToggle.isOn));
89 }
90
91 public void SendSessionEvent()
92 {
94 }
95}
static bool SendSimpleSessionEvent(string action, string targetObject, Extension contextExtension)
static bool JoinSession(string scenarioID=null, Extension contextExtension=null)
static bool CompleteSession(SessionData currentSessionData, Extension contextExtension=null, Extension resultExtension=null)
void AddSimple(string key, string value)
void OnSessionJoinedSuccess(HttpResponseMessage joinResponse)
void OnLoginFailed(FailureResponse failedLoginResponse)
void OnSessionCompletedSuccess(HttpResponseMessage joinResponse)
void OnSessionJoinedFailed(FailureResponse failedLoginResponse)
void OnSessionCompletedFailed(FailureResponse failedLoginResponse)
InputField ScaledScoreInput
void OnLoginSuccess(LoginResponseContent loginResponse)