private void Start() { logic = GetComponent <CorePuzzleLogic>(); handler = GetComponent <CorePuzzleHandler>(); if (activateTimerOnStart) { StartTimer(); } }
private void InstantiateSystem() { if (!handler || !logic || (!trigger && !triggerPrefab)) { if (!EditorUtility.DisplayDialog("[PuzzleSystem] System Creation Warning", "There is at least one empty field passed into the . The system will most likely work improperly unless you add missing components by yourself later. \n\nDo you want to continue the creation without the missing component(-s)?", "Continue", "Cancel")) { return; } } if (handler) { if (!handler.GetClass().IsSubclassOf(typeof(CorePuzzleHandler)) && handler.GetClass() != typeof(CorePuzzleHandler)) { EditorUtility.DisplayDialog("[PuzzleSystem] System Creation Failed", "The creation of the puzzle system has failed becuase inputted Handler component does not inherit its core elements.\n\nPlease, make sure that the script you are choosing is a subclass of CorePuzzleHandler.", "Ok"); handler = null; return; } } if (logic) { if (!logic.GetClass().IsSubclassOf(typeof(CorePuzzleLogic)) && logic.GetClass() != typeof(CorePuzzleLogic)) { EditorUtility.DisplayDialog("[PuzzleSystem] Failed System Creation", "The creation of the puzzle system has failed becuase inputted Logic component does not inherit its core elements.\n\nPlease, make sure that the script you are choosing is a subclass of CorePuzzleLogic.", "Ok"); logic = null; return; } } bool includeCollider = false; if (trigger && toolBarTriggerType == 1) { if (!trigger.GetClass().IsSubclassOf(typeof(CorePuzzleTrigger)) && trigger.GetClass() != typeof(CorePuzzleTrigger)) { EditorUtility.DisplayDialog("[PuzzleSystem] Failed System Creation", "The creation of the puzzle system has failed becuase inputted Trigger component does not inherit its core elements.\n\nPlease, make sure that the script you are choosing is a subclass of CorePuzzleTrigger.", "Ok"); trigger = null; return; } includeCollider = trigger.GetClass().IsSubclassOf(typeof(CoreColliderBasedPuzzleTrigger)); } // PuzzleSystem Creation -- parent object & triggers GameObject parentObj = new GameObject("PuzzleSystem"); if (handler) { parentObj.AddComponent(handler.GetClass()); } CorePuzzleLogic logicComponent = logic ? parentObj.AddComponent(logic.GetClass()) as CorePuzzleLogic : null; GameObject temp = null; CorePuzzleTrigger tempTriggerComponent = null; CorePuzzleTrigger[] triggers = new CorePuzzleTrigger[triggerCount]; for (int i = 0; i < triggerCount; i++) { if (toolBarTriggerType == 1) { temp = new GameObject("Trigger"); if (includeCollider) { temp.AddComponent <BoxCollider>().isTrigger = true; } tempTriggerComponent = temp.AddComponent(trigger.GetClass()) as CorePuzzleTrigger; } else if (triggerPrefab) { temp = Instantiate(triggerPrefab); tempTriggerComponent = temp.GetComponent <CorePuzzleTrigger>(); } if (temp) { temp.transform.parent = parentObj.transform; } if (tempTriggerComponent) { triggers[i] = tempTriggerComponent; } } if (toolBarTriggerType == 0 && triggers.Length > 0 && !triggers[0]) { EditorUtility.DisplayDialog("[PuzzleSystem] Warning System Creation", "The prefab of the trigger, that was passed in for creating a system, does not contain any script that inherit CorePuzzleTrigger." + "\n\nThis means that the instantiated objects will not play the role of the triggers in the created puzzle system.", "Ok"); return; } if (logicComponent) { logicComponent.SetTriggers(triggers); } }