Skip to content

[Manual] Simple Path Generator

KimYC1223 edited this page Feb 3, 2022 · 8 revisions

๐ŸŒŠ Simple Path Visualizer

Unity Flow Visualizer's simple version

To be updated later

ํ•œ๊ตญ์–ด ์„ค๋ช…์€ ์•„๋ž˜์— ์žˆ์Šต๋‹ˆ๋‹ค.


1 . Overview

  • Expresses only the shortest straight line path by receiving two point (Vector3 or Transform)
  • Visualizer that can display the flow rate passing through the path

2. How to use

in Unity Scene, You should instantiate Assets\UnityFlowVisualizer\Prefabs\SimplePath\SimplePathGenerator prefabs (You only need one in the scene)

2-1. Set namespace

To use the Simple Path Visualizer, you must use the UnityFlowVisualizer namespace in your script.

using UnityFlowVisualizer;

2-2. Get SimplePathGenerator instance

In order to use the Simple Path Visualizer, you need to get an instance of SimplePathGenerator.

SimplePathGenerator simplePath = SimplePathGenerator.Instance;

At this time, if step 2 is not performed, SimplePathGenerator.Instance is null.

2-3. Make simple path

You can create a path connecting two points through the public GameObject InstantiatePath(...) function of SimplePathGenerator.

public GameObject InstantiatePath(...) is overloaded with the following 4 types.

  • public GameObject InstantiatePath(Transform Start, Transform End, Color PathColor, float Thickness = 1f);
  • public GameObject InstantiatePath(Vector3 Start, Vector3 End, Color PathColor, float Thickness = 1f);
  • public GameObject InstantiatePath(Transform Parent, Transform Start, Transform End, Color PathColor, float Thickness = 1f);
  • public GameObject InstantiatePath(Transform Parent, Vector3 Start, Vector3 End, Color PathColor, float Thickness = 1f);

A description of the parameters is as follows.

Parameter Description
Start The starting point of the Path (For Vector3, it must be World coordinates of the starting point)
End End point of Path (For Vector3, it must be World coordinates of the starting point)
Parent Path can be set as a child of that object
Color The color of the path. Alpha value can be applyed
Thickness The thickness of the path. Default 1

2-4. Flow visualize

Through the public GameObject Shooting(...) function of SimplePathGenerator, you can visualize the flow rate that flows through the path.

public GameObject Shooting(...) has the following three overloads.

  • public GameObject Shooting(SimplePath path, SHOT_TYPE type = SHOT_TYPE.FLOW_BLUE, float speed = 0.2f);
  • public GameObject Shooting(Transform start, Transform end, SHOT_TYPE type = SHOT_TYPE.FLOW_BLUE, float speed =0.2f);
  • public GameObject Shooting(Vector3 start, Vector3 end, SHOT_TYPE type = SHOT_TYPE.FLOW_BLUE, float speed = 0.2f);

A description of the parameters is as follows.

Parameter Description
Start The starting point of the Path (For Vector3, it must be World coordinates of the starting point)
End End point of Path (For Vector3, it must be World coordinates of the starting point)
path Path to be expressed.
type Type of flow particle. Default FLOW_BLUE
speed flow rate. Default 0.2

Here, SHOT_TYPE is an enum declared in SimplePathGenerator and is as follows.

public enum SHOT_TYPE {
    FLOW_RED, FLOW_GREEN, FLOW_BLUE,
    GAS_RED,  GAS_GREEN,  GAS_BLUE,
    ELEC_RED, ELEC_GREEN, ELEC_BLUE
}

2-5. Delete path

You can delete the created path through the public void DeletePath(SimplePath path) function of SimplePathGenerator.

2-6. Clear path

You can remove all generated paths through the public void ClearPath() function of SimplePathGenerator.

This is useful when you want to redraw the path.


Example

Here is a demo of SimplePathDemo.unity located in Assets\UnityFlowVisualizer\Demo.

The following test code was used.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityFlowVisualizer;    // UnityFlowVisualizer ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค ์‚ฌ์šฉ

public class SimplePathTest : MonoBehaviour
{
    public Transform StartTr;
    public Transform EndTr;
    public Color PathColor;

    // Start is called before the first frame update
    void Start()
    {
        // Draw path
        SimplePathGenerator.Instance.InstantiatePath(StartTr, EndTr, PathColor, 1f);

        // Visualize flow
        StartCoroutine(Shooting());
    }

