public static void MakeSharedChildrenMembers(SECTR_Sector sector, List <SECTR_Member.Child> sharedChildren, string undoName) { int numSharedChildren = sharedChildren.Count; for (int childIndex = 0; childIndex < numSharedChildren; ++childIndex) { SECTR_Member.Child child = sharedChildren[childIndex]; bool hasMemberParent = false; Transform parent = child.gameObject.transform; while (parent != null) { if (parent.gameObject != sector.gameObject && parent.GetComponent <SECTR_Member>()) { hasMemberParent = true; break; } else { parent = parent.parent; } } if (!hasMemberParent) { SECTR_Member newMember = child.gameObject.AddComponent <SECTR_Member>(); SECTR_Undo.Created(newMember, undoName); } } sector.ForceUpdate(true); }
protected override void OnDrawGizmosSelected() { Bounds bounds = TotalBounds; Gizmos.color = SectorColor; Gizmos.DrawWireCube(bounds.center, bounds.size); if (enabled) { // Render links to neighbor Sectors. Gizmos.color = SECTR_Portal.ActivePortalColor; int numNeighbors = portals.Count; for (int neighborIndex = 0; neighborIndex < numNeighbors; ++neighborIndex) { SECTR_Portal portal = portals[neighborIndex]; Gizmos.DrawLine(TotalBounds.center, portal.Center); } Gizmos.color = Color.red; List <SECTR_Member.Child> sharedChildren = GetSharedChildren(); int numSharedChildren = sharedChildren.Count; for (int childIndex = 0; childIndex < numSharedChildren; ++childIndex) { SECTR_Member.Child child = sharedChildren[childIndex]; Bounds totalChildBounds = new Bounds(child.gameObject.transform.position, Vector3.zero); if (child.renderer) { totalChildBounds.Encapsulate(child.rendererBounds); } if (child.light) { totalChildBounds.Encapsulate(child.lightBounds); } if (child.terrain) { totalChildBounds.Encapsulate(child.terrainBounds); } Gizmos.DrawWireCube(totalChildBounds.center, totalChildBounds.size); } } }
public List <SECTR_Member.Child> GetSharedChildren() { List <SECTR_Member.Child> sharedChildren = new List <SECTR_Member.Child>(); List <SECTR_Sector> overlappingSectors = new List <SECTR_Sector>(); int numChildren = Children.Count; for (int childIndex = 0; childIndex < numChildren; ++childIndex) { SECTR_Member.Child child = Children[childIndex]; if (child.renderer && !SECTR_Geometry.BoundsContainsBounds(TotalBounds, child.rendererBounds)) { GetContaining(ref overlappingSectors, child.rendererBounds); if (overlappingSectors.Count > 1) { sharedChildren.Add(child); continue; } } if (child.light && !SECTR_Geometry.BoundsContainsBounds(TotalBounds, child.lightBounds)) { GetContaining(ref overlappingSectors, child.lightBounds); if (overlappingSectors.Count > 1) { sharedChildren.Add(child); continue; } } if (child.terrain && !SECTR_Geometry.BoundsContainsBounds(TotalBounds, child.terrainBounds)) { GetContaining(ref overlappingSectors, child.terrainBounds); if (overlappingSectors.Count > 1) { sharedChildren.Add(child); continue; } } } return(sharedChildren); }