예제 #1
0
        /// <summary>
        /// 自由物理驱动
        /// </summary>
        public void Auto()
        {
            var hRig = HeadHandler.GetComponent <Rigidbody>();
            var tRig = TailHandler.GetComponent <Rigidbody>();

            hRig.isKinematic = false;
            tRig.isKinematic = false;
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        /// <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);
        }