コード例 #1
0
    private static void FindCollider(Transform root, Transform trans, GameColliderItem gameColliderItem)
    {
        int count = trans.childCount;

        for (int i = 0; i < count; i++)
        {
            var child = trans.GetChild(i);
            if (child.tag == "GameCollider" && gameColliderItem != null)
            {
                Collider collider = child.GetComponent <Collider>();
                if (collider != null)
                {
                    var scale = child.lossyScale;
                    collider.enabled = false;
                    if (scale.x != 1 || scale.y != 1 || scale.z != 1)
                    {
                        EditorUtility.DisplayDialog("提示", "child=" + child.name + "不能有缩放", "知道了");
                        return;
                    }
                    if (collider is SphereCollider)
                    {
                        SphereCollider     sphereCollider = (SphereCollider)collider;
                        CircleColliderData colliderData   = new CircleColliderData();
                        colliderData.name             = child.name;
                        colliderData.gameColliderType = GameColliderType.CircleCollider;
                        Vector3 center      = child.TransformPoint(sphereCollider.center);
                        var     localCenter = root.InverseTransformPoint(center);
                        colliderData.center = new TSVector(FP.FromFloat(localCenter.x), 0, FP.FromFloat(localCenter.z));
                        var localForward = child.forward;
                        colliderData.forward = new TSVector(FP.FromFloat(localForward.x), 0, FP.FromFloat(localForward.z));

                        colliderData.radius = FP.FromFloat(sphereCollider.radius);
                        gameColliderItem.mLstData.Add(colliderData);
                    }
                    else if (collider is BoxCollider)
                    {
                        BoxCollider      boxCollider  = (BoxCollider)collider;
                        RectColliderData colliderData = new RectColliderData();
                        colliderData.name             = child.name;
                        colliderData.gameColliderType = GameColliderType.RectCollider;
                        Vector3 center      = child.TransformPoint(boxCollider.center);
                        var     localCenter = root.InverseTransformPoint(center);
                        colliderData.center = new TSVector(FP.FromFloat(localCenter.x), 0, FP.FromFloat(localCenter.z));
                        var localForward = child.forward;
                        colliderData.forward    = new TSVector(FP.FromFloat(localForward.x), 0, FP.FromFloat(localForward.z));
                        colliderData.halfWidth  = FP.FromFloat(boxCollider.size.x / 2f);
                        colliderData.halfHeight = FP.FromFloat(boxCollider.size.z / 2f);
                        gameColliderItem.mLstData.Add(colliderData);
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("提示", "暂时不支持" + collider.GetType().ToString() + "碰撞框(请删除它再重试)", "知道了");
                        return;
                    }
                }
            }
            FindCollider(root, child, gameColliderItem);
        }
    }
コード例 #2
0
    private void OnCircleGUI(CircleColliderData colliderData)
    {
        EditorGUILayout.BeginHorizontal();
        var center = colliderData.center;

        EditorGUILayout.Vector3Field("\tcenter", new Vector3(center.x.AsFloat(), center.y.AsFloat(), center.z.AsFloat()));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        var forward = colliderData.forward;

        EditorGUILayout.Vector3Field("\tforward", new Vector3(forward.x.AsFloat(), forward.y.AsFloat(), forward.z.AsFloat()));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("\tradius", colliderData.radius.ToString());
        EditorGUILayout.EndHorizontal();
    }