/// <summary> /// This is called to validate the scene and ensure it can be exported. /// <strong>If you override this, make sure to call <code>base.Validate(scene, root, err)</code>! (Preferably before your code)</strong> /// Also, do NOT return early from this method unless absolutely necessary. Validate as many thing as you can. /// </summary> /// <param name="scene">The scene to export</param> /// <param name="root">The root game object</param> /// <param name="err">An object used to inform the exporter what's happened</param> public virtual void Validate(Scene scene, CustomScene root, ExportErrors err) { // Save these for later. _scene = scene; _root = root; _err = err; // Check for NavMesh and Occlusion data // These aren't *required* so they will only be warnings if (!File.Exists(Path.GetDirectoryName(scene.path) + "/" + scene.name + "/NavMesh.asset")) { err.AddWarning("Scene is missing NavMesh data!"); } if (!File.Exists(Path.GetDirectoryName(scene.path) + "/" + scene.name + "/OcclusionCullingData.asset")) { err.AddWarning("Scene is missing Occlusion Culling Data!"); } // Let the proxied components know we're about to export foreach (var proxy in scene.GetRootGameObjects().SelectMany(x => x.GetComponentsInChildren <ComponentProxy>())) { proxy.OnExport(err); } }
/// <summary> /// Simple helper function to check if the number of components of a certain type is between two numbers /// </summary> /// <param name="min">The minimum number</param> /// <param name="max">The maximum number</param> /// <param name="warning">If invalid, produces a warning instead of an error</param> /// <param name="message">Custom message to log</param> /// <typeparam name="T">The type of the component</typeparam> protected void RequiredComponents <T>(int min, int max = int.MaxValue, bool warning = false, string message = null) { var count = _root.GetComponentsInChildren <T>().Length; if (min <= count && count <= max) { return; } var msg = min == max ? $"{min}" : max == int.MaxValue ? $"at least {min}" : $"{min} - {max}"; if (warning) { _err.AddWarning(message ?? $"Your scene contains {count} {typeof(T).Name}. Recommended number is {msg}"); } else { _err.AddError(message ?? $"Your scene contains {count} {typeof(T).Name}. Required number is {msg}"); } }