Get it on Google Play


Wm뮤 :: 유니티 파티클, 트레일, 라인 렌더러

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2023. 1. 21. 23:55 Unity

 

파티클의 startLifeTime

//읽을때
var startLifetime=particleEffect.main.startLifetime.constant;


//쓸때
var particleEffectMain = particleEffect.main;
var startLifetime = particleEffectMain.startLifetime;
startLifetime.constant = 설정할시간;
particleEffectMain.startLifetime = startLifetime;

 

파티클 텍스처 변경

var renderer = particle.GetComponent<Renderer>();
renderer.material.mainTexture = sprite.texture;

 

파티클 데이터 수정

//생성
{
    var particleSystem = GetComponent<ParticleSystem>();
    var particles = new ParticleSystem.Particle[100];
    for (int i = 0; i < particles.Length; i++)
    {
        particles[i] = new ParticleSystem.Particle();
        particles[i].position = new Vector3(0, i * 0.1f, 0);
        particles[i].startSize = particleSystem.main.startSize.Evaluate(0);
        particles[i].rotation3D = new Vector3(0, i * 10, 0);
    }
    particleSystem.SetParticles(particles);
}

//읽기
{
    var particleSystem = GetComponent<ParticleSystem>();
    var particles = new ParticleSystem.Particle[particleSystem.particleCount];
    particleSystem.GetParticles(particles);
    for (int i = 0; i < particles.Length; i++)
    {
        Debug.Log($"particles[{i}].position: {particles[i].position}");
        Debug.Log($"particles[{i}].rotation3D: {particles[i].rotation3D}");
        
        Debug.DrawLine(particles[i].position, particles[i].position+Quaternion.Euler(particles[i].rotation3D) * Vector3.forward*0.1f);
        Debug.DrawLine(particles[i].position, particles[i].position + Quaternion.Euler(particles[i].rotation3D) * Vector3.up * 0.1f);
        //Debug.Log($"Quaternion.Euler(particles[{i}].rotation3D): {Quaternion.Euler(particles[i].rotation3D)}");
    }
}

//수정
{
    var particleSystem = GetComponent<ParticleSystem>();
    var particles = new ParticleSystem.Particle[particleSystem.particleCount];
    particleSystem.GetParticles(particles);
    for (int i = 0; i < particles.Length; i++)
    {
        particles[i].position = new Vector3(0, i * 0.1f, 0);
    }
    particleSystem.SetParticles(particles);
}

 

 

 

라인렌더러 좌표를 트랜스폼들 좌표로 설정

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


#if UNITY_EDITOR

using UnityEditor;
[CustomEditor(typeof(TransformsLine))]
public class TransformsLineEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();//기본 인스펙터를 받아올때
        serializedObject.Update();
        {
            if (GUILayout.Button("Preview"))
            {
                ((FishingLine)target).SetLineRenderer();
            }
        }
        serializedObject.ApplyModifiedProperties();


    }
}

#endif

public class TransformsLine : MonoBehaviour
{

    public Transform[] transforms;
    public LineRenderer lineRenderer;
    // Start is called before the first frame update
    void Start()
    {
        lineRenderer = lineRenderer ?? GetComponent<LineRenderer>();
    }

    // Update is called once per frame
    public void SetLineRenderer()
    {
        if ((lineRenderer != null) && (transforms.Length > 0))
        {
            lineRenderer.SetPositions(System.Array.ConvertAll(transforms, transform => transform.position));
        }
    }
    // Update is called once per frame
    void Update()
    {
        SetLineRenderer();
    }
}

 

 

 

 

 

 

트레일 Positions 구조

//1번라인
(0: (-0.3, 0.7, 0.0))(1: (-0.3, 0.7, 0.0))(2: (-0.4, 0.8, 0.1))
(3: (-0.6, 1.0, 0.4))(4: (-0.5, 1.1, 0.5))(5: (-0.5, 1.2, 0.5))
(6: (-0.5, 1.3, 0.5))(7: (-0.5, 1.3, 0.5))(8: (-0.5, 1.2, 0.6))
(9: (-0.5, 1.0, 0.6))(10: (-0.5, 0.9, 0.6))(11: (-0.5, 0.8, 0.6))

//2번라인
(12: (-0.5, 0.9, 0.7))(13: (-0.5, 0.9, 0.7))(14: (-0.4, 1.0, 0.8))
(15: (-0.4, 1.0, 0.8))(16: (-0.4, 1.0, 0.8))(17: (-0.4, 1.0, 0.8))
(18: (-0.4, 1.1, 0.8))(19: (-0.4, 1.1, 0.8))(20: (-0.4, 1.1, 0.8))
(21: (-0.4, 1.0, 0.9))(22: (-0.4, 1.0, 0.9))(23: (-0.4, 0.9, 0.9))

동일한 좌표를 두번 찍는것으로 시작점을 표현

 

'Unity' 카테고리의 다른 글

구글플레이 앱 이전  (0) 2023.03.06
유니티 창위치 설정  (0) 2022.06.18
유니티 csv 에셋  (0) 2022.04.30
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입