Exemple #1
0
        /// <summary>
        /// 取消对象绑定
        /// </summary>
        /// <param name="trans"></param>
        /// <param name="info"></param>
        /// <param name="bShadow"></param>
        private void UnbindObject(Transform trans, PassengerInfo info, bool bShadow)
        {
            if (null == trans)
            {
                return;
            }

            //获取角色实体组件
            CharacterEntity charEntity = trans.GetComponent <CharacterEntity>();

            if (null != charEntity)
            {
                charEntity.SetParent(null, false, "Tank");
            }
            else
            {
                trans.SetParent(null);
            }

            //恢复刚体的设置
            Rigidbody rigidbody = trans.GetComponent <Rigidbody>();

            if (bShadow)
            {
                rigidbody.constraints = info.shadowConstraints;
            }
            else
            {
                rigidbody.constraints = info.entityConstraints;
            }
            rigidbody.useGravity = true;

            //恢复角度
            trans.rotation = Quaternion.identity;

            //恢复碰撞体
            CapsuleCollider c = trans.GetComponent <CapsuleCollider>();

            if (c != null)
            {
                if (bShadow)
                {
                    c.isTrigger = info.isShadowColliderTrigger;
                }
                else
                {
                    c.isTrigger = info.isEntityColliderTrigger;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 玩家进入载具
        /// </summary>
        /// <param name="passenger"></param>
        /// <param name="seadIndex"></param>
        public bool PassengerEnter(Transform passenger, Transform shadow, int seatIndex)
        {
            if (seatIndex < 0 || seatIndex >= m_ListBones.Count)
            {
                Debug.LogError("进入载具失败,载具的座位不够!seatIndex=" + seatIndex);
                return(false);
            }

            //获取角色实体组件
            CharacterEntity charEntity = passenger.GetComponent <CharacterEntity>();

            if (charEntity == null)
            {
                return(false);
            }

            PassengerInfo info           = null;
            bool          infoExistAreay = false;

            if (m_dicPassengerInfo.ContainsKey(passenger))
            {
                info           = m_dicPassengerInfo[passenger];
                infoExistAreay = true;
            }
            else
            {
                info = new PassengerInfo();
                m_dicPassengerInfo.Add(passenger, info);
            }
            info.sid        = charEntity.sid;
            info.nSeatIndex = seatIndex;

            BindObject(passenger, seatIndex, info, false, infoExistAreay);
            if (null != shadow)
            {
                BindObject(shadow, seatIndex, info, true, infoExistAreay);
            }

            //设置处于载具状态
            charEntity.SetAniState(Ani.EnAniState.Tank);

            return(true);
        }
Exemple #3
0
        /// <summary>
        ///  绑定对象
        /// </summary>
        /// <param name="trans"></param>
        /// <param name="seatIndex"></param>
        /// <param name="info"></param>
        /// <param name="bShadow"></param>
        /// <param name="bInfoExistAreay"></param>
        private void BindObject(Transform trans, int seatIndex, PassengerInfo info, bool bShadow, bool bInfoExistAreay)
        {
            if (null == trans)
            {
                return;
            }

            //设置刚体
            Rigidbody rigidbody = trans.GetComponent <Rigidbody>();

            //保存刚体状态,后面用来恢复
            if (bShadow)
            {
                info.shadow = trans;
                if (!bInfoExistAreay)
                {
                    info.shadowConstraints = rigidbody.constraints;
                }
            }
            else
            {
                info.passenger = trans;
                if (!bInfoExistAreay)
                {
                    info.entityConstraints = rigidbody.constraints;
                }
            }

            //取消乘客的刚体动力学特性,使其可以进入载具
            rigidbody.constraints = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation;
            rigidbody.useGravity  = false;

            //修改碰撞提
            CapsuleCollider c = trans.GetComponent <CapsuleCollider>();

            if (c != null)
            {
                //保存碰撞触发设置
                if (!bInfoExistAreay)
                {
                    if (bShadow)
                    {
                        info.isShadowColliderTrigger = c.isTrigger;
                    }
                    else
                    {
                        info.isEntityColliderTrigger = c.isTrigger;
                    }
                }
                c.isTrigger = true;
            }

            //获取角色实体组件
            CharacterEntity charEntity = trans.GetComponent <CharacterEntity>();

            //绑定到载具上
            string    bindBoneName = m_ListBones[seatIndex] as string;
            Transform bone         = transform.Find(bindBoneName);

            if (bone == null)
            {
                Debug.LogError("PassengerEnter >> 没有找到对应的骨骼,直接绑定到0点!seatIndex=" + seatIndex + "; bone=" + bindBoneName);
                if (charEntity != null)
                {
                    charEntity.SetParent(transform, false, "Tank");
                }
                else
                {
                    trans.SetParent(transform, false);
                }
            }
            else
            {
                if (charEntity != null)
                {
                    charEntity.SetParent(bone, false, "Tank");
                }
                else
                {
                    trans.SetParent(bone, false);
                }
            }

            trans.localPosition = Vector3.zero;
            trans.localRotation = Quaternion.identity;
        }