/// <summary> /// Callback for the initialization of the MMUs /// </summary> /// <param name="initialized"></param> protected virtual void InitializingCallback(bool initialized) { if (initialized) { //Create a new instance of the remote cosimulation class if (this.UseRemoteCoSimulation) { this.CoSimulator = new RemoteCoSimulation(this.MMUAccess.MotionModelUnits.Find(s => s.Name == this.RemoteCoSimulationName), this.MMUAccess.ServiceAccess, this, null); } //Create the local co-simulator (directly integrated in Unity) else { this.CoSimulator = new LocalCoSimulation(this.MMUAccess.MotionModelUnits, this.MMUAccess.ServiceAccess, this); } if (this.AllowRemoteCoSimulationAccess) { if (MainThreadDispatcher.Instance == null) { Debug.LogError("Please add a MainTrhead Dispatcher to the scene in order to allow remote co simulation acess"); return; } //Must be executed on main thread MainThreadDispatcher.Instance.ExecuteBlocking(() => { //Get the settings in the parent object MMISettings settings = this.gameObject.GetComponentInParent <MMISettings>(); if (settings == null) { Debug.LogError("Please add the MMI settings to the UnitySceneAccess it is required to access the MMIRegisterAddress"); return; } try { //Start the remote co-simulation access for the given avatar this.coSimulationAccess = new CoSimulationAccess(this.CoSimulator, new MIPAddress(this.RemoteCoSimulationAccessAddress, this.RemoteCoSimulationAccessPort), new MIPAddress(settings.MMIRegisterAddress, settings.MMIRegisterPort)); this.coSimulationAccess.Start(); Debug.Log("Started remote co-simulation access"); } catch (Exception e) { Debug.LogError(e.Message); } }); } } else { this.statusText = "Problem at initializing MMUs"; Debug.LogError("Problem at initializing MMUs"); } }
/// <summary> /// Setup method for the MMIAvatar /// </summary> /// <param name="address">The address of the MMU server</param> /// <param name="sessionId">A unique id for the session</param> /// <param name="avatarID">A unique id for the avatar</param> public virtual void Setup(string address, int port, string sessionId) { //Save the initial position and rotation Vector3 startPosition = this.transform.position; Quaternion startRotation = this.transform.rotation; //Setup the retargeting this.SetupRetargeting(); //Create the mmu access which creates the connection to the MMI framework this.MMUAccess = new MMUAccess(sessionId + ":" + this.MAvatar.ID) { //Set the scene access SceneAccess = GameObject.FindObjectOfType <UnitySceneAccess>(), //Define the retargeting here SkeletonAccess = this.GetSkeletonAccess(), }; //Set the id this.MMUAccess.AvatarID = this.MAvatar.ID; //Setthe status text this.statusText = "Connecting to MMUAccess " + address + ":" + port; //Connect asynchronously and wait for the result this.MMUAccess.ConnectAsync(new MIPAddress(address, port), TimeSpan.FromSeconds(this.Timeout), this.ConnectionCallback, this.MAvatar.ID); // Spawn Skeleton Access Service, if required. MMISettings settings = GetComponentInParent <MMISettings>(); if (settings.AllowRemoteSkeletonConnections) { //Start the remote skeleton access this.remoteSkeletonAccessServer = new RemoteSkeletonAccessServer(new MIPAddress(settings.RemoteSkeletonAccessAddress, settings.RemoteSkeletonAccessPort), new MIPAddress(settings.MMIRegisterAddress, settings.MMIRegisterPort), this.GetRetargetingService().GetSkeleton()); this.remoteSkeletonAccessServer.Start(); Debug.Log("Started Remote Skeleton Access Server with Avatar <" + this.AvatarID + ">"); } //Set the postion and rotation of the avatar to the desired one this.transform.position = startPosition; this.transform.rotation = startRotation; //Apply the transform manipulations to update the avatar location this.ApplyTransformManipulations(); }