private void Awake() { //there can be only one! if (Instance != null) { Destroy(this); } Instance = this; }
protected void GatherRefs() { if (EditorApplication.isPlaying) { return; } HittablesController controller = (HittablesController)target; Hittable[] hittables = FindObjectsOfType <Hittable>(); //check if we already have all hittables so we don't dirty scene for nothing if (hittables.Length == controller.hittables.Count) { int same = 0; foreach (Hittable hittable in controller.hittables) { //if one not found, save them all if (System.Array.IndexOf(hittables, hittable) == -1) { break; } else { same++; } } //already saved, exit if (same == controller.hittables.Count) { return; } } //create undo Undo.RecordObject(controller, "Ref Set"); //store controller.hittables = new List <Hittable>(hittables); }