예제 #1
0
    private void UnDo(int boomId)
    {
        BoomParams tempParam = boomParam[boomId];
        GameObject go        = tempParam.targetObj;

        tempParam.collider.enabled      = true;
        tempParam.rigidbody.isKinematic = true;
        go.transform.SetParent(boomParam[boomId].parentTrans);
        go.transform.localPosition = tempParam.position;
        go.transform.localRotation = tempParam.rotation;
        go.transform.localScale    = tempParam.scale;

        tempParam.collider.enabled      = false;
        tempParam.rigidbody.isKinematic = true;

        //for (int i = 0; i < tempParam.ignoreRagdollTrans.Count; i++)
        //{
        //    ragdollManager.SetIgnoreRagdoll(tempParam.ignoreRagdollTrans[i], false);
        //}

        if (tempParam.mainJoint)
        {
            tempParam.mainJoint.connectedBody = tempParam.jointRigidbody;
            var collider  = tempParam.mainJoint.GetComponent <Collider>();
            var rigidbody = tempParam.mainJoint.GetComponent <Rigidbody>();
            if (collider && rigidbody)
            {
                collider.enabled      = false;
                rigidbody.isKinematic = true;
                rigidbody.useGravity  = false;
            }
        }
    }
예제 #2
0
    private void UnDo(int boomId)
    {
        BoomParams tempParam = boomParam[boomId];
        GameObject go        = tempParam.targetObj;

        tempParam.collider.enabled      = true;
        tempParam.rigidbody.isKinematic = true;
        go.transform.SetParent(boomParam[boomId].parentTrans);
        go.transform.localPosition = tempParam.position;
        go.transform.localRotation = tempParam.rotation;
        go.transform.localScale    = tempParam.scale;

        tempParam.collider.enabled      = false;
        tempParam.rigidbody.isKinematic = true;

        for (int i = 0; i < tempParam.ignoreRagdollTrans.Count; i++)
        {
            ragdollManager.SetIgnoreRagdoll(tempParam.ignoreRagdollTrans[i], false);
        }

        if (WeaponObj != null)
        {
            for (int i = 0; i < WeaponObj.Count; i++)
            {
                WeaponObj[i].UnDo();
            }
        }
    }
예제 #3
0
    private Transform SetIgnoreRagdoll(BoomParams boomParam)
    {
        Transform root = boomParam.targetObj.transform;

        if (root.GetComponent <CharacterJoint>() != null)
        {
            boomParam.ignoreRagdollTrans.Add(root);
        }

        Stack <Transform> trans = new Stack <Transform>();

        trans.Push(root);
        while (trans.Count > 0)
        {
            var temp = trans.Pop();
            for (int i = 0; i < temp.childCount; i++)
            {
                var childTrans = temp.GetChild(i);
                if (childTrans.GetComponent <CharacterJoint>() != null)
                {
                    boomParam.ignoreRagdollTrans.Add(childTrans);
                }

                trans.Push(childTrans);
            }
        }

        return(null);
    }
예제 #4
0
    //private Transform SetIgnoreRagdoll(BoomParams boomParam)
    //{
    //    Transform root = boomParam.targetObj.transform;
    //    if(root.GetComponent<CharacterJoint>() != null)
    //    {
    //        boomParam.ignoreRagdollTrans.Add(root);
    //    }

    //    Stack<Transform> trans = new Stack<Transform>();
    //    trans.Push(root);
    //    while (trans.Count > 0)
    //    {
    //        var temp = trans.Pop();
    //        for (int i = 0; i < temp.childCount; i++)
    //        {
    //            var childTrans = temp.GetChild(i);
    //            if(childTrans.GetComponent<CharacterJoint>() != null)
    //            {
    //                boomParam.ignoreRagdollTrans.Add(childTrans);
    //            }

    //            trans.Push(childTrans);
    //        }
    //    }

    //    return null;
    //}

    /// <summary>
    /// 设置肢解Child MainJoint
    /// </summary>
    public void SetDismemberChildJoint(BoomParams boomParam)
    {
        Transform root = boomParam.targetObj.transform;

        for (int i = 0; i < root.childCount; i++)
        {
            var childTrans = root.GetChild(i);
            if (childTrans.GetComponent <CharacterJoint>() != null)
            {
                boomParam.mainJoint = childTrans.GetComponent <CharacterJoint>();
                break;
            }
        }
    }
