/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents) return true; if (meshes == null) { context.LogError(name + " Mesh exclusion list is null. (Invalid processor state.)" , this); return false; } if (meshes.Count == 0) { context.Log(name + ": Filter is inactive. No meshes configured to filter.", this); return true; } List<Component> targetFilters = context.components; int removed = 0; for (int iTarget = targetFilters.Count - 1; iTarget >= 0; iTarget--) { if (!(targetFilters[iTarget] is MeshFilter)) continue; MeshFilter filter = (MeshFilter)targetFilters[iTarget]; if (!filter) continue; MatchPredicate p = new MatchPredicate(filter.sharedMesh, matchType, true); int iSource = meshes.FindIndex(p.Matches); if (iSource != -1) { targetFilters.RemoveAt(iTarget); removed++; } } if (removed > 0) context.Log(string.Format("{0}: Filtered out {1} components.", name, removed), this); else context.Log(name + ": No components filtered.", this); return true; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.ApplyAreaModifiers) return true; context.info.areaModifierCount++; if (meshes == null || areas == null || meshes.Count != areas.Count) { context.LogError("Mesh/Area size error. (Invalid processor state.)", this); return false; } if (meshes.Count == 0) { context.Log("No action taken. No mesh areas defined.", this); return true; } List<Component> targetFilters = context.components; List<byte> targetAreas = context.areas; int applied = 0; for (int iTarget = 0; iTarget < targetFilters.Count; iTarget++) { if (!(targetFilters[iTarget] is MeshFilter)) continue; MeshFilter filter = (MeshFilter)targetFilters[iTarget]; if (filter == null || targetAreas[iTarget] == org.critterai.nmgen.NMGen.NullArea) // Never override null area. continue; MatchPredicate p = new MatchPredicate(filter.sharedMesh, matchType, true); int iSource = meshes.FindIndex(p.Matches); if (iSource != -1) { targetAreas[iTarget] = areas[iSource]; applied++; } } context.Log(string.Format("Applied area(s) to {0} components.", applied), this); return true; }