void sendalivemsg() { if (m_client != null) { m_client.Send(m_serverAliveMsg); } }
void DoHandshake() { StopAllCoroutines(); serverIP = IPAddress.Parse(handshakeIP); GearData.handShakeIP = handshakeIP; try { //send handshake to server if (client != null) { client.Close(); client = new OSCClient(serverIP, GearData.RECEIVE_PORT); } else { client = new OSCClient(serverIP, GearData.RECEIVE_PORT); //handshake port is hardcoded } OSCMessage msg = new OSCMessage(HANDSHAKE, 0); client.Send(msg); StartCoroutine(RepeatHandshake(client, msg)); } catch (System.Exception e) { cancelRetry = true; DoError("Could not connect to handshake server: " + e.StackTrace); } }
// Update is called once per frame void Update() { var playerOnBase = Vector3.Project(Player.transform.position, _speakerBase); _playerOnBaseGameObject.transform.position = playerOnBase; _playerOnBaseGameObject.transform.Rotate(new Vector3(0f, 45f, 0f)); var i = 0; foreach (var source in _engine.Drops) { if (source == null) { return; } ComputeSpeakerValues(source); // Debug.Log("Senfind OSC ..."); //Start clip var packet = new OSCMessage("/live/play/clip"); packet.Append(_engine.ActualFamily); packet.Append(source.GetComponent <DropBehaviour>().Id); myClient.Send(packet); // /live/volume (int track, float volume(0.0 to 1.0)) packet = new OSCMessage("/live/volume"); packet.Append(source.GetComponent <DropBehaviour>().Id); packet.Append(Volume); myClient.Send(packet); // /live/master/pan (int track, float pan(-1.0 to 1.0)) Sets master track's pan to pan packet = new OSCMessage("/live/master/pan"); packet.Append(source.GetComponent <DropBehaviour>().Id); packet.Append(Pourcentage); myClient.Send(packet); i++; //var mouseDir = mousePos - charPos; //if (Vector3.Dot(right, mouseDir) < 0) //{ // //do right hand stuff //} //else //{ // //do left hand stuff //} //Player.transform.forward; } // Debug.Log(" Closest point : " + Vector3.Project(Player.transform.position, Speaker1.transform.position - Speaker2.transform.position)); }
/// <summary> /// Creates an OSC Client (sends OSC messages) given an outgoing port and address. /// </summary> /// <param name="clientId"> /// A <see cref="System.String"/> /// </param> /// <param name="destination"> /// A <see cref="IPAddress"/> /// </param> /// <param name="port"> /// A <see cref="System.Int32"/> /// </param> public void CreateClient(string clientId, IPAddress destination, int port) { if (m_DebugCreateNoServers) { return; } OSCClient newOSCClient = new OSCClient(destination, port); m_Clients.Add(newOSCClient); // Send test message string testaddress = "/test/alive/"; OSCMessage message = new OSCMessage(testaddress, destination.ToString()); message.Append(port); message.Append("OK"); //_clients[clientId].log.Add(String.Concat(DateTime.UtcNow.ToString(),".", // FormatMilliseconds(DateTime.Now.Millisecond), " : ", // testaddress," ", DataToString(message.Data))); //_clients[clientId].messages.Add(message); newOSCClient.Send(message); Debug.Log("Client created. " + clientId + ", " + destination.ToString() + ", " + port.ToString() + " Client count: " + m_Clients.Count); }
public static void Main(string[] args) { JObject settings = JObject.Parse(File.ReadAllText(@"..\..\settings.json")); int listenPort = settings["listenPort"].Value <int>(); string destination = settings["destination"].Value <string>(); int destinationPort = settings["destinationPort"].Value <int>(); bool verbose = settings["verbose"].Value <bool>(); OSCServer server = new OSCServer(listenPort); OSCClient client = new OSCClient(destination, destinationPort); server.DefaultOnMessageReceived += (sender, messageArgs) => { client.Send(messageArgs.Message); if (verbose) { Console.WriteLine(messageArgs.Message.ToString()); } }; Console.WriteLine("Listening on port " + listenPort + ", sending to " + destination + " on port " + destinationPort); while (true) { //do nothing } ; }
/// <summary> /// Send OSC message to client /// </summary> /// <param name="value">Value.</param> private void SendMessage(float value) { OSCMessage m = new OSCMessage("/unity_trigger1"); m.Append(value); client.Send(m); }
public void SendOSCMessage(int index, bool state) { // The format of the OSC message that ScreenPlay uses string _OSCAddress = "/1/push" + (index); OSCMessage msg = new OSCMessage(_OSCAddress, state ? 1.0f : 0.0f); _OSCClient.Send(msg); }
public void SendToNode(string address, object val) { try { OSCMessage message = new OSCMessage(address, val); client.Send(message); } catch (Exception e) { } }
private void Test() { client = new OSCClient(IPAddress.Parse("127.0.0.1"), listenPort); OSCMessage m = new OSCMessage("/testMessage"); client.Send(m); client.Flush(); client.Close(); client = null; }
/// <summary> /// Sends the specified MSG through OSC. /// </summary> /// <param name="msg">The MSG.</param> /// <param name="value">The value.</param> public void Send(string msg, object value) { if (_oscForCore.Host == null) { _oscForCore.Host = GetLocalIp(); _oscForCore.Port = 9000; } _oscForCore.Send(new OSCMessage(msg, value)); }
private void Send(OSCPacket packet) { try { client.Send(packet); } catch (Exception e) { Debug.LogWarning(e); } }
private void SendOSCData() { // calculate distances var handDistances = _fingers.Select(e => Vector3.Distance(palmCenter.transform.position, e.transform.position)).ToArray(); var msg = new OSCMessage("/wek/inputs"); foreach (var handDistance in handDistances) { msg.Append(handDistance); } _oscClient.Send(msg); }
void Send(string address, ArrayList arguments) { OSCMessage m = new OSCMessage(address); foreach (object argument in arguments) { m.Append(argument); } oscClient.Send(m); if (LogSentOscMessages) { Debug.Log($"Sent OSC Message: {m.ToString()}"); } }
public void Send(OSCPacket packet) { try { client.Send(packet); if (SendToLocalhostToo) { localhost.Send(packet); } } catch (Exception e) { Debug.Log(e); } }
void LateUpdate() { if (flyAround) { Vector3 newPos = center; newPos.x = Mathf.Cos(Time.time); newPos.z = Mathf.Sin(Time.time); transform.position = newPos; } OSCMessage msg = new OSCMessage("/rigidBody"); msg.Append(id); msg.Append(name); Vector3 pos = transform.position; Quaternion rot = transform.rotation; //position msg.Append(pos.x); msg.Append(pos.y); msg.Append(pos.z); //rotation (quat) msg.Append(rot.x); msg.Append(rot.y); msg.Append(rot.z); msg.Append(rot.w); //velocity msg.Append(0f); msg.Append(0f); msg.Append(0f); //angvelocity msg.Append(0f); msg.Append(0f); msg.Append(0f); //isActive msg.Append(1); //always active client.Send(msg); client.Flush(); }
// Use this for initialization void Start() { _audioSources = GameObject.FindGameObjectsWithTag("Audio"); _speakerBase = Speaker1.transform.position - Speaker2.transform.position; _playerOnBaseGameObject = new GameObject { name = "PlayerOnSpeakerBase" }; _sourceOnBaseGameObject = new GameObject { name = "AudioSourceOnSpeakerBase" }; _engine = this.GetComponent <Engine>(); myClient = new OSCClient(System.Net.IPAddress.Parse("127.0.0.1"), 9000); var packet = new OSCMessage("/live/name/track"); myClient.Send(packet); }
void Update() { switch (m_state) { case OSCInputState.WAIT_FOR_CONNECT: { sendservercount++; if (sendservercount >= sendserverinterval) { m_broadcastClient.Send(m_serverinfoMsg); sendservercount = 0; } break; } case OSCInputState.WAIT_FOR_CONFIRM: { if (m_client != null) { m_client.Send(m_serverOKMsg); } //发送10次确认信息后自动转入接收输入状态,而不等待客户端确认 confirmcount++; if (confirmcount >= 10) { confirmcount = 0; WaitforInput(); } break; } case OSCInputState.WAIT_FOR_INPUT: { m_aliveCount++; if (m_aliveCount >= m_aliveInterval) { m_aliveCount = 0; RemoveClientAndStopDoingAnything(null); } break; } } }
void OnCollisionEnter(Collision col) { bool isSphere = col.collider.tag == "Sphere"; // float vel = col.relativeVelocity; particleTrigger = true; GameObject obj = Instantiate(collisionParticles, transform.position, Quaternion.identity) as GameObject; // obj.GetComponent<ParticleSystem>(). Destroy(obj, (float)obj.GetComponent <ParticleSystem>().duration + 5f); // collisionParticles.GetComponent<ParticleSystem> (); if (oscClient != null && !collided && isSphere) { OSCMessage msg = new OSCMessage("/test", "killedSynth"); oscClient.Send(msg); Destroy(gameObject); collided = true; } }
/// <summary> /// Sends an OSC message. /// </summary> /// <param name="client">The OSC client to send from.</param> /// <param name="topic">The OSC topic.</param> /// <param name="values">The values to send.</param> public void SendOscMessage(OSCClient client, string topic, params object[] values) { if (shouldPrintDebugMessages) { Debug.LogFormat("sending message on {0}", topic); } OSCMessage msg = new OSCMessage(topic); foreach (object val in values) { Type val_type = val.GetType(); MethodInfo method = typeof(OSCMessage).GetMethod("Append"); MethodInfo generic = method.MakeGenericMethod(val_type); object[] valWrapped = new object[1]; valWrapped [0] = val; generic.Invoke(msg, valWrapped); } client.Send(msg); }
/// <summary> /// Sends a command to vrc /// </summary> /// <param name="command"></param> public async System.Threading.Tasks.Task SendMessageAsync(VrcCameraCommands command) { if (command == VrcCameraCommands.None) { return; } async Task sendMessage(float value) { OSCMessage message = new OSCMessage($"/riz/{command.ToString().ToLowerInvariant()}", value); logger.Debug($"{nameof(VrcOscSender)}.{nameof(this.SendMessageAsync)}: {nameof(command)} {command}. Message: {Encoding.UTF8.GetString(message.Bytes)}"); await oscClient.Send(message); } await sendMessage(1.0f); //on await Task.Delay(1000); await sendMessage(0.0f); //off }
Sprite LoadSprite(string fileName) { var imgPath = Path.Combine(Application.persistentDataPath, fileName); if (!File.Exists(imgPath)) { StartCoroutine(ShowInfoForFixedDuration("no " + fileName, 3, 30)); return(null); } var imgBytes = File.ReadAllBytes(imgPath); Texture2D tex = new Texture2D(1280, 720); tex.LoadImage(imgBytes, false); if (oscClient != null) { var msg = new OSCMessage("/image-loaded"); msg.Append(myIP); msg.Append(fileName); oscClient.Send(msg); } return(Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f)); }
public override void PrepareFrame(Playable playable, FrameData info) { double t = playable.GetTime(); client.Send(new OSCMessage("/time", (float)t)); }
public void SendToNode(string address, object val) { OSCMessage message = new OSCMessage(address, val); client.Send(message); }
void ExecuteOSCCmd(string address, List <System.Object> dataList) { int count = dataList.Count; if (address.Equals("/play-video")) { if (count > 0) { ResetVideoRelatedParams(); var url = dataList[0].ToString(); if (!url.Contains("http")) { if (url.Equals("-1")) { StopVideo(); DoNextCmd(); return; } var fileName = Path.GetFileName(url); var fullPath = Path.Combine(Application.persistentDataPath, fileName); url = "file://" + fullPath; if (!File.Exists(fullPath)) { StartCoroutine(ShowInfoForFixedDuration("no " + fileName, 3, 40)); return; } } var isLooping = false; int val = 0; if (count > 1) { float.TryParse(dataList[1].ToString(), out firstPlayStartPos); } if (count > 2) { float.TryParse(dataList[2].ToString(), out firstPlayStopPos); } if (count > 3 && int.TryParse(dataList[3].ToString(), out val)) { isLooping = val == 1; } if (count > 4) { float.TryParse(dataList[4].ToString(), out loopingStartPos); } if (count > 5) { float.TryParse(dataList[5].ToString(), out loopingStopPos); } PlayVideo(url, isLooping, false); } else { DoNextCmd(); } } else if (address.Equals("/stop-video")) { StopVideo(); DoNextCmd(); } else if (address.Equals("/pause-video")) { if (curPlayer != null) { curPlayer.Pause(); } DoNextCmd(); } else if (address.Equals("/continue-video")) { if (curPlayer != null && !curPlayer.isPlaying) { ResetVideoRelatedParams(); if (count > 0) { float.TryParse(dataList[0].ToString(), out firstPlayStopPos); if (firstPlayStopPos > 0) { stopFrame = (long)(curPlayer.frameCount * firstPlayStopPos); } } if (count > 1) { float.TryParse(dataList[1].ToString(), out loopingStartPos); } if (count > 2) { float.TryParse(dataList[2].ToString(), out loopingStopPos); } curPlayer.Play(); } else { DoNextCmd(); } } else if (address.Equals("/load-video")) { if (count > 0) { var url = dataList[0].ToString(); if (!url.Contains("http")) { if (url.Equals("-1")) { StopVideo(); return; } var fileName = Path.GetFileName(url); var fullPath = Path.Combine(Application.persistentDataPath, fileName); url = "file://" + fullPath; if (!File.Exists(fullPath)) { StartCoroutine(ShowInfoForFixedDuration("no " + fileName, 3, 40)); return; } } LoadVideo(url, true, false, OnVideoLoaded); } else { DoNextCmd(); } } else if (address.Equals("/download-file")) { if (count > 0) { var url = dataList[0].ToString(); var filename = Path.GetFileName(url); var filePath = Path.Combine(Application.persistentDataPath, filename); int val; bool testPlay = false; bool overwrite = true; bool interruptDuringDownload = false; if (count > 1 && int.TryParse(dataList[1].ToString(), out val)) { interruptDuringDownload = val == 1; } if (count > 2 && int.TryParse(dataList[2].ToString(), out val)) { overwrite = val == 1; } if (count > 3 && int.TryParse(dataList[3].ToString(), out val)) { testPlay = val == 1; } if (!overwrite && File.Exists(filePath)) { return; } if (downloadRoutine != null) { if (interruptDuringDownload) { StopCoroutine(downloadRoutine); } else { return; } } downloadRoutine = StartCoroutine(DownloadFileToPath(url, filePath, () => { var fileExist = File.Exists(filePath); if (!fileExist) { StartCoroutine(ShowInfoForFixedDuration("download failed", 3, 40)); return; } if (testPlay) { PlayVideo("file://" + filePath, false, false); } if (oscClient != null) { OSCMessage message = new OSCMessage("/download-done"); message.Append(myIP); message.Append(filename); message.Append(fileExist? "succeed" : "failed"); oscClient.Send(message); } DoNextCmd(); })); } else { DoNextCmd(); } } else if (address.Equals("/set-server")) { if (count > 1) { if (oscClient != null) { oscClient.Close(); oscClient = null; } targetServerIP = dataList[0].ToString(); if (int.TryParse(dataList[1].ToString(), out port)) { oscClient = CreateOSCClient(targetServerIP, port); var oscMsg = new OSCMessage("/set-server-response"); oscMsg.Append(myIP); oscMsg.Append("connected"); oscClient.Send(oscMsg); } DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/set-id")) { if (count > 0) { if (count > 1) { int val = 1; if (int.TryParse(dataList[1].ToString(), out val)) { info.enabled = val == 1; } } else { info.enabled = !info.enabled; } if (info.enabled) { info.fontSize = 90; int index = -1; int.TryParse(dataList[0].ToString(), out index); if (index >= 0 && index < dancerNames.Length) { info.text = dancerNames[index]; } else { info.text = dataList[0].ToString(); } } DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/set-effect-param")) { if (count > 0) { int effectIndex = -1; if (int.TryParse(dataList[0].ToString(), out effectIndex)) { if (effectIndex >= 0 && effectIndex < effectList.Length) { bool toRecord = false; int temp = 0; if (count > 1) { int.TryParse(dataList[1].ToString(), out temp); toRecord = temp == 1; EffectParamsRecording.EffectParams paramFrame = null; if (toRecord && paramRecording.state == EffectParamsRecording.State.Recording && curPlayer != null && curPlayer.isPlaying) { for (int i = 0; i < paramRecording.seq.Count; i++) { var frameData = paramRecording.seq[i]; if (frameData.effectIndex == effectIndex && frameData.videoFrame == curPlayer.frame) { paramFrame = frameData; break; } } if (paramFrame == null) { paramFrame = new EffectParamsRecording.EffectParams(); paramRecording.seq.Add(paramFrame); paramFrame.effectIndex = effectIndex; paramFrame.videoFrame = curPlayer.frame; } } var effect = effectList[effectIndex]; float val = -1; int paramIndex = -1; for (int i = 2; i < count;) { var data = dataList[i].ToString(); if (data.Equals("i")) { if ((i + 2) < count && int.TryParse(dataList[i + 1].ToString(), out paramIndex) && float.TryParse(dataList[i + 2].ToString(), out val)) { effect.SetParameter(paramIndex, val); if (paramFrame != null) { paramFrame.paramIndex.Add(paramIndex); paramFrame.paramVal.Add(val); } } i += 3; } else if (data.Equals("s")) { int startIndex = 0; int paramCount = 0; if ((i + 2) < count && int.TryParse(dataList[i + 1].ToString(), out startIndex) && int.TryParse(dataList[i + 2].ToString(), out paramCount)) { if (i + 2 + paramCount < count) { for (int k = 0; k < paramCount; k++) { if (float.TryParse(dataList[k + i + 3].ToString(), out val)) { paramIndex = startIndex + k; effect.SetParameter(paramIndex, val); if (paramFrame != null) { paramFrame.paramIndex.Add(paramIndex); paramFrame.paramVal.Add(val); } } } } } i += (3 + paramCount); } else { i++; } } effect.SetEffectActive(true); } } else { StartCoroutine(ShowInfoForFixedDuration("effectIndex out of bound", 3, 25)); } DoNextCmd(); } } else { DoNextCmd(); } } else if (address.Equals("/trigger-effect")) { if (count > 0) { int effectIndex = -1; if (int.TryParse(dataList[0].ToString(), out effectIndex)) { if (effectIndex >= 0 && effectIndex < effectList.Length) { paramRecording.Reset(); float duration = 1; float.TryParse(dataList[1].ToString(), out duration); var effect = effectList[effectIndex]; effect.ResetTriggerData(); effect.SetEffectRoutineDuration(duration); List <object> funcParamBuf = new List <object>(); for (int i = 2; i < count;) { int paramIndex = -1, patternID = -1, funcParamCount = -1; funcParamBuf.Clear(); int.TryParse(dataList[i].ToString(), out paramIndex); int.TryParse(dataList[i + 1].ToString(), out patternID); int.TryParse(dataList[i + 2].ToString(), out funcParamCount); if (paramIndex >= 0 && patternID >= 0 && funcParamCount > 0) { for (int k = 0; k < funcParamCount; k++) { funcParamBuf.Add(dataList[i + 3 + k].ToString()); } var paramFunc = ParamPattern.GetFunc( (ParamPattern.PatternType)patternID, funcParamBuf); effect.AddData(paramIndex, paramFunc); i = i + 3 + funcParamCount; } else { i += 3; } } effect.TriggerEffect(DoNextCmd); } else { StartCoroutine(ShowInfoForFixedDuration("effectIndex out of bound", 3, 25)); DoNextCmd(); } } } else { return; } } else if (address.Equals("/record-params")) { int policy = 0; if (count > 0) { int.TryParse(dataList[0].ToString(), out policy); } paramRecording.Reset(); paramRecording.state = EffectParamsRecording.State.Recording; if (curPlayer != null && curPlayer.url != null) { switch (policy) { case 0: //replay if (curPlayer.isPlaying) { PlayVideo(curPlayer.url, true, false); } break; case 1: //no replay if (!curPlayer.isPlaying) { PlayVideo(curPlayer.url, true, false); } break; case 2: //no action break; } } DoNextCmd(); } else if (address.Equals("/stop-recording")) { StopRecording(); DoNextCmd(); } else if (address.Equals("/clear-recording")) { paramRecording.Reset(); DoNextCmd(); } else if (address.Equals("/set-image")) { if (count > 0) { var imgName = dataList[0].ToString(); if (imgName.Equals("-1")) { stillImage.sprite = null; } else if (imgCache.ContainsKey(imgName)) { var img = imgCache[imgName]; stillImage.sprite = img; } else { var sprite = LoadSprite(imgName); if (sprite != null) { imgCache.Add(imgName, sprite); stillImage.sprite = sprite; } } if (count > 1) { float alpha = 0; if (float.TryParse(dataList[1].ToString(), out alpha)) { var color = stillImage.color; color.a = alpha; stillImage.color = color; stillImage.enabled = true; bgCanvas.enabled = true; } } DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/load-image")) { if (count > 0) { var imgName = dataList[0].ToString(); var img = LoadSprite(imgName); if (imgCache.ContainsKey(imgName)) { imgCache[imgName] = img; } else { imgCache.Add(imgName, img); } DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/disable-effect")) { if (count > 0) { if (dataList[0].ToString().Equals("-1")) { DisableAllEffect(); } else { for (int i = 0; i < count; i++) { int effectIndex = -1; if (int.TryParse(dataList[i].ToString(), out effectIndex)) { if (effectList.Length > effectIndex && effectIndex >= 0) { effectList[effectIndex].SetEffectActive(false); } } } } } paramRecording.Reset(); DoNextCmd(); } else if (address.Equals("/close-all")) { CloseAll(); DoNextCmd(); } else if (address.Equals("/show-text")) { if (count > 5) { TextManager.SentenceData sd = null; string content = dataList[0].ToString(); if (content.Equals("-1")) { sd = txtManager.GetRandSentenceData(); } else { sd = new TextManager.SentenceData(); sd.main = content; } TextManager.Orientation orient = TextManager.Orientation.Horizontal; int fontSize = 28; float posX = 0.5f; float posY = 0.5f; int effectIndex = 0; int val = 0; if (int.TryParse(dataList[1].ToString(), out val)) { orient = (TextManager.Orientation)val; } if (count > 2) { int.TryParse(dataList[2].ToString(), out fontSize); } if (count > 3) { float.TryParse(dataList[3].ToString(), out posX); } if (count > 4) { float.TryParse(dataList[4].ToString(), out posY); } if (count > 5) { int.TryParse(dataList[5].ToString(), out effectIndex); } dataBuf.Clear(); for (int i = 6; i < count; i++) { dataBuf.Add(dataList[i].ToString()); } txtManager.ShowText(sd, orient, fontSize, posX, posY, effectIndex, dataBuf); } else { txtManager.ShowText(); } DoNextCmd(); } else if (address.Equals("/set-brightness")) { if (count > 0) { int val = 0; if (int.TryParse(dataList[0].ToString(), out val)) { DeviceUtils.SetScreenBrightness(val); } } DoNextCmd(); } else if (address.Equals("/set-bg-color")) { if (count > 0) { float val = 0; Color color = Color.white; int i = 0; foreach (var valStr in dataList) { if (float.TryParse(valStr.ToString(), out val)) { if (i == 0) { color.r = val; } else if (i == 1) { color.g = val; } else if (i == 2) { color.b = val; } else { color.a = val; } } i++; } bg.color = color; DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/set-video-alpha")) { if (count > 0) { float alpha = 1; if (float.TryParse(dataList[0].ToString(), out alpha)) { var color = videoImage.color; color.a = alpha; videoImage.color = color; } DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/set-video-speed")) { if (count > 0) { float factor = 0; if (float.TryParse(dataList[0].ToString(), out factor)) { SetVideoSpeed(factor); } DoNextCmd(); } } else if (address.Equals("/set-start-pos")) { if (count > 0) { float val = -1; float.TryParse(dataList[0].ToString(), out val); SetLoopStartPos(val); DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/get-battery-level")) { if (oscClient != null) { if (oscClient != null) { OSCMessage message = new OSCMessage("/battery-level"); message.Append(SystemInfo.batteryLevel); oscClient.Send(message); } } DoNextCmd(); } else if (address.Equals("/set-text-effect-sentences-file")) { if (count > 0) { string path = GetTextFilePath(dataList[0].ToString()); if (!File.Exists(path)) { StartCoroutine(ShowInfoForFixedDuration("no such text file", 3, 25)); return; } else { PlayerPrefs.SetString(TextManager.sentenceInputPathKey, path); txtManager.ProcessInputData(File.ReadAllText(path)); } DoNextCmd(); } else { DoNextCmd(); } } else if (address.Equals("/reset-receiver")) { Debug.Log("reset receiver"); reciever.Close(); reciever = new OSCReciever(); reciever.Open(oscPort); DoNextCmd(); } //unused cmds else if (address.Equals("/set-canvas")) { if (count > 0) { int val = 1; if (int.TryParse(dataList[0].ToString(), out val)) { if (count > 1) { if (dataList[1].ToString().Equals("txt")) { txtCanvas.enabled = val == 1; } else { bgCanvas.enabled = val == 1; } } else { bgCanvas.enabled = val == 1; } } } else { return; } } else if (address.Equals("/set-camera")) { if (count > 0 && cam != null) { int val = 0; if (int.TryParse(dataList[0].ToString(), out val)) { cam.clearFlags = (CameraClearFlags)val; } } } else if (address.Equals("/cache-video")) { if (count > 0) { var url = dataList[0].ToString(); CacheVideoPlayer(url); } else { return; } } else if (address.Equals("/release-video")) { if (count > 0) { var url = dataList[0].ToString(); ReleaseVideoPlayer(url); } else { return; } } }
protected override void ApplyTransformUpdate(Vector3 position, Quaternion rotation) { //our gear if (name == handShakedName) { if (verticalWalking) { if (rBody == null) { rBody = t.GetComponent <Rigidbody>(); if (rBody == null) { rBody = t.gameObject.AddComponent <Rigidbody>(); rBody.useGravity = false; } } //snap to near-ground float yOffset = OptiTrackOSCClient.GetPosition().y; physicalY = position.y - yOffset; Vector3 objectPosition = t.position; //move object to correct X/Z position objectPosition.x = position.x; objectPosition.z = position.z; //raycast down from object RaycastHit hitInfo; //TODO: figure out if we need to raycast from closer to the floor (so we don't teleport on top of stuff too much) if (Physics.Raycast(objectPosition, -Vector3.up, out hitInfo, 2f, 1 << 8)) { objectPosition.y += (physicalY - hitInfo.distance); t.position = objectPosition; rBody.velocity = Vector3.zero; } else { t.position = objectPosition; if (canFall) { if (withAccelleration) { rBody.AddForce(-Vector3.up * 9.81f, ForceMode.Acceleration); } else { rBody.velocity = -3 * Vector3.up; } } } //send OSC Message for position OSCMessage m = new OSCMessage("/gear-virtualpos"); m.Append(name); m.Append(objectPosition.x); m.Append(objectPosition.y); m.Append(objectPosition.z); handshakeClient.Send(m); handshakeClient.Flush(); //when previewing in editor, apply rotation (Gear's handle this themselves) #if UNITY_EDITOR t.rotation = rotation; #endif } else { //TODO: test t.position = position; #if UNITY_EDITOR t.rotation = rotation; #endif } } //other player's gear else { if (verticalWalking) { //TODO: test //ignore y, but store it for reference float yOffset = OptiTrackOSCClient.GetPosition().y; physicalY = position.y - yOffset; Vector3 alternateP = t.position; alternateP.x = position.x; alternateP.z = position.z; t.position = alternateP; } else { //TODO: test //business as usual t.position = position; t.rotation = rotation; } } }
// Update is called once per frame void Update() { var emission = dustPS.emission; emission.rateOverTimeMultiplier = 40 + depth * 80; float meanExcitement = 0; float meanDiversity = 0; float meanDepth = 0; if (activeAudienceMembers.Count != 0) { foreach (KeyValuePair <int, GameObject> entry in activeAudienceMembers) { meanExcitement += entry.Value.GetComponent <Audience> ().excitement; meanDiversity += entry.Value.GetComponent <Audience> ().diversity; meanDepth += entry.Value.GetComponent <Audience> ().depth; } meanDepth = meanDepth / activeAudienceMembers.Count; meanDiversity = meanDiversity / activeAudienceMembers.Count; meanExcitement = meanExcitement / activeAudienceMembers.Count; } if (newSolo) { soloTime = Time.time + soloDur; newSolo = false; } if (Time.time > soloTime && solo) { solo = false; if (activeAudienceMembers.ContainsKey(soloID)) { activeAudienceMembers [soloID].GetComponent <Audience> ().solo = false; } else { print("WARNING attempted to remove solo from non-existant audience member"); } } if (solo) { if (activeAudienceMembers.ContainsKey(soloID)) { var soloist = activeAudienceMembers [soloID].GetComponent <Audience> (); soloist.solo = true; excitement = Mathf.Clamp(soloist.excitement, 0, 1); depth = Mathf.Clamp(soloist.depth, 0, 1); diversity = Mathf.Clamp(soloist.diversity, 0, 1); } else { print("WARNING attempted to give solo to non-existant audience member - Layer 3's set to normal values."); excitement = Mathf.Clamp((1 - coherence) * lcExcitement + coherence * meanExcitement, 0, 1); depth = Mathf.Clamp((1 - coherence) * lcDepth + coherence * meanDepth, 0, 1); diversity = Mathf.Clamp((1 - coherence) * lcDiversity + coherence * meanDiversity, 0, 1); } } else { excitement = Mathf.Clamp((1 - coherence) * lcExcitement + coherence * meanExcitement, 0, 1); depth = Mathf.Clamp((1 - coherence) * lcDepth + coherence * meanDepth, 0, 1); diversity = Mathf.Clamp((1 - coherence) * lcDiversity + coherence * meanDiversity, 0, 1); } // OSCMessage oscPack = new OSCMessage("/l3",excitement,depth,diversity); // float[] vals = new float[3]{excitement,depth,diversity}; // // create a byte array and copy the floats into it... // var byteArray = new byte[12]; // System.Buffer.BlockCopy(vals, 0, byteArray, 0, byteArray.Length); try{ scOSC.Send(new OSCMessage("/unityL3/excitement", excitement)); scOSC.Send(new OSCMessage("/unityL3/diversity", diversity)); scOSC.Send(new OSCMessage("/unityL3/depth", depth)); } catch (System.Exception e) { print("Warning, SC refusing OSC messages"); } if (newEvalText) { evalText.GetComponent <CodeFlash> ().textFlash(evalTextString); newEvalText = false; } camera.GetComponent <CameraScript>().excitement = excitement; drawLightSynths(); drawAmbientSynths(); drawBigSynths(); setRaveLights(); drawText(); drawAudienceMembers(); removeAudienceMembers(); //@fio what the real problem is here... try { updateAudienceObjects(); } catch (System.Exception e) { print("error updating audience..." + e); } nudgeAudience(); if (beatCount <= 0) { beat = 0; } else { beatCount = beatCount - 1; } excitementText.text = ("Excitement: " + string.Format("{0:N2}", excitement)); diversityText.text = ("Diversity: " + string.Format("{0:N2}", diversity)); depthText.text = ("Depth: " + string.Format("{0:N2}", depth)); } // End of update //////////////////////////////////////////////////////////////////////////////////////////////////////////