Example #1
0
    public void ShowNodeItem(int layer_, LYRagdoll.BoneItemD node_)
    {
        if (node_ == null)
        {
            return;
        }
        string f = "";

        for (int i = 0; i < layer_; i++)
        {
            f += "  ";
        }
        f        += "|_";
        GUI.color = Color.white;
        Transform t = (Transform)EditorGUILayout.ObjectField(f + node_.boneName, node_.anchor, typeof(Transform), true);

        if (t != node_.anchor)
        {
            node_.anchor = t;
            LYRagdoll r = Selection.activeGameObject.GetComponent <LYRagdoll>();
            if (r != null)
            {
                r.OnDisable();
                r.OnEnable();
            }
        }

        for (int i = 0; i < node_.childLst.Count; i++)
        {
            ShowNodeItem(layer_ + 1, node_.childLst[i]);
        }
    }
Example #2
0
    void OnGUI()
    {
        uiScroll = EditorGUILayout.BeginScrollView(uiScroll, false, false, GUILayout.MinWidth(200), GUILayout.MaxWidth(position.width));

        if (Selection.activeGameObject != null && EditorApplication.isPlaying == true)
        {
            GUI.color = Color.green;
            if (GUILayout.Button("重新加载配置文件"))
            {
                LoadConfig();
            }
            GUI.color = Color.white;
            EditorGUILayout.Separator();

            string    curTemplateName = "";
            LYRagdoll r = Selection.activeGameObject.GetComponent <LYRagdoll>();
            if (r != null && r.RagdollItem != null)
            {
                curTemplateName = r.RagdollItem.name;
            }
            EditorGUILayout.LabelField("当前使用的模板:" + curTemplateName);

            if (GUILayout.Button("自动匹配"))
            {//自动匹配模板
                LYRagdollManager.Instance.Clear(Selection.activeGameObject);
                LYRagdollManager.Instance.Enable(Selection.activeGameObject);
            }

            EditorGUILayout.Separator();

            //选择模板
            if (LYRagdollManager.Instance.NodeLst.Count > 0)
            {
                int curIdx = LYRagdollManager.Instance.GetIndexByName(curTemplateName);
                int idx    = EditorGUILayout.Popup("选择模板:", curIdx, LYRagdollManager.Instance.NameLst.ToArray());
                if (idx != curIdx)
                {
                    LYRagdollManager.Instance.Clear(Selection.activeGameObject);
                    LYRagdollManager.Instance.EnableByNodeItem(Selection.activeGameObject, LYRagdollManager.Instance.NameLst[idx]);
                }
            }

            EditorGUILayout.Separator();

            if (GUILayout.Button("Disable Ragdoll"))
            {
                LYRagdollManager.Instance.Disable(Selection.activeGameObject);
            }

            if (r != null)
            {
                ShowNodeItem(0, r.RootItem);

                GUI.color = Color.green;
                if (GUILayout.Button("保存"))
                {
                    r.SaveXml(Application.dataPath + "/Editor/ragdollConfig/template/" + Selection.activeGameObject.name + ".xml", Selection.activeGameObject.name);
                    LoadConfig();
                }
            }
        }
        else
        {
            GUI.color = Color.red;
            if (EditorApplication.isPlaying == false)
            {
                GUILayout.Label("请先处于运行状态");
            }
            if (Selection.activeGameObject == null)
            {
                GUILayout.Label("请选择角色");
            }
        }

        EditorGUILayout.EndScrollView();
    }