예제 #1
0
    void DrawNavMeshDebug()
    {
        if (!source.Agent)
        {
            return;
        }

        if (!source.Agent.hasPath || source.Agent.pathPending)
        {
            return;
        }

        Handles.color = Color.green;
        var pathPoints = source.Agent.path.corners;

        if (pathPoints.Length > 0)
        {
            for (int i = 0; i < pathPoints.Length; i++)
            {
                if (i > 0)
                {
                    Handles.DrawLine(pathPoints[i], pathPoints[i - 1]);
                }
            }

            EditorExtensions.DrawWireSphere(source.CurDestination, Quaternion.identity, 0.2f, Color.red);
        }
    }
예제 #2
0
    private void OnSceneGUI()
    {
        if (!source.pivot)
        {
            return;
        }

        Handles.color = Color.magenta;
        for (int i = 0; i < source.screenPoints.Length; i++)
        {
            Handles.DrawLine(source.screenPoints[i], source.pivot.position);
        }

        if (detectPivotCollision.boolValue)
        {
            Handles.zTest = UnityEngine.Rendering.CompareFunction.Less;
            EditorExtensions.DrawWireSphere(source.pivot.position, source.pivot.rotation, detectPivotRadius.floatValue, Color.red);
        }
    }
    public static void DrawDetectZone(SerializedProperty _detectZoneProperty, Transform _sourceTrans = null)
    {
        var worldPos          = _detectZoneProperty.FindPropertyRelative("worldPos");
        var detectType        = _detectZoneProperty.FindPropertyRelative("detectType");
        var offset            = _detectZoneProperty.FindPropertyRelative("offset");
        var angle             = _detectZoneProperty.FindPropertyRelative("angle");
        var size              = _detectZoneProperty.FindPropertyRelative("size");
        var radius            = _detectZoneProperty.FindPropertyRelative("radius");
        var height            = _detectZoneProperty.FindPropertyRelative("height");
        var positionType      = _detectZoneProperty.FindPropertyRelative("positionType");
        var trans             = _detectZoneProperty.FindPropertyRelative("trans");
        var transRoot         = trans.objectReferenceValue as Transform;
        var useTransformAngle = _detectZoneProperty.FindPropertyRelative("useTransformAngle");
        var debugColor        = _detectZoneProperty.FindPropertyRelative("debugColor");


        var pos = offset.vector3Value;

        if (positionType.enumValueIndex == (int)DetectZone.PositionType.World)
        {
            worldPos.vector3Value = Handles.PositionHandle(worldPos.vector3Value, Quaternion.Euler(angle.vector3Value));

            //get final position
            pos = worldPos.vector3Value + offset.vector3Value;
        }
        else if (positionType.enumValueIndex == (int)DetectZone.PositionType.Local && trans.objectReferenceValue)
        {
            pos = transRoot.TransformPoint(offset.vector3Value);
        }
        else if (positionType.enumValueIndex == (int)DetectZone.PositionType.Offset && _sourceTrans)
        {
            pos = _sourceTrans.TransformPoint(offset.vector3Value);
        }

        if (useTransformAngle.boolValue)
        {
            if (positionType.enumValueIndex == (int)DetectZone.PositionType.Local && trans.objectReferenceValue)
            {
                angle.vector3Value = transRoot.eulerAngles;
            }
            else if (positionType.enumValueIndex == (int)DetectZone.PositionType.Offset && _sourceTrans)
            {
                angle.vector3Value = _sourceTrans.eulerAngles;
            }
        }

        var rot = Quaternion.Euler(angle.vector3Value);
        var col = debugColor.colorValue;

        Handles.zTest = UnityEngine.Rendering.CompareFunction.Less;
        //draw the objects
        if (detectType.enumValueIndex == (int)DetectZone.DetectAreaType.Box)
        {
            EditorExtensions.DrawWireCube(pos, rot, size.vector3Value, col);
        }
        else if (detectType.enumValueIndex == (int)DetectZone.DetectAreaType.Sphere)
        {
            EditorExtensions.DrawWireSphere(pos, rot, radius.floatValue, col);
        }
        else if (detectType.enumValueIndex == (int)DetectZone.DetectAreaType.Capsule)
        {
            EditorExtensions.DrawWireCapsule(pos, rot, radius.floatValue, height.floatValue, col);
        }

        _detectZoneProperty.serializedObject.ApplyModifiedProperties();
    }