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);
}
}
}
잉 상속안쓰는건가요??
그건 델리게이트 event 쓸때
이게 씬과 씬사이가 연결이 될까요?? 일단 지금 만드는중이에요
업데이트함 보셈
private void Awake() { GetComponentsInChildren(LTObj, includeInactive: true); for(int i=0; i < LTObj.Count; i++) { LTObj[i].ActionEvent += AE => EventHelper(AE, ActionEvent); } } 여기서 Getcomponent 오류나는데 이걸 누구한테 전달하시는건가요??
빠르게 대충 만든거라서 이해안되면 윗꺼써라 그리고 이 클래스 자식에 triggerObject 달려있어야함
그것도 아니라면 아마도 자식부모간 델리게이트 이름이 같아서 그런 것 같다
위에꺼 해봤는데 위에 UIManager가 다른씬에 존재해서 에디터상 추가가 불가능합니다.
https://gall.dcinside.com/mgallery/board/view/?id=game_dev&no=68966&page=1
사진에서
UIManager 추가가 안되요