예제 #5
0
    private void Do(int boomId, int forceId, bool useEffect = true)
    {
        if (boomId >= boomParam.Count)
        {
            return;
        }

        BoomParams tempParam = boomParam[boomId];
        GameObject obj       = tempParam.targetObj;
        string     name      = obj.name;

        tempParam.parentTrans = obj.transform.parent;
        tempParam.position    = obj.transform.localPosition;
        tempParam.rotation    = obj.transform.localRotation;
        tempParam.scale       = obj.transform.localScale;
        obj.transform.SetParent(LimbRoot);
        if (null == onEffectOver)
        {
            onEffectOver = OnEffectOver;
        }
        var tempParticle = tempParam.particles;

        if (tempParticle != null && useEffect)
        {
            for (int i = 0; i < tempParticle.Count; i++)
            {
                var    temp   = tempParticle[i];
                Effect effect = Effect.PlayAttach(temp.ParticleName, temp.particleRoot,
                                                  (tempEffect) =>
                {
                    tempEffect.SetPos(temp.initPos, true);
                    tempEffect.SetRot(temp.initEurler, true);
                    tempEffect.SetScale(temp.initScale.x, temp.initScale.y, temp.initScale.z, true);
                    tempEffect.Play();
                }, onEffectOver);
                if (null == cachedEffect)
                {
                    cachedEffect = new Dictionary <int, Effect>();
                }
                cachedEffect.Add(effect.oid, effect);
            }
        }

        //rigidbody setting
        tempParam.collider.enabled      = true;
        tempParam.rigidbody.isKinematic = false;
        //force Params
        var drag = tempParam.forceParams[forceId].drag;

        tempParam.rigidbody.drag = Global.RandomRange(drag * (1 - rp.friction), drag * (1 + rp.friction));
        var angledrag = tempParam.forceParams[forceId].angleDrag;

        tempParam.rigidbody.angularDrag = Global.RandomRange(angledrag * (1 - rp.angleFriction), angledrag * (1 + rp.angleFriction));
        var force = transform.TransformDirection(tempParam.forceParams[forceId].force);

        tempParam.rigidbody.velocity = new Vector3(Global.RandomRange(force.x * (1 - rp.speed.x), force.x * (1 + rp.speed.x)),
                                                   Global.RandomRange(force.y * (1 - rp.speed.y), force.y * (1 + rp.speed.y))
                                                   , Global.RandomRange(force.z * (1 - rp.speed.z), force.z * (1 + rp.speed.z)));
        var torque = transform.TransformDirection(tempParam.forceParams[forceId].torque);

        tempParam.rigidbody.angularVelocity = new Vector3(Global.RandomRange(torque.x * (1 - rp.angleSpeed.x), torque.x * (1 + rp.angleSpeed.x)),
                                                          Global.RandomRange(force.y * (1 - rp.angleSpeed.y), torque.y * (1 + rp.angleSpeed.y))
                                                          , Global.RandomRange(torque.z * (1 - rp.angleSpeed.z), torque.z * (1 + rp.angleSpeed.z)));

        ////ignore ragdoll effect
        //for (int i = 0; i < tempParam.ignoreRagdollTrans.Count; i++)
        //{
        //    ragdollManager.SetIgnoreRagdoll(tempParam.ignoreRagdollTrans[i], true);
        //}

        //set limb joint
        if (tempParam.mainJoint)
        {
            tempParam.jointRigidbody          = tempParam.mainJoint.connectedBody;
            tempParam.mainJoint.connectedBody = tempParam.rigidbody;
            var collider  = tempParam.mainJoint.GetComponent <Collider>();
            var rigidbody = tempParam.mainJoint.GetComponent <Rigidbody>();
            if (collider && rigidbody)
            {
                collider.enabled      = true;
                rigidbody.isKinematic = false;
                rigidbody.useGravity  = true;
            }
        }
    }
