using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class triggerObjectParent : MonoBehaviour
{
public UIManager ui;
}
public class triggerObject : MonoBehaviour
{
protected triggerObjectParent parent;
private void Awake()
{
parent = GetComponentInParent<triggerObjectParent>();
}
protected virtual void Triggers()
{
parent.ui.updateUI();
}
}




이벤트 델리게이트



using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIManager : MonoBehaviour
{
public triggerObjectParent parent;
void Awake()
{
parent.ActionEvent += updateUI;
}
void updateUI(triggerObject obj)
{
obj.doSomething;
}
}
public class triggerObjectParent : MonoBehaviour
{
public UIManager ui;
public Action<triggerObject> ActionEvent;
public List<triggerObject> LTObj;
private void Awake()
{
GetComponentsInChildren(LTObj, includeInactive: true);
for(int i=0; i < LTObj.Count; i++)
{
LTObj[i].ActionEvent += AE => EventHelper(AE, ActionEvent);
}
}
void EventHelper(triggerObject obj, Action<triggerObject> objEvent)
{
if (objEvent != null) objEvent(obj);
}
}
public class triggerObject : MonoBehaviour
{
public Action<triggerObject> ActionEvent;
public void Triggers()
{
if(ActionEvent != null)
{
ActionEvent(this);
}
}
}