Exemplo n.º 1
0
    void OnGUI()
    {
        if (normalStyle == null)
        {
            normalStyle = new GUIStyle();
            normalStyle.normal.textColor = Color.red;
        }

        if (particleStyle == null)
        {
            particleStyle = new GUIStyle();
            particleStyle.normal.textColor = Color.green;
        }

        if (ragdollStyle == null)
        {
            ragdollStyle = new GUIStyle();
            ragdollStyle.normal.textColor = Color.white;
        }

        targetObj = (GameObject)EditorGUILayout.ObjectField("目标角色", targetObj, typeof(GameObject), true);
        if (targetObj != null)
        {
            ////init
            if (orignObj == null)
            {
                initParams(targetObj);
                orignObj = targetObj;
                return;
            }

            if (targetObj != orignObj)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayoutEx.Button("更换模型", Color.red))
                {
                    initParams(targetObj);
                    orignObj = targetObj;
                }

                if (GUILayoutEx.Button("恢复模型", Color.green))
                {
                    targetObj = orignObj;
                }
                EditorGUILayout.EndHorizontal();
                return;
            }

            useDismember = EditorGUILayout.Toggle("是否使用Dismember", useDismember);
            if (useDismember)
            {
                //////init components
                if (dismember == null)
                {
                    if (targetObj.GetComponent <Dismemberment>() == null)
                    {
                        dismember = targetObj.AddComponent <Dismemberment>();
                        CreateWithDefaultParam();
                    }
                    else
                    {
                        dismember = targetObj.GetComponent <Dismemberment>();
                    }
                    initParams(targetObj);
                }
            }

            if (ragdollManager == null)
            {
                //todo:动物布娃娃不初始化,只进行操作
                if (targetObj.GetComponent <RagdollManagerGen>() != null)
                {
                    ragdollManager = targetObj.GetComponent <RagdollManagerGen>();
                }
                else
                {
                    if (targetObj.GetComponent <RagdollManagerHum>() == null)
                    {
                        ragdollManager = targetObj.AddComponent <RagdollManagerHum>();
                        ragdollManager.onCreateCompeleted = CreateWithDefaultParam;
                        ((RagdollManagerHum)ragdollManager).DefaultInitialize();
                    }
                    else
                    {
                        ragdollManager = targetObj.GetComponent <RagdollManagerHum>();
                    }
                }
                initParams(targetObj);
            }

            //Copy from copyTarget
            copyTarget = (GameObject)EditorGUILayout.ObjectField("拷贝角色", copyTarget, typeof(GameObject), true);

            if (copyTarget != null && copyTarget.GetComponent <Dismemberment>() != null &&
                copyTarget.GetComponent <RagdollManagerHum>() != null && isCopying == false)
            {
                if (GUILayoutEx.Button("拷贝参数", Color.yellow))
                {
                    isCopying = true;
                }
            }
            if (isCopying == true)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayoutEx.Button("确认拷贝", Color.red))
                {
                    CopyParamFromTarget(targetObj, copyTarget);
                    initParams(targetObj);
                    copyParam = true;
                    isCopying = false;
                }
                if (GUILayoutEx.Button("恢复", Color.green))
                {
                    isCopying = false;
                }
                EditorGUILayout.EndHorizontal();
                return;
            }

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            if (useDismember)
            {
                //////Dismember
                GUILayout.Label("肢解设置", EditorStyles.boldLabel);

                limbTransRoot      = (Transform)EditorGUILayout.ObjectField("肢解根节点:", limbTransRoot, typeof(Transform), true);
                dismember.LimbRoot = limbTransRoot;

                dismemberNum = EditorGUILayout.IntField("肢解方案个数:", dismemberNum);
                if (dismemberNum != dismember.BoomParamsNum && !copyParam)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayoutEx.Button("确定更改方案数", Color.red))
                    {
                        dismember.BoomParamsNum = dismemberNum;
                    }
                    if (GUILayoutEx.Button("恢复方案数", Color.green))
                    {
                        dismemberNum = dismember.BoomParamsNum;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                //Scroll Dismember
                else
                {
                    copyParam = false;
                    if (dismemberNum > 0)
                    {
                        var boomParam = dismember.boomParam;
                        for (int i = 0; i < dismemberNum; i++)
                        {
                            string normalText = string.Format("-------------------------方案{0}-------------------------", i + 1);
                            EditorGUILayout.LabelField(normalText, normalStyle);
                            var temp = boomParam[i];
                            dismemberTarget[i]     = (GameObject)EditorGUILayout.ObjectField("被肢解目标:", dismemberTarget[i], typeof(GameObject), true);
                            temp.targetObj         = dismemberTarget[i];
                            dismemberColliders[i]  = (Collider)EditorGUILayout.ObjectField("肢解碰撞体:", dismemberColliders[i], typeof(Collider), true);
                            temp.collider          = dismemberColliders[i];
                            dismemberRigidbodys[i] = (Rigidbody)EditorGUILayout.ObjectField("被肢解目标:", dismemberRigidbodys[i], typeof(Rigidbody), true);
                            temp.rigidbody         = dismemberRigidbodys[i];
                            bodyPart[i]            = (Dismemberment.BodyPartHint)EditorGUILayout.EnumPopup("肢解部位:", bodyPart[i]);
                            temp.bodyPart          = (Dismemberment.BodyPartHint)bodyPart[i];

                            ////ignore Ragdoll Effect
                            //ignoreRagdollNum[i] = EditorGUILayout.IntField("忽略布娃娃效果个数:", ignoreRagdollNum[i]);

                            //if (ignoreRagdollNum[i] != temp.IgnoreRagdollEffectNum)
                            //{
                            //    EditorGUILayout.BeginHorizontal();
                            //    if (GUILayoutEx.Button("确定更改", Color.red)) temp.IgnoreRagdollEffectNum = ignoreRagdollNum[i];
                            //    if (GUILayoutEx.Button("恢复", Color.green)) ignoreRagdollNum[i] = temp.IgnoreRagdollEffectNum;
                            //    EditorGUILayout.EndHorizontal();
                            //}
                            //else
                            //{
                            //    copyParam = false;
                            //    if (ignoreRagdollNum[i] > 0)
                            //    {
                            //        for (int j = 0; j < ignoreRagdollNum[i]; j++)
                            //        {
                            //            string particleText = string.Format("-------------------------忽略{0}-------------------------", j + 1);
                            //            var ignoreRagdollParam = temp.ignoreRagdollTrans[j];
                            //            ignoreRagdollTrans[dismemberParamNum * i + j] = (Transform)EditorGUILayout.ObjectField("忽略布娃娃效果:", ignoreRagdollTrans[dismemberParamNum * i + j], typeof(Transform), true);
                            //            ignoreRagdollParam = ignoreRagdollTrans[dismemberParamNum * i + j];
                            //        }
                            //    }
                            //}

                            //particle
                            particleNum[i] = EditorGUILayout.IntField("特效个数:", particleNum[i]);

                            if (particleNum[i] != temp.ParticleNum && !copyParam)
                            {
                                EditorGUILayout.BeginHorizontal();
                                if (GUILayoutEx.Button("确定更改特效数", Color.red))
                                {
                                    temp.ParticleNum = particleNum[i];
                                }
                                if (GUILayoutEx.Button("恢复特效数", Color.green))
                                {
                                    particleNum[i] = temp.ParticleNum;
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                            else
                            {
                                copyParam = false;
                                if (particleNum[i] > 0)
                                {
                                    for (int j = 0; j < particleNum[i]; j++)
                                    {
                                        string particleText = string.Format("-------------------------特效{0}-------------------------", j + 1);
                                        EditorGUILayout.LabelField(particleText, particleStyle);
                                        var particleParm = temp.particles[j];
                                        particleNames[dismemberParamNum * i + j] = EditorGUILayout.TextField("特效名称", particleNames[dismemberParamNum * i + j]);
                                        particleParm.ParticleName = particleNames[dismemberParamNum * i + j];
                                        particleRoot[dismemberParamNum * i + j] = (Transform)EditorGUILayout.ObjectField("特效起始位置父节点:", particleRoot[dismemberParamNum * i + j], typeof(Transform), true);
                                        particleParm.particleRoot          = particleRoot[dismemberParamNum * i + j];
                                        initPos[dismemberParamNum * i + j] = EditorGUILayout.Vector3Field("特效初始位置:", initPos[dismemberParamNum * i + j]);
                                        particleParm.initPos = initPos[dismemberParamNum * i + j];
                                        initEurler[dismemberParamNum * i + j] = EditorGUILayout.Vector3Field("特效初始旋转位置:", initEurler[dismemberParamNum * i + j]);
                                        particleParm.initEurler = initEurler[dismemberParamNum * i + j];
                                        initScale[dismemberParamNum * i + j] = EditorGUILayout.Vector3Field("特效初始缩放:", initScale[dismemberParamNum * i + j]);
                                        particleParm.initScale = initScale[dismemberParamNum * i + j];
                                    }
                                }
                            }

                            //forceParam
                            forceNum[i] = EditorGUILayout.IntField("力参数个数:", forceNum[i]);

                            if (forceNum[i] != temp.ForceNum && !copyParam)
                            {
                                EditorGUILayout.BeginHorizontal();
                                if (GUILayoutEx.Button("确定更改特效数", Color.red))
                                {
                                    temp.ForceNum = forceNum[i];
                                }
                                if (GUILayoutEx.Button("恢复特效数", Color.green))
                                {
                                    forceNum[i] = temp.ForceNum;
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                            else
                            {
                                if (forceNum[i] > 0)
                                {
                                    for (int j = 0; j < forceNum[i]; j++)
                                    {
                                        string forceParamText = string.Format("-------------------------力参数{0}-------------------------", j + 1);
                                        EditorGUILayout.LabelField(forceParamText, particleStyle);
                                        var forceParam = temp.forceParams[j];
                                        drag[dismemberParamNum * i + j] = EditorGUILayout.FloatField("摩擦力:", drag[dismemberParamNum * i + j]);
                                        forceParam.drag = drag[dismemberParamNum * i + j];
                                        angleDrag[dismemberParamNum * i + j] = EditorGUILayout.FloatField("角动量摩擦力:", angleDrag[dismemberParamNum * i + j]);
                                        forceParam.angleDrag             = angleDrag[dismemberParamNum * i + j];
                                        force[dismemberParamNum * i + j] = EditorGUILayout.Vector3Field("速度:", force[dismemberParamNum * i + j]);
                                        forceParam.force = force[dismemberParamNum * i + j];
                                        torque[dismemberParamNum * i + j] = EditorGUILayout.Vector3Field("角速度:", torque[dismemberParamNum * i + j]);
                                        forceParam.torque = torque[dismemberParamNum * i + j];
                                    }
                                }
                            }


                            EditorGUILayout.BeginHorizontal();
                            forceMethod = EditorGUILayout.IntField("肢解力方案选择:1~10:", forceMethod);
                            if (GUILayoutEx.Button("测试肢解", Color.yellow))
                            {
                                dismember.TestDismember(i * 10 + forceMethod - 1);
                            }
                            //if (GUILayoutEx.Button("恢复", Color.green)) dismember.ReCoverOne(i * 10 + forceMethod - 1);
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
            }

            //////Ragdoll
            string ragdollText = string.Format("-------------------------布娃娃系统-------------------------");
            EditorGUILayout.LabelField(ragdollText, ragdollStyle);

            ragdollId    = EditorGUILayout.IntField("布娃娃受力点:", ragdollId);
            ragdollForce = EditorGUILayout.Vector3Field("布娃娃受力方向:", ragdollForce);

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("测试布娃娃"))
            {
                ragdollManager.DisableCustomRagdoll();
                var anim = targetObj.GetComponent <Animation>();
                if (anim != null)
                {
                    anim.enabled = false;
                }

                var characterControl = targetObj.GetComponent <CharacterController>();
                if (characterControl != null)
                {
                    characterControl.enabled = false;
                }

                ragdollManager.CustomRagdoll(ragdollId, ragdollForce);
            }

            if (GUILayout.Button("恢复布娃娃"))
            {
                ragdollManager.DisableCustomRagdoll();

                var anim = targetObj.GetComponent <Animation>();
                if (anim != null)
                {
                    anim.enabled = true;
                    anim.Play("idle");
                }

                var characterControl = targetObj.GetComponent <CharacterController>();
                if (characterControl != null)
                {
                    characterControl.enabled = true;
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            //综合方案
            method = EditorGUILayout.IntField("方案选择 : 11~90:", method);
            if (GUILayout.Button("走你"))
            {
                ragdollManager.DisableCustomRagdoll();
                var anim = targetObj.GetComponent <Animation>();
                if (anim != null)
                {
                    anim.enabled = false;
                }

                var characterControl = targetObj.GetComponent <CharacterController>();
                if (characterControl != null)
                {
                    characterControl.enabled = false;
                }

                dismember.TestDismember(Mathf.Clamp(method - 10 - 1, 0, 79));

                ragdollManager.CustomRagdoll(ragdollId, ragdollForce);
            }

            if (GUILayout.Button("恢复"))
            {
                ragdollManager.DisableCustomRagdoll();

                var anim = targetObj.GetComponent <Animation>();
                if (anim != null)
                {
                    anim.enabled = true;
                    anim.Play("idle");
                }

                var characterControl = targetObj.GetComponent <CharacterController>();
                if (characterControl != null)
                {
                    characterControl.enabled = true;
                }
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
        }
    }