    // Update is called once per frame
    IEnumerator Shooting()
    {
        while(true) {
            // Fires FLOW_BLUE at a speed of 0.2 every 0.7 seconds
            SimplePathGenerator.Instance.Shooting(StartTr, EndTr);
            yield return new WaitForSeconds(0.35f);
        }
    }
}






๐ŸŒŠ ์‹ฌํ”Œ ํŒจ์Šค ์ƒ์„ฑ๊ธฐ (๐Ÿ‡ฐ๐Ÿ‡ท Ver)

Unity Flow Visualizer์˜ ๊ฐ„๋‹จํ•œ ๋ฒ„์ „

์ถ”ํ›„ ๋” ์—…๋ฐ์ดํŠธ ์˜ˆ์ •


1 . ๊ฐœ์š”

  • ๋‘ ์ขŒํ‘œ(Vector3๋˜๋Š” Transform)์„ ์ž…๋ ฅ๋ฐ›์•„ ์ตœ๋‹จ๊ฑฐ๋ฆฌ ์ง์„  Path๋งŒ์„ ํ‘œํ˜„
  • Path๋ฅผ ์ง€๋‚˜๊ฐ€๋Š” ์œ ๋Ÿ‰์„ ํ‘œ์‹œ ํ•  ์ˆ˜ ์žˆ๋Š” Visualize

2. ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”๊ฐ€?

Unity Scene์—์„œ, Assets\UnityFlowVisualizer\Prefabs\SimplePath\SimplePathGeneratorํ”„๋ฆฌํŒน์„ ์ธ์Šคํ„ด์Šคํ™” ํ•ด์•ผํ•จ (Scene์— ํ•˜๋‚˜๋งŒ ์žˆ์œผ๋ฉด ๋จ)

2-1. ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค ์‚ฌ์šฉํ•˜๊ธฐ

Simple Path Visualizer๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ, ์Šคํฌ๋ฆฝํŠธ์—์„œ UnityFlowVisualizer ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•จ

using UnityFlowVisualizer;

2-2. SimplePathGenerator ์ธ์Šคํ„ด์Šค ๊ฐ€์ ธ์˜ค๊ธฐ

Simple Path Visualizer๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ, SimplePathGenerator ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€์ ธ์™€์•ผํ•จ

SimplePathGenerator simplePath = SimplePathGenerator.Instance;

์ด๋•Œ, 2๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š์•˜์œผ๋ฉด, SimplePathGenerator.Instance๋Š” null์ž„

2-3. ํŒจ์Šค ๋งŒ๋“ค๊ธฐ

SimplePathGenerator์˜ public GameObject InstantiatePath(...) ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋‘ ์ ์„ ์ž‡๋Š” Path๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ

public GameObject InstantiatePath(...)๋Š” ๋‹ค์Œ 4๊ฐ€์ง€๋กœ ์˜ค๋ฒ„๋กœ๋”ฉ๋˜์–ด ์žˆ๋‹ค.

  • public GameObject InstantiatePath(Transform Start, Transform End, Color PathColor, float Thickness = 1f);
  • public GameObject InstantiatePath(Vector3 Start, Vector3 End, Color PathColor, float Thickness = 1f);
  • public GameObject InstantiatePath(Transform Parent, Transform Start, Transform End, Color PathColor, float Thickness = 1f);
  • public GameObject InstantiatePath(Transform Parent, Vector3 Start, Vector3 End, Color PathColor, float Thickness = 1f);

ํŒŒ๋ผ๋ฏธํ„ฐ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค๋ช…
Start Path์˜ ์‹œ์ž‘ ์ง€์  (Vector3์ธ ๊ฒฝ์šฐ, ์‹œ์ž‘ ์ง€์ ์˜ World์ขŒํ‘œ์—ฌ์•ผ ํ•จ)
End Path์˜ ๋ ์ง€์  (Vector3์ธ ๊ฒฝ์šฐ, ์‹œ์ž‘ ์ง€์ ์˜ World์ขŒํ‘œ์—ฌ์•ผ ํ•จ)
Parent ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ์˜ ์ž์‹์œผ๋กœ Path๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Œ
Color Path์˜ ์ƒ‰์ƒ. Alpha๊ฐ’์„ ๋„ฃ์„ ์ˆ˜ ์žˆ์Œ
Thickness Path์˜ ๋‘๊ป˜. ๊ธฐ๋ณธ๊ฐ’ 1

