Skip to content
Snippets Groups Projects
Commit 4ac7ff42 authored by Dr. phil. Stephen James Tobin's avatar Dr. phil. Stephen James Tobin
Browse files

Files and Folders set to original names with capitalization correction.

parent c75f882e
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 254 deletions
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TeachR.ApplicationManager;
using UnityEngine;
namespace TeachR.WebCommunication
{
/// <summary>
/// This class is intended to provide game objects for (controller) scripts.
/// It is used to check which components of the website should be available
/// and which should not.
/// </summary>
public class ControllerManager : MonoBehaviour
{
[SerializeField] private GameObject impulseController;
//[SerializeField] private GameObject behaviourController;
[SerializeField] private GameObject scenarioController;
[SerializeField] private GameObject speechToolsController;
[SerializeField] private GameObject labController;
[SerializeField] private GameObject ToAddMoreScriptsController;
//[SerializeField] private List<GameObject> controllerGameObjects = new ();
[SerializeField] private List<ControllerScriptEntry> controllerGameObjects = new();
public static ControllerManager instance;
private void Awake()
{
// Singleton
if (instance != null && instance != this)
Destroy(this);
else
{
instance = this;
InitGlobals.WebsocketInitHook += Init;
}
}
private Task Init()
{
controllerGameObjects.Add(new ControllerScriptEntry("ImpulseController", impulseController));
//controllerGameObjects.Add(new ControllerScriptEntry("BehaviourController", behaviourController));
controllerGameObjects.Add(new ControllerScriptEntry("ScenarioController", scenarioController));
controllerGameObjects.Add(new ControllerScriptEntry("SpeechToolsController", speechToolsController));
controllerGameObjects.Add(new ControllerScriptEntry("LabController", labController));
//controllerGameObjects.Add(new ControllerScriptEntry(" ", ToAddMoreScriptsController));
RegisterAvailableControllersHandler(CheckControllerStatus);
return Task.CompletedTask;
}
private void RegisterAvailableControllersHandler(Action<JsonMsg> handler)
{
//website can send "askForControllerAvailability"
Debug.Log($"Website asks for controllers");
CoachRtc.Persistent.On("askForControllerAvailability", handler);
}
private void SendControllerStatus()
{
// send the information to the website (as json)
var payload = new
{
controllers = controllerGameObjects.ConvertAll(controller => new
{
scriptName = controller.scriptName,
available = controller.available
})
};
Debug.Log($"SendControllerStatus() {controllerGameObjects.ToArray()}");
CoachRtc.Send("receiveControllerAvailability", payload);
}
/// <summary>
/// Updates the information about the controllers and then sends it to the website.
/// </summary>
/// <param name="message">Message is always null</param>
public void CheckControllerStatus(JsonMsg message = null)
{
foreach (var controller in controllerGameObjects)
{
// set the availability to true if the game object is provided, activated and contains the desired script.
controller.SetAvailability();
}
SendControllerStatus();
}
}
/// <summary>
/// Helper class to combine the controller scripts you are looking for,
/// the associated GameObjects in the scene and the availability status
/// in one structure.
/// </summary>
[System.Serializable]
public struct ControllerScriptEntry
{
public string scriptName;
public GameObject gameObject;
public bool available;
public ControllerScriptEntry(string script, GameObject container, bool available = false)
{
scriptName = script;
gameObject = container;
gameObject = container;
this.available = available;
}
/// <summary>
/// Checks whether a gameObject is specified, whether it is activated in the scene and,
/// if so, whether it has a script with the specified type.
/// </summary>
/// <returns>Returns true if the GameObject <see cref="gameObject"/> has
/// a script of type <see cref="scriptName"/>, otherwise false.</returns>
public void SetAvailability()
{
available = false;
// gameobject exists
if (gameObject)
{
// gameobject enabled
if (gameObject.activeSelf)
{
if (Type.GetType(scriptName) != null)
{
if (gameObject.GetComponent(scriptName))
{
available = true;
}
else
Debug.Log($"Will disable {scriptName}-functionailty on coach-website");
}
else
Debug.LogWarning($"No script with type {scriptName} known. Check for typo or maybe the namespace is not known.");
}
}
}
}
}
fileFormatVersion: 2
guid: b286769c8299aaa498f82eb23a36fa69
using System;
using UnityEngine;
namespace TeachR.WebCommunication
{
/// <summary>
/// Sync the position of the object this component is attached to.
/// </summary>
public class SyncPosition2D : MonoBehaviour
{
/// <summary>
/// Rate of the sync actions.
/// </summary>
public int frequency = 10; // 10 FPS
private Transform _transform;
[SerializeField]
private string id;
public string Id => id != "" ? id : name;
private void Awake()
{
_transform = transform;
}
private void OnEnable() => SyncPositionSystem.Add(this);
private void OnDisable() => SyncPositionSystem.Remove(this);
public Position2D ToPosition()
{
return new Position2D(_transform);
}
}
[Serializable]
public class Position2D
{
public float x, z, facingX, facingZ;
public Position2D(Transform t)
{
Vector3 position = t.position;
x = position.x;
z = position.z;
// TODO: Should this be an angle instead?
Vector3 forward = t.forward;
facingX = x + forward.x;
facingZ = z + forward.z;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 0e0313da9d028fc4aaad1a90c9fe7587
\ No newline at end of file
using System;
using TeachR.ApplicationManager;
using UnityEngine;
namespace TeachR.WebCommunication
{
public class WebsocketDelegateHooks : MonoBehaviour
{
/// <summary>
/// Action event that can be used to use the update functionality in non-monobehavior scripts.
/// </summary>
public static event Action OnUpdate;
/// <summary>
/// Action event that can be used to use the fixedUpdate functionality in non-monobehavior scripts.
/// </summary>
public static event Action OnFixedUpdate;
/// <summary>
/// Action event that can be used to use the lateUpdate functionality in non-monobehavior scripts.
/// </summary>
public static event Action OnLateUpdate;
[Obsolete] //Socketserver is deprecated
private void Awake()
{
DontDestroyOnLoad(gameObject);
InitGlobals.WebsocketInitHook += CoachRtc.Init;
}
// Update is called once per frame
void Update()
{
OnUpdate?.Invoke();
}
private void LateUpdate()
{
OnLateUpdate?.Invoke();
}
private void FixedUpdate()
{
OnFixedUpdate?.Invoke();
}
}
}
fileFormatVersion: 2
guid: 44f50844796000d4ca7505dcb3a46a81
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment