Unity/Asset 분석

[RTS Engine] AttackObject의 Mesh가 재생성 되지 않을 때

lipnus 2021. 6. 2. 20:44
반응형

캐터펄트로 실험을 했는데,

첫 1회만 돌이 날아가고 그다음부터는 Particle Effect만 보이고 돌은 안날아감.

 

날아가는 물체는 Effect Obj, Attack Object 컴포넌트를 가져야 함.

 

Effect Obj Pool 구성 요소는 맵에서 효과 및 공격 오브젝트에 대한 Pool 역할을합니다. RTS Engine 메뉴 편집기를 사용하여 새지도를 만들 때이 구성 요소는 "AttackManager"라는 개체에 연결됩니다.

 

 


 

 

  1. Code: Make sure that every effect object has a unique code so that the effect object pool can distinguish between different effect objects.
  2. Enable Life Time: When enabled, the effect object will have a life time during which it will be shown when activated. When disabled, the effect object will have to be manually hidden.
  3. Default Life Time: When life time is enabled, this is the default life time (in seconds) of the effect object.
  4. Disable Time: Time (in seconds) to keep displaying the effect object after it’s marked as disabled. During this time, the effect object won’t be able to be fetched to be re-used again by the effect object pool. This can be useful to allow time for a particle system that’s attached to the effect object to stop and not just disappear instantly.
  5. Spawn Position Offset: Offset the spawn position by this vector.
  6. On Enable Event: Methods from other components to call when the effect object is enabled.
  7. On Disable Event: Methods from other components to call when the effect object is disabled.

비활성화 시간 : 비활성화 된 것으로 표시된 후 효과 객체를 계속 표시하는 시간 (초)입니다. 이 시간 동안 효과 개체 풀에서 다시 사용하기 위해 효과 개체를 가져올 수 없습니다. 이는 효과 오브젝트에 연결된 입자 시스템이 즉시 사라지는 것이 아니라 중지되는 시간을 허용하는 데 유용 할 수 있습니다.

 


① Disable Time을 0으로 한다.

② On Disable Event() : 적에게 명중해서 이 이벤트가 없어질 때

    GameObject.SetActive밑에 Check

 

 

EffectObj.cs

(전체코드 아님)

        [SerializeField]
        private UnityEvent onDisableEvent = null; //invoked when the effect object is disabled.        
        
        void Update ()
		{
            if (CurrentState != State.inactive) //if the effect object is not inactive then run timer
            {
                if (timer > 0.0f)
                    timer -= Time.deltaTime;
                else //life timer is through
                {
                    switch (CurrentState)
                    {
                        case State.running: //if the effect object is running (active)
                            if (enableLifeTime == true) //make sure the life time is enabled
                                Disable(); //disable the effect object
                            break;
                        case State.disabling: //if the effect object is getting disabled
                            DisableInternal(); //disable the effect object completely
                            break;

                    }
                }
            }
        }

        //hide the effect object
        public void Disable()
        {
            if (CurrentState == State.disabling) //if the effect object is already being disabled
                return;

            onDisableEvent.Invoke(); //invoke the event.

            timer = disableTime; //start the disable timer
            CurrentState = State.disabling; //we're now disabling the effect object
        }
 

Effect Objects

The Effect Obj Pool component serves as pool for effect and attack objects in the map. When you’re creating a new map using the RTS Engine menu editor, this component is attached to an object called “AttackManager”. While the Effect Obj Pool componen

soumidelrio.com

 

 

UnityEvent 클래스

UnityEvent C#의 Delegate인데 Unity용으로 만든 것. MonoBehaviour를 상속받는 모든 클래스에서 사용할 수 있고, UnityEvent 변수를 선언하면 인스펙터에 표시되고 영구적 콜백을 추가할 수 있다. - 영구적 콜.

sunpil.tistory.com

 

반응형