2-4. ์œ ๋Ÿ‰ ์‹œ๊ฐํ™”

SimplePathGenerator์˜ public GameObject Shooting(...) ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด Path๋ฅผ ํ๋ฅด๋Š” ์œ ๋Ÿ‰์„ ์‹œ๊ฐํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค.

public GameObject Shooting(...)๋Š” ๋‹ค์Œ 3๊ฐ€์ง€๋กœ ์˜ค๋ฒ„๋กœ๋”ฉ๋˜์–ด ์žˆ๋‹ค.

  • public GameObject Shooting(SimplePath path, SHOT_TYPE type = SHOT_TYPE.FLOW_BLUE, float speed = 0.2f);
  • public GameObject Shooting(Transform start, Transform end, SHOT_TYPE type = SHOT_TYPE.FLOW_BLUE, float speed =0.2f);
  • public GameObject Shooting(Vector3 start, Vector3 end, SHOT_TYPE type = SHOT_TYPE.FLOW_BLUE, float speed = 0.2f);

ํŒŒ๋ผ๋ฏธํ„ฐ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค๋ช…
Start Path์˜ ์‹œ์ž‘ ์ง€์  (Vector3์ธ ๊ฒฝ์šฐ, ์‹œ์ž‘ ์ง€์ ์˜ World์ขŒํ‘œ์—ฌ์•ผ ํ•จ)
End Path์˜ ๋ ์ง€์  (Vector3์ธ ๊ฒฝ์šฐ, ์‹œ์ž‘ ์ง€์ ์˜ World์ขŒํ‘œ์—ฌ์•ผ ํ•จ)
path ํ‘œํ˜„ํ•˜๊ณ ์ž ํ•˜๋Š” Path.
type ์œ ๋Ÿ‰ Particle์˜ ์ข…๋ฅ˜. ๊ธฐ๋ณธ๊ฐ’ FLOW_BLUE
speed ์œ ๋Ÿ‰์˜ ์†๋„. ๊ธฐ๋ณธ๊ฐ’ 0.2

์—ฌ๊ธฐ์„œ SHOT_TYPE์€ SimplePathGenerator์— ์„ ์–ธ๋œ enum์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

public enum SHOT_TYPE {
    FLOW_RED, FLOW_GREEN, FLOW_BLUE,
    GAS_RED,  GAS_GREEN,  GAS_BLUE,
    ELEC_RED, ELEC_GREEN, ELEC_BLUE
}

2-5. ํŒจ์Šค ์‚ญ์ œ

SimplePathGenerator์˜ public void DeletePath(SimplePath path) ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ Path๋ฅผ ์ œ๊ฑฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.

2-6. ํŒจ์Šค ์ „์ฒด ์‚ญ์ œ

SimplePathGenerator์˜ public void ClearPath() ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ ๋ชจ๋“  Path๋ฅผ ์ œ๊ฑฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.

Path๋ฅผ ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹๋‹ค.


์‚ฌ์šฉ ์˜ˆ์ œ

๋‹ค์Œ์€ Assets\UnityFlowVisualizer\Demo์— ์žˆ๋Š” SimplePathDemo.unity ๋ฐ๋ชจ์ด๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์€ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityFlowVisualizer;    // UnityFlowVisualizer ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค ์‚ฌ์šฉ

public class SimplePathTest : MonoBehaviour
{
    public Transform StartTr;
    public Transform EndTr;
    public Color PathColor;

    // Start is called before the first frame update
    void Start()
    {
        // Path ๊ทธ๋ฆฌ๊ธฐ
        SimplePathGenerator.Instance.InstantiatePath(StartTr, EndTr, PathColor, 1f);

        // Flow ์‹œ๊ฐํ™”
        StartCoroutine(Shooting());
    }

    // Update is called once per frame
    IEnumerator Shooting()
    {
        while(true) {
            // 0.7์ดˆ๋งˆ๋‹ค FLOW_BLUE๋ฅผ ์†๋„ 0.2๋กœ ๋ฐœ์‚ฌ
            SimplePathGenerator.Instance.Shooting(StartTr, EndTr);
            yield return new WaitForSeconds(0.35f);
        }
    }
}