Ejemplo n.º 1
0
        public static void CenterPivotOnSelection()
        {
            var selectedNodes = ChiselSelectionManager.SelectedNodes;

            if (selectedNodes != null && selectedNodes.Count != 0)
            {
                var center = PIvotUtility.FindSelectionWorldSpaceCenter(selectedNodes);
                PIvotUtility.MovePivotTo(selectedNodes, center);
            }
        }
Ejemplo n.º 2
0
        public static void MovePivotToCenter(IReadOnlyList <ChiselNode> nodes)
        {
            // TODO: optimize
            var nodesWithChildObjects = new HashSet <UnityEngine.Object>();
            var nodesWithChildren     = new HashSet <ChiselNode>();

            foreach (var node in nodes)
            {
                var children = node.GetComponentsInChildren <ChiselNode>(includeInactive: true);
                foreach (var child in children)
                {
                    nodesWithChildren.Add(child);
                    nodesWithChildObjects.Add(child);
                    nodesWithChildObjects.Add(child.hierarchyItem.Transform);
                }
            }

            Undo.RecordObjects(nodesWithChildObjects.ToArray(), "Move Pivot");
            foreach (var node in nodesWithChildren)
            {
                var newPosition = PIvotUtility.FindSelectionWorldSpaceCenter(node);
                node.SetPivot(newPosition);
            }
        }