Simple application of Unity OnDrawGizmos to draw circles

Editors and configuration tables each have their own advantages.
No matter how complicated the card game is, even if it is Fantasy Westward Journey, Westward Journey, or even Wow, it is no problem to use a watch. But for Honkai 3, or Devil May Cry, fighting games, the visual editor is the only option.
When the skills were first allocated in the early stage of development, the editor experience was better than the configuration table. But in the later stage, when I wanted to adjust a lot of skills, it was really "crying and screaming" (but then I thought if I made a tool to make the editor an import and export function for the configuration table (it can also be xml or json), it should be able to solve some problems). If the logic is clear enough, matching tables is the most efficient way to work, but the expressive ability of tables is too weak, and the special effect peaks (center points) of some skills are often not what they appear to be.
At present, our project uses configuration tables. A few days ago, when we were making a hero, we encountered a pitfall. The special effects center and the actual position center were not in the same place. Because we used configuration tables, it was particularly troublesome to debug, so I wrote a simple The visualization logic
insert image description here
uses Unity OnDrawGizmos.
OnDrawGizmos is a callback method in Unity, which is used to draw debugging graphics in the scene view to help developers visually debug the position, boundaries, paths and other information of game objects. These graphics will only be shown in the editor, not in the actual game being built. This is useful for debugging and scene layout.
code show as below

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletVisual : MonoBehaviour
{
    
    
    public float r = 3;

    private void OnDrawGizmos()
    {
    
    
        DrawCirCle(gameObject.transform.position, r);
    }
    private void DrawCirCle(Vector2 center,float Radius,int VertexCount=50)
    {
    
    
        float deltaTheta = (2f * Mathf.PI) / VertexCount;
        float theta = 0f;
        Vector3 oldPos = center;
        Debug.Log(oldPos);
        for (int i = 0; i < VertexCount + 1; i++)
        {
    
    
            Vector3 pos = new Vector3(Radius * Mathf.Cos(theta), Radius * Mathf.Sin(theta), 0f);
            Gizmos.DrawLine(oldPos, (Vector3)center + pos);
            Gizmos.color = Color.red;
            oldPos = transform.position + pos;

            theta += deltaTheta;
        }

    }
}

Some friends who wrote this may ask, why not use BoxCollider? Didn't he provide a visual line?
Because in actual projects, the objects we actually collide with are often data rather than entities. In the DrawCirCle function, we can pass in a set of vector2 vectors to view collisions "on data", which is useful for debugging configuration table writing skills. Useful, and you may want to draw some custom graphics in the scene view, not just simple collider shapes. For example, you may want to display a path, a trigger area, a virtual protection range, etc. in the scene. These requirements exceed the default functionality of BoxCollider, and you can use OnDrawGizmos to implement custom visualization.
Remember to enable Gizmos in SceneView.
insert image description here
This is it. . . . I searched all over the Internet for a simple question but there is no answer. I would like to record it here. I didn’t notice that Gizmos was closed in SceneView, so I never called it...

Guess you like

Origin blog.csdn.net/qq_45498613/article/details/132484471