예제 #6
0
    /// <summary>
    /// 默认参数
    /// </summary>
    public void InitDefaultParam()
    {
        boomParam.Clear();
        //Limb Root
        var temp = transform.Find("Limb");

        if (temp == null)
        {
            GameObject go = new GameObject("Limb");
            temp = go.transform;
            temp.transform.SetParent(transform);
        }

        LimbRoot = temp.transform;

        for (int i = 0; i < defaultCutName.Length; i++)
        {
            BoomParams tempParam = new BoomParams();

            var trans = transform.FindRecursive(defaultCutName[i]);
            if (trans == null)
            {
                Debug.LogError("Cant Find : " + defaultCutName[i]);
                continue;
            }

            tempParam.targetObj = transform.FindRecursive(defaultCutName[i]).gameObject;
            //碰撞体
            if (i != 0 && i != 1)
            {
                DestroyImmediate(tempParam.targetObj.GetComponent <Collider>());
            }
            var collider = tempParam.targetObj.GetComponent <Collider>();
            if (collider == null)
            {
                if (i == 0 || i == 1)
                {
                    collider = tempParam.targetObj.AddComponent <SphereCollider>();
                    var sphereCollider = collider as SphereCollider;
                    sphereCollider.radius = 0.14f;
                }
                else
                {
                    collider = tempParam.targetObj.AddComponent <CapsuleCollider>();
                    var cp = (CapsuleCollider)collider;
                    //小臂
                    if (i == 3 || i == 6)
                    {
                        cp.center = new Vector3(-0.1f, 0, 0);
                        cp.height = 0.44f;
                    }
                    //大腿
                    else if (i == 4 || i == 7)
                    {
                        cp.center = new Vector3(0, 0, 0);
                        cp.height = 0.55f;
                    }
                    //上臂
                    else
                    {
                        cp.center = new Vector3(0, 0, 0);
                        cp.height = 0.35f;
                    }

                    cp.radius    = 0.06f;
                    cp.direction = 0;
                }

                collider.enabled = false;
            }
            tempParam.collider = collider;

            var rigidbody = tempParam.targetObj.GetComponent <Rigidbody>();
            if (rigidbody == null)
            {
                rigidbody             = tempParam.targetObj.AddComponent <Rigidbody>();
                rigidbody.isKinematic = true;
            }
            tempParam.rigidbody = rigidbody;

            //particleParam
            if (tempParam.particles == null)
            {
                // head : (0,90,0), body : (0,-90,0)  pos-> (-0.25,0,0)
                tempParam.particles = new List <ParticleParms>(2);
                ParticleParms pp1 = new ParticleParms();
                pp1.ParticleName = "blood_head";
                pp1.particleRoot = tempParam.targetObj.transform;
                pp1.initPos      = Vector3.zero;
                pp1.initEurler   = new Vector3(0, 90, 0);
                pp1.initScale    = Vector3.one;

                ParticleParms pp2 = new ParticleParms();
                pp2.ParticleName = "blood_body";
                pp2.particleRoot = tempParam.targetObj.transform.parent;
                pp2.initPos      = new Vector3(-0.25f, 0, 0);
                pp2.initEurler   = new Vector3(0, -90, 0);
                pp2.initScale    = Vector3.one;

                //CUT_K
                if (i != 1)
                {
                    tempParam.particles.Add(pp1);
                    tempParam.particles.Add(pp2);
                }
                else
                {
                    tempParam.particles.Clear();
                }
            }

            //forceParam
            if (tempParam.forceParams == null)
            {
                tempParam.forceParams = new List <ForceParams>(4);
                for (int j = 0; j < 5; j++)
                {
                    ForceParams fp = new ForceParams();
                    tempParam.forceParams.Add(fp);
                    tempParam.forceParams[j].drag      = 0.1f;
                    tempParam.forceParams[j].angleDrag = 0.1f;
                    tempParam.forceParams[j].force     = new Vector3(0, 5, 0);
                    tempParam.forceParams[j].torque    = new Vector3(0, 5, 0);
                }
            }

            //设置Dismember MainJoint
            //大腿,上臂
            if (i == 2 || i == 4 || i == 5 || i == 7)
            {
                SetDismemberChildJoint(tempParam);
            }
            //tempParam.ignoreRagdollTrans = new List<Transform>();
            //SetIgnoreRagdoll(tempParam);
            boomParam.Add(tempParam);
        }
    }