// When the selection is changed, reset the bounds of the tool. public void ResetBounds() { GameObject[] selectedGameObjects = Selection.gameObjects; if (selectedGameObjects.Length > 0) { objectBounds = InternalEditorUtility.CalculateSelectionBounds(true, false); foreach (var point in from GameObject gameObject in selectedGameObjects from Transform transform in gameObject.GetComponentsInChildren <Transform>() where transform.GetComponent <Renderer>() == null select transform.position) { objectBounds.Encapsulate(point); } if (objectBounds.size == Vector3.zero) { objectBounds = new Bounds(selectedGameObjects[0].transform.position, Vector3.one); } } else { objectBounds = default; } duplicationBounds.SetMinMax(objectBounds.center, objectBounds.center); ResetHandleBounds(); }
internal static Vector3 GetHandlePosition() { Transform activeTransform = Selection.activeTransform; if (activeTransform == null) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } Vector3 vector2 = handleOffset + (handleRotation * localHandleOffset); PivotMode pivotMode = get.m_PivotMode; if (pivotMode != PivotMode.Center) { if (pivotMode != PivotMode.Pivot) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } } else { if (current == UnityEditor.Tool.Rect) { return(((Vector3)(handleRotation * InternalEditorUtility.CalculateSelectionBoundsInSpace(Vector3.zero, handleRotation, rectBlueprintMode).center)) + vector2); } return(InternalEditorUtility.CalculateSelectionBounds(true, false).center + vector2); } if (((current == UnityEditor.Tool.Rect) && rectBlueprintMode) && InternalEditorUtility.SupportsRectLayout(activeTransform)) { return(activeTransform.parent.TransformPoint(new Vector3(activeTransform.localPosition.x, activeTransform.localPosition.y, 0f)) + vector2); } return(activeTransform.position + vector2); }
internal static Vector3 GetHandlePosition() { Transform activeTransform = Selection.activeTransform; if (!activeTransform) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } Vector3 b = Tools.handleOffset + Tools.handleRotation * Tools.localHandleOffset; PivotMode pivotMode = Tools.get.m_PivotMode; if (pivotMode != PivotMode.Center) { if (pivotMode != PivotMode.Pivot) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } if (Tools.current == Tool.Rect && Tools.rectBlueprintMode && InternalEditorUtility.SupportsRectLayout(activeTransform)) { return(activeTransform.parent.TransformPoint(new Vector3(activeTransform.localPosition.x, activeTransform.localPosition.y, 0f)) + b); } return(activeTransform.position + b); } else { if (Tools.current == Tool.Rect) { return(Tools.handleRotation * InternalEditorUtility.CalculateSelectionBoundsInSpace(Vector3.zero, Tools.handleRotation, Tools.rectBlueprintMode).center + b); } return(InternalEditorUtility.CalculateSelectionBounds(true, false).center + b); } }
internal static Vector3 GetHandlePosition() { Transform activeTransform = Selection.activeTransform; if (!(bool)((Object)activeTransform)) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } Vector3 vector3 = Tools.handleOffset + Tools.handleRotation * Tools.localHandleOffset; switch (Tools.get.m_PivotMode) { case PivotMode.Center: if (Tools.current == Tool.Rect) { return(Tools.handleRotation * InternalEditorUtility.CalculateSelectionBoundsInSpace(Vector3.zero, Tools.handleRotation, Tools.rectBlueprintMode).center + vector3); } return(InternalEditorUtility.CalculateSelectionBounds(true, false).center + vector3); case PivotMode.Pivot: if (Tools.current == Tool.Rect && Tools.rectBlueprintMode && InternalEditorUtility.SupportsRectLayout(activeTransform)) { return(activeTransform.parent.TransformPoint(new Vector3(activeTransform.localPosition.x, activeTransform.localPosition.y, 0.0f)) + vector3); } return(activeTransform.position + vector3); default: return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } }
internal static Vector3 GetHandlePosition() { Transform t = Selection.activeTransform; if (!t) { return(new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); } Vector3 totalOffset = handleOffset + handleRotation * localHandleOffset; using (s_GetHandlePositionMarker.Auto()) { switch (get.m_PivotMode) { case PivotMode.Center: { if (current == Tool.Rect) { return(handleRotation * InternalEditorUtility .CalculateSelectionBoundsInSpace(Vector3.zero, handleRotation, rectBlueprintMode) .center + totalOffset); } else { return(InternalEditorUtility.CalculateSelectionBounds(true, false).center + totalOffset); } } case PivotMode.Pivot: { if (current == Tool.Rect && rectBlueprintMode && InternalEditorUtility.SupportsRectLayout(t)) { return(t.parent.TransformPoint(new Vector3(t.localPosition.x, t.localPosition.y, 0)) + totalOffset); } else { return(t.position + totalOffset); } } default: { return(new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); } } } }
void samplePrefab() { GameObject prefabParent = new GameObject("Parent Object"); var myBounds = InternalEditorUtility.CalculateSelectionBounds(false, false); Vector3 centerPoint = myBounds.center; switch (editorData.yPivotType) { case 0: centerPoint.y = 0; break; case 1: centerPoint.y = myBounds.min.y; break; case 2: centerPoint.y = myBounds.center.y; break; default: centerPoint.y = 0; break; } prefabParent.transform.position = centerPoint; foreach (GameObject copyObject in selected) { GameObject copy = Instantiate(copyObject) as GameObject; copy.transform.position = copyObject.transform.position; copy.transform.eulerAngles = copyObject.transform.eulerAngles; copy.transform.parent = prefabParent.transform; } prefabParent.name = editorData.appendName + selected[0].name; prefabParent.transform.position = Vector3.zero; #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(prefabParent, appendNumber(editorData.destinationFolder + "/" + prefabParent.name)); #else PrefabUtility.CreatePrefab(appendNumber(editorData.destinationFolder + "/" + prefabParent.name), prefabParent); #endif DestroyImmediate(prefabParent); }