/// <summary> /// Updates client model associated with the given socket /// </summary> /// <param name="Client">Socket whose model needs to be updated</param> /// <param name="NewModel">New data as <see cref="InfoPackage"/></param> /// <returns>Original model that has been replaced</returns> private ClientModel UpdateClientModel(Socket Client, InfoPackage NewModel) { var originalModel = mClients[Client]; mClients[Client].Name = NewModel.ClientName; mClients[Client].LastName = NewModel.ClientSurname; mClients[Client].MachineName = NewModel.MachineName; return(originalModel); }
static void GetGroupChatInASync(RTMClient client, long groupId, int count, InfoPackage info = null) { const int countLimitation = 10; if (info == null) { info = new InfoPackage(); info.count = count; } bool status = client.GetGroupChat((int gotCount, long lastId, long beginMsec, long endMsec, List <HistoryMessage> messages, int errorCode) => { if (errorCode == com.fpnn.ErrorCode.FPNN_EC_OK) { info.beginMsec = beginMsec; info.endMsec = endMsec; info.lastId = lastId; info.beginMsec = beginMsec; info.fetchedCount += gotCount; info.count -= gotCount; DisplayHistoryMessages(messages); if (gotCount == countLimitation && info.count > 0) { GetGroupChatInASync(client, groupId, info.count, info); } else { Console.WriteLine("Get group history chat in group {0} in async completed. Fetched {1} items.", groupId, info.fetchedCount); } } else { Console.WriteLine("Fetch group history chat in group {0} in async failed. Fetched {1} items, error code: {2}", groupId, info.fetchedCount, errorCode); } }, groupId, info.desc, countLimitation, info.beginMsec, info.endMsec, info.lastId); if (status == false) { Console.WriteLine("Start fetch group history chat in group {0} in async failed.", groupId); } }
void Update() { /* * LineRenderer lineRenderer = GetComponent<LineRenderer>(); * Vector3[] points = new Vector3[lengthOfLineRenderer]; * float t = Time.time; * for (int i = 0; i < lengthOfLineRenderer; i++) * { * points[i] = new Vector3(penModel.transform.position.x + (i * 0.5f) / lengthOfLineRenderer, penModel.transform.position.y, penModel.transform.position.z); * } * lineRenderer.SetPositions(points); */ RaycastHit hit = new RaycastHit(); bool hitSomething = false; int layerMask = 1 << 8; layerMask = ~layerMask; //Debug.DrawRay(penModel.transform.position, penModel.transform.up * 30, Color.red, Time.deltaTime); //RaycastHit[] allrayHits; //allrayHits = Physics.SphereCastAll(penModel.transform.position, 0.01f, penModel.transform.up, 0.101f, layerMask); //Debug.Log(allrayHits.Length); Debug.DrawRay(penModel.transform.position, penModel.transform.up * 0.101f, Color.black); if (Physics.Raycast(penModel.transform.position, penModel.transform.up, out hit, 0.101f, layerMask)) { hitSomething = true; } else { for (int i = 0; i < meshVerticesWC.Length; i++) { Debug.DrawRay(penModel.transform.TransformPoint(meshVerticesWC[i]), penModel.transform.TransformDirection(meshNormals[i]) * 0.01f, Color.red); if (Physics.Raycast(penModel.transform.TransformPoint(meshVerticesWC[i]), penModel.transform.TransformDirection(meshNormals[i]), out hit, 0.01f, layerMask)) { hitSomething = true; break; } } } if (tempOldRayHit == false) { //if (Physics.Raycast(penModel.transform.position, penModel.transform.up, out hit, 0.101f, layerMask)) if (hitSomething) { Debug.Log("Did Hit"); oldInfoPackage = new InfoPackage { pos = penModel.transform.position, rayHitPoint = hit.point, rayHitDis = hit.distance, hitNormal = hit.normal }; tempOldRayHit = true; } } else { //if (Physics.Raycast(penModel.transform.position, penModel.transform.up, out hit, 0.101f, layerMask)) if (hitSomething) { Debug.Log(hit.transform.parent.name); newInfoPackage = new InfoPackage { pos = penModel.transform.position, rayHitPoint = hit.point, rayHitDis = hit.distance, hitNormal = hit.normal }; float fromOldtoNewDis = Vector3.Distance(oldInfoPackage.rayHitPoint, newInfoPackage.rayHitPoint); float fromOldOrigintoOldHit = oldInfoPackage.rayHitDis; float fromOldOrigintoNewHit = Vector3.Distance(oldInfoPackage.pos, newInfoPackage.rayHitPoint); angle = Mathf.Acos((fromOldOrigintoNewHit * fromOldOrigintoNewHit + fromOldOrigintoOldHit * fromOldOrigintoOldHit - fromOldtoNewDis * fromOldtoNewDis) / (2.0f * fromOldOrigintoNewHit * fromOldOrigintoOldHit)) * Mathf.Rad2Deg; for (int i = 0; i < anountOfRays; i++) { //for use later for faning out the ray from new ray pos towards old ray hit pos } float angleXNormals = Mathf.Max(0, Vector3.Dot(newInfoPackage.hitNormal, oldInfoPackage.hitNormal)); //Debug.Log(fromOldtoNewDis); if (angleXNormals <= 0.9f && istoutching && fromOldtoNewDis >= minMovement) { amplitudeHigh = Mathf.Max(minMovement, ((minMovement / fromOldtoNewDis))); vib.Execute(0, durationHigh, freqencyHigh, amplitudeHigh, thisHand); Debug.DrawRay(oldInfoPackage.rayHitPoint, oldInfoPackage.hitNormal, Color.blue, 0.5f); Debug.DrawRay(newInfoPackage.rayHitPoint, newInfoPackage.hitNormal, Color.green, 0.5f); } else if (istoutching && fromOldtoNewDis >= minMovement) { amplitudeLow = (minMovement / fromOldtoNewDis) * ((1f - angleXNormals) * multiplyer); //Debug.Log(((minMovement/fromOldtoNewDis))*0.1f); vib.Execute(0, Time.deltaTime * 0.9f, freqencyLow, amplitudeLow, thisHand); } Debug.DrawRay(penModel.transform.position, penModel.transform.up * hit.distance, Color.red, Time.deltaTime); } else { Debug.DrawRay(penModel.transform.position, penModel.transform.up * 30, Color.red, Time.deltaTime); } oldInfoPackage = newInfoPackage; } }