public static void AutoOff(this IPropertySwitch propSwitch) { if (Application.isPlaying) { propSwitch.Off(); } else { propSwitch.OffNow(); } }
private void constructChildren() { var stack = Pool <Stack <Transform> > .Spawn(); stack.Clear(); stack.Push(this.transform); try { while (stack.Count > 0) { var transform = stack.Pop(); foreach (var child in transform.GetChildren()) { // Ignore SwitchTreeControllers, which will handle their own internal // hierarchy. if (child.GetComponent <SwitchTreeController>() != null) { continue; } // ObjectSwitches get priority, but any Switch will do. IPropertySwitch objSwitch = child.GetComponent <ObjectSwitch>(); if (objSwitch == null) { objSwitch = child.GetComponent <IPropertySwitch>(); } if (objSwitch != null) { // Each child with a switch component gets a node with the current node // as its parent. var newChild = new Node((objSwitch as MonoBehaviour), new NodeRef(this), this.treeDepth + 1); children.Add(newChild); this.numAllChildren += 1 + newChild.numAllChildren; } else { // This node will "inherit" any grand-children nodes whose parents are // not _themselves_ switches as direct "children" in the switch tree. stack.Push(child); } } } } finally { stack.Clear(); Pool <Stack <Transform> > .Recycle(stack); } }