/// <summary> /// 自由物理驱动 /// </summary> public void Auto() { var hRig = HeadHandler.GetComponent <Rigidbody>(); var tRig = TailHandler.GetComponent <Rigidbody>(); hRig.isKinematic = false; tRig.isKinematic = false; }
private void HangExternal() { _headSyncFromExt = _tailSyncFromExt = false; Rigidbody from, to; Vector3 fromAnchor, toAnchor; fromAnchor = toAnchor = Vector3.zero; float distance = _rawLength; if (_exTail != null)// 如果尾部挂接外部刚体 { from = _exTail; fromAnchor = _exTailOffset; _tailSyncFromExt = true; } else { from = TailHandler.GetComponent <Rigidbody>(); } if (_exHead != null)// 如果首部挂接外部刚体 { to = _exHead; toAnchor = _exHeadOffset; _headSyncFromExt = true; } else { to = HeadHandler.GetComponent <Rigidbody>(); } if (!_tailSyncFromExt && !_headSyncFromExt)// 如果两端没有挂接外部刚体 { _epJoint.xMotion = _epJoint.yMotion = _epJoint.zMotion = ConfigurableJointMotion.Limited; return; } else { _epJoint.xMotion = _epJoint.yMotion = _epJoint.zMotion = ConfigurableJointMotion.Free; if (_tailSyncFromExt) { ManualTail(true, false); } if (_headSyncFromExt) { ManualHead(true, false); } } JointRig(from, fromAnchor, to, toAnchor, distance, ref _exJoint); if (_headSyncFromExt && _tailSyncFromExt)// 如果两端都挂接了外部刚体,要让外部两个刚体可以碰撞 { _exJoint.enableCollision = true; } }
/// <summary> /// 手动控制尾部 /// </summary> /// <returns>尾部控制柄刚体</returns> public Rigidbody ManualTail(bool enable, bool exclusive = true) { var hRig = HeadHandler.GetComponent <Rigidbody>(); var tRig = TailHandler.GetComponent <Rigidbody>(); if (enable && exclusive) { hRig.isKinematic = false; } tRig.isKinematic = enable; return(tRig); }
/// <summary> /// 设置绳子与指定刚体是否可碰撞 /// </summary> public new void Ignore(Collider collider, bool ignore) { base.Ignore(collider, ignore); foreach (var c in HeadHandler.GetComponentsInChildren <Collider>()) { Physics.IgnoreCollision(collider, c, ignore); } foreach (var c in TailHandler.GetComponentsInChildren <Collider>()) { Physics.IgnoreCollision(collider, c, ignore); } }
public Handler CreateAndAttachHandlers() { var headHandler = new HeadHandler(); var optionsHandler = new OptionsHandler(); var fileHandler = new StaticFileHandler(); var controllerHandler = new ControllerHandler(); headHandler.SetSuccessor(optionsHandler); optionsHandler.SetSuccessor(fileHandler); fileHandler.SetSuccessor(controllerHandler); return(headHandler); }
public Handler CreateAndAttachHandlers() { var headHandler = new HeadHandler(); var optionsHandler = new OptionsHandler(); var fileHandler = new StaticFileHandler(); var controllerHandler = new ControllerHandler(); headHandler.SetSuccessor(optionsHandler); optionsHandler.SetSuccessor(fileHandler); fileHandler.SetSuccessor(controllerHandler); return headHandler; }
// for interactive testing... void Update() { if (Input.GetKeyDown(KeyCode.H) && head == null) { GameObject body = GameObject.Find("RigtestBody"); // already in scene head = HeadHandler.AddHead(body, "test/RigtestHead", "Neck"); } if (Input.GetKeyDown(KeyCode.J) && head != null) { GameObject body = GameObject.Find("RigtestBody"); // already in scene HeadHandler.RemoveHead(body, head); } }
public void CarHandlerTest() { CarHandler headHandler = new HeadHandler(); CarHandler bodyHandler = new BodyHandler(); CarHandler tailHandler = new TailHandler(); headHandler.SetNextHandler(bodyHandler).SetNextHandler(tailHandler); headHandler.Handler(); var chainList = ChainData.Instance().GetChainList(); Assert.True(chainList[0] == "Head" && chainList[1] == "Body" && chainList[2] == "Tail"); }
private void HandleConnection(Socket sock) { NetworkStream stream = new NetworkStream(sock); string line = null; bool error = false; bool keepAlive = false; DateTime startTime = DateTime.Now; sock.ReceiveTimeout = RequestHandler.Timeout * 100; sock.Blocking = false; sock.NoDelay = true; sock.SendBufferSize = 16 * 1024; sock.UseOnlyOverlappedIO = true; string type = ""; string path = ""; do { bool first = true; RequestHandler handler = null; do { line = null; try { line = ReadLine(stream); BytesReadHeader += line.Length + 2; } catch (ThreadAbortException e) { keepAlive = false; error = true; break; } catch (IOException e) { keepAlive = false; error = true; break; } catch (Exception e) { keepAlive = false; error = true; break; } /* connection timed out or closed */ if (line == null) { sock.Close(); LogRequest(" (Socket closed)"); return; } if (first) { LogRequest(" (Connection from " + sock.RemoteEndPoint + ")"); } LogRequest("< " + line); /* not an empty line? */ if (line != "") { /* the first line contains the request */ if (first) { if (line.Contains(' ')) { type = line.Substring(0, line.IndexOf(' ')); path = line.Substring(line.IndexOf(' ')).Trim(); try { switch (type) { case "OPTIONS": handler = new OptionsHandler(this, path); break; case "PROPFIND": handler = new PropFindHandler(this, path); break; case "GET": handler = new GetHandler(this, path); break; case "HEAD": handler = new HeadHandler(this, path); break; case "PUT": handler = new PutHandler(this, path); break; case "LOCK": handler = new LockHandler(this, path); break; case "UNLOCK": handler = new UnlockHandler(this, path); break; case "DELETE": handler = new DeleteHandler(this, path); break; case "MOVE": handler = new MoveHandler(this, path); break; case "COPY": handler = new CopyHandler(this, path); break; case "MKCOL": handler = new MkColHandler(this, path); break; case "PROPPATCH": handler = new PropPatchHandler(this, path); break; default: handler = new RequestHandler(this, "/"); break; } } catch (IOException e) { Log("[i] Connection from " + sock.RemoteEndPoint + " (" + type + ") had IOException"); } catch (Exception e) { Log("[E] '" + e.GetType().ToString() + "' in connection from " + sock.RemoteEndPoint + " (" + type + ")"); } } first = false; } else { try { handler.AddHeaderLine(line); } catch (IOException e) { /* just close */ sock.Close(); LogRequest(" (Socket closed)"); return; } catch (Exception e) { Log("[E] '" + e.GetType().ToString() + "' in connection from " + sock.RemoteEndPoint + " (AddHeaderLine)"); } //stream.Flush(); } } } while (line != ""); if (handler == null) { Log("[E] Empty request in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)"); handler.KeepAlive = false; return; } if (!error) { try { if (handler.RequestContentLength > 0) { handler.HandleContent(stream); } handler.HandleRequest(stream); stream.Flush(); } catch (FileNotFoundException e) { Log("[E] 404 '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)"); /* respond with error */ handler = new RequestHandler(this, "/"); handler.StatusCode = RequestHandler.GetStatusCode(404); handler.KeepAlive = false; handler.HandleRequest(stream); stream.Flush(); } catch (SocketException e) { Log("[E] '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)"); handler.KeepAlive = false; return; } catch (UnauthorizedAccessException e) { Log("[i] 403 '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)"); /* respond with error */ handler = new RequestHandler(this, "/"); handler.StatusCode = RequestHandler.GetStatusCode(403); handler.KeepAlive = false; handler.HandleRequest(stream); stream.Flush(); } catch (Exception e) { Log("[E] 500 '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)"); /* respond with error */ handler = new RequestHandler(this, "/"); handler.StatusCode = RequestHandler.GetStatusCode(500); handler.KeepAlive = false; handler.HandleRequest(stream); stream.Flush(); } if (EnableRequestLog) { DateTime endTime = DateTime.Now; Log("[i] Connection from " + sock.RemoteEndPoint + " (" + type + " " + path + ") took " + (endTime - startTime).TotalMilliseconds + " ms (" + handler.StatusCode + ")"); } LogRequest(""); lock (StatisticsLock) { BytesWrittenHeader += handler.BytesWrittenHeader; BytesWrittenData += handler.BytesWrittenData; BytesReadHeader += handler.BytesReadHeader; BytesReadData += handler.BytesReadData; } keepAlive = handler.KeepAlive; /* windows isnt really using keepalive :( */ keepAlive = false; } } while (keepAlive); sock.Close(); LogRequest(" (Socket closed)"); }