/// <summary> /// Make new Event /// </summary> /// <param name="data"></param> public EventActionData(EventActionData data) { this.levelValidation = data.levelValidation; if (data.eventType == EventType.Event) { this.eventType = data.eventType; string json = JsonUtility.ToJson(data.block); Block sData = JsonUtility.FromJson(json, data.block.GetType()) as Block; if (sData != null) { BeforeSerialize(sData); AfterSerialize(); } } else { eventType = EventType.Or; } }
/// <summary> /// Validate validation. /// </summary> /// <returns></returns> public bool Validate(UnityEngine.Object instance) { //if(editIndex == -1) return true; if (eventList == null || eventList.Count == 0) { //editIndex = -1; return(true); } bool hasFail = false; //to check that validation has fail. if (!useLevelValidation) { for (int i = 0; i < eventList.Count; i++) { EventActionData Event = eventList[i]; if (!hasFail && Event.eventType == EventActionData.EventType.Event) { #if UNITY_EDITOR try { if (!Event.block.Validate(instance)) //do validate { hasFail = true; } } catch { Debug.LogError("Error in validation : " + eventList[i].displayName + " in index : " + i); throw; } #else if (!Event.block.Validate(instance)) //do validate { hasFail = true; } #endif } else if (Event.eventType == EventActionData.EventType.Or) { if (hasFail && i + 1 == eventList.Count) //if or event is in the end of array then stop it. { break; } else if (hasFail) //if prev validate has fail, execute next validate { hasFail = false; } else //if prev validate does't have fail then stop this. { break; } } } } else { byte lastLevel = 0; for (int i = 0; i < eventList.Count; i++) { EventActionData Event = eventList[i]; if (Event.levelValidation == 0) { if (Event.eventType == EventActionData.EventType.Event) { #if UNITY_EDITOR try { if (!hasFail && !Event.block.Validate(instance)) //do validate { hasFail = true; } } catch { Debug.LogError("Error in validation : " + eventList[i].displayName + " in index : " + i); throw; } #else if (!hasFail && !Event.block.Validate(instance)) //do validate { hasFail = true; } #endif } else //Or Statement { if (hasFail) //if or event is in the end of array then stop it. { if (i + 1 == eventList.Count) { return(false); } //if prev validate has fail, execute next validate hasFail = false; } else //if prev validate does't have fail then stop this. { break; } } } else { if (i == 0) { lastLevel = Event.levelValidation; } else if (lastLevel != Event.levelValidation && hasFail) { continue; } if (Event.eventType == EventActionData.EventType.Event) { #if UNITY_EDITOR try { if (!hasFail && !Event.block.Validate(instance)) //do validate { hasFail = true; } } catch { Debug.LogError("Error in validation : " + eventList[i].displayName + " in index : " + i); throw; } #else if (!hasFail && !Event.block.Validate(instance)) //do validate { hasFail = true; } #endif } else //Or Statement { if (lastLevel == Event.levelValidation && !hasFail) { continue; } if (hasFail) //if or event is in the end of array then stop it. { if (i + 1 == eventList.Count) { return(false); } //if prev validate has fail, execute next validate hasFail = false; } else //if prev validate does't have fail then execute next validate. { if (i + 1 == eventList.Count) { break; } continue; } } } lastLevel = Event.levelValidation; } } return(!hasFail); }
public void RemoveBlock(EventActionData @event) { eventList.Remove(@event); }