void Awake(){
int index = 0;
foreach(EventData eventData in m_Logic.getEvents()){
int idx = index;
Messenger.Callback<GameObject, bool> callbackFunc =
delegate(GameObject obj, bool triggerOnlyForMe){
//string requiredState = m_Logic.getEvent(idx).getRequiredObjectState();
bool doCall = true;
string eventName = m_Logic.getEvent(idx).getName();
if(PuzzleEvent.isEventCancelled(eventName)){
doCall = false;
}
if(triggerOnlyForMe && obj != gameObject){
doCall = false;
}
/*
Interactable interObj = obj.GetComponent<Interactable>();
if(m_Logic.getEvent(idx).getName() == "onUseWith"){
Debug.Log("State: "+interObj.getPuzzleState()+", expected: "+requiredState);
}
if(interObj != null && requiredState.Length > 0 && requiredState != interObj.getPuzzleState()){
doCall = false;
}
*/
if(doCall){
List<ObjectState> objectStates = m_Logic.getObjectStates(idx);
TriggerData triggerData = m_Logic.getTriggerData(idx);
foreach(ObjectState objectState in objectStates){
GameObject attachedObj = objectState.getObject();
if(attachedObj == null){
attachedObj = gameObject;
}
Interactable interSavedObj = attachedObj.GetComponent<Interactable>();
if(interSavedObj != null){
if(interSavedObj.getPuzzleState() != objectState.getState()){
doCall = false;
break;
}
}
else{
Debug.LogError("Condition objects need to have interactable script attached to it");
}
}
if(doCall){
/*
Interactable thisInterObj = gameObject.GetComponent<Interactable>();
if(thisInterObj != null && triggerData.getNewObjectState().Length > 0){
thisInterObj.setPuzzleState(triggerData.getNewObjectState());
}
*/
if(triggerData.getName().Length > 0 && !PuzzleEvent.isEventCancelled(triggerData.getName())){
Messenger.Broadcast<GameObject, bool>(triggerData.getName(), gameObject, false);
}
}
}
};
if(!m_CallbackFuncs.ContainsKey(eventData.getName())){
m_CallbackFuncs.Add(eventData.getName(), new List<Messenger.Callback<GameObject, bool>>());
}
m_CallbackFuncs[eventData.getName()].Add(callbackFunc);
Messenger.AddListener<GameObject, bool>(eventData.getName(), callbackFunc);
++index;
}
puzzleLogics.Add(this);
}