protected override void UpdateOverride() { base.UpdateOverride(); if (Editor.Tools.IsViewing) { SelectedAxis = RuntimeHandleAxis.None; return; } if (!IsWindowActive || !Window.IsPointerOver) { return; } if (!IsDragging /*&& !IsPointerDown*/) { if (HightlightOnHover) { m_targetInverseMatrix = Matrix4x4.TRS(Target.position, Target.rotation * StartingRotationInv, Vector3.one).inverse; SelectedAxis = HitTester.GetSelectedAxis(this); } if (m_targetRotation != Target.rotation) { m_startingRotation = Target.rotation; m_startinRotationInv = Quaternion.Inverse(m_startingRotation); m_targetRotation = Target.rotation; } } }
protected override bool OnBeginDrag() { SelectedAxis = HitTester.GetSelectedAxis(this); m_currentPosition = Position; m_cursorPosition = Position; if ((IsInVertexSnappingMode || Editor.Tools.IsSnapping) && SelectedAxis != RuntimeHandleAxis.Snap) { return(HitSnapHandle()); } if (SelectedAxis == RuntimeHandleAxis.XZ) { DragPlane = GetDragPlane(m_matrix, Vector3.up); return(GetPointOnDragPlane(Window.Pointer, out m_prevPoint)); } if (SelectedAxis == RuntimeHandleAxis.YZ) { DragPlane = GetDragPlane(m_matrix, Vector3.right); return(GetPointOnDragPlane(Window.Pointer, out m_prevPoint)); } if (SelectedAxis == RuntimeHandleAxis.XY) { DragPlane = GetDragPlane(m_matrix, Vector3.forward); return(GetPointOnDragPlane(Window.Pointer, out m_prevPoint)); } if (SelectedAxis != RuntimeHandleAxis.None) { Vector3 axis = Vector3.zero; switch (SelectedAxis) { case RuntimeHandleAxis.X: axis = Vector3.right; break; case RuntimeHandleAxis.Y: axis = Vector3.up; break; case RuntimeHandleAxis.Z: axis = Vector3.forward; break; } DragPlane = GetDragPlane(axis); bool result = GetPointOnDragPlane(Window.Pointer, out m_prevPoint); if (!result) { SelectedAxis = RuntimeHandleAxis.None; } return(result); } return(false); }
public static void GenerateLightProbes(float gridSize, float height, float probeHeight) { if (gridSize < Mathf.Epsilon) { Debug.Log("间矩是个无效数值"); return; } if (height < Mathf.Epsilon) { Debug.Log("碰撞高度是无效数值"); return; } Bounds bounds = GetNavMeshBounds(); if (bounds.extents.magnitude < Mathf.Epsilon) { Debug.Log("场景没有物件的layer属性设置为Terrain,请先完成相应设置."); return; } HitTester hitTester = new HitTester(bounds, gridSize, height, probeHeight); Vector3[] positions = hitTester.CalcProbes(bounds); // then set positions to component GameObject lightProbeHolder = GameObject.Find("LightProbeHolder"); if (!lightProbeHolder) { lightProbeHolder = new GameObject("LightProbeHolder", typeof(LightProbeGroup)); } if (!lightProbeHolder) { return; } LightProbeGroup lpg = lightProbeHolder.GetComponent <LightProbeGroup>(); if (!lpg) { return; } lpg.probePositions = positions; Debug.Log("Generated " + lpg.probePositions.Length.ToString() + " probe points\n"); HierarchyUtils.DestroyObjByName("LightProbeBox"); //Lightmapping.Bake(); }
protected override bool OnBeginDrag() { if (!base.OnBeginDrag()) { return(false); } SelectedAxis = HitTester.GetSelectedAxis(this); if (SelectedAxis == RuntimeHandleAxis.Free) { DragPlane = GetDragPlane(Vector3.zero); } else if (SelectedAxis == RuntimeHandleAxis.None) { return(false); } m_refScales = new Vector3[ActiveTargets.Length]; for (int i = 0; i < m_refScales.Length; ++i) { Quaternion rotation = Editor.Tools.PivotRotation == RuntimePivotRotation.Global ? ActiveTargets[i].rotation : Quaternion.identity; m_refScales[i] = rotation * ActiveTargets[i].localScale; } Vector3 axis = Vector3.zero; switch (SelectedAxis) { case RuntimeHandleAxis.X: axis = Vector3.right; break; case RuntimeHandleAxis.Y: axis = Vector3.up; break; case RuntimeHandleAxis.Z: axis = Vector3.forward; break; } DragPlane = GetDragPlane(axis); bool result = GetPointOnDragPlane(Window.Pointer, out m_prevPoint); if (!result) { SelectedAxis = RuntimeHandleAxis.None; } return(result); }
protected override void UpdateOverride() { base.UpdateOverride(); if (Editor.Tools.IsViewing) { SelectedAxis = RuntimeHandleAxis.None; return; } if (!IsWindowActive || !Window.IsPointerOver) { return; } if (HightlightOnHover && !IsDragging && !IsPointerDown) { SelectedAxis = HitTester.GetSelectedAxis(this); } }
protected override void UpdateOverride() { base.UpdateOverride(); if (Editor.Tools.IsViewing) { SelectedAxis = RuntimeHandleAxis.None; return; } if (!IsWindowActive || !Window.IsPointerOver) { return; } IRTE editor = Editor; if (IsDragging) { if (SnapToGround && SelectedAxis != RuntimeHandleAxis.Y) { SnapActiveTargetsToGround(ActiveTargets, Window.Camera, true); transform.position = Targets[0].position; } } if (HightlightOnHover && !IsDragging /*&& !IsPointerDown*/) { SelectedAxis = HitTester.GetSelectedAxis(this); } if (IsInVertexSnappingMode || Editor.Tools.IsSnapping) { Vector2 mousePosition; if (Window.Pointer.XY(Position, out mousePosition)) { if (editor.Tools.SnappingMode == SnappingMode.BoundingBox) { if (IsDragging) { SelectedAxis = RuntimeHandleAxis.Snap; if (m_prevMousePosition != mousePosition) { m_prevMousePosition = mousePosition; float minDistance = float.MaxValue; Vector3 minPoint = Vector3.zero; bool minPointFound = false; for (int i = 0; i < m_allExposedToEditor.Length; ++i) { ExposeToEditor exposeToEditor = m_allExposedToEditor[i]; Bounds bounds = exposeToEditor.Bounds; m_boundingBoxCorners[0] = bounds.center + new Vector3(bounds.extents.x, bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[1] = bounds.center + new Vector3(bounds.extents.x, bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[2] = bounds.center + new Vector3(bounds.extents.x, -bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[3] = bounds.center + new Vector3(bounds.extents.x, -bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[4] = bounds.center + new Vector3(-bounds.extents.x, bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[5] = bounds.center + new Vector3(-bounds.extents.x, bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[6] = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[7] = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, -bounds.extents.z); GetMinPoint(ref minDistance, ref minPoint, ref minPointFound, exposeToEditor.BoundsObject.transform); } if (minPointFound) { Position = minPoint; } } } else { SelectedAxis = RuntimeHandleAxis.None; if (m_prevMousePosition != mousePosition) { m_prevMousePosition = mousePosition; float minDistance = float.MaxValue; Vector3 minPoint = Vector3.zero; bool minPointFound = false; for (int i = 0; i < m_snapTargets.Length; ++i) { Transform snapTarget = m_snapTargets[i]; Bounds bounds = m_snapTargetsBounds[i]; m_boundingBoxCorners[0] = bounds.center + new Vector3(bounds.extents.x, bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[1] = bounds.center + new Vector3(bounds.extents.x, bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[2] = bounds.center + new Vector3(bounds.extents.x, -bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[3] = bounds.center + new Vector3(bounds.extents.x, -bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[4] = bounds.center + new Vector3(-bounds.extents.x, bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[5] = bounds.center + new Vector3(-bounds.extents.x, bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[6] = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[7] = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, -bounds.extents.z); if (Targets[i] != null) { GetMinPoint(ref minDistance, ref minPoint, ref minPointFound, snapTarget); } } if (minPointFound) { m_handleOffset = minPoint - transform.position; } } } } else { if (IsDragging) { SelectedAxis = RuntimeHandleAxis.Snap; if (m_prevMousePosition != mousePosition) { m_prevMousePosition = mousePosition; Ray ray = Window.Pointer; RaycastHit hitInfo; LayerMask layerMask = (1 << Physics.IgnoreRaycastLayer); layerMask = ~layerMask; layerMask &= Editor.CameraLayerSettings.RaycastMask; for (int i = 0; i < m_snapTargets.Length; ++i) { m_targetLayers[i] = m_snapTargets[i].gameObject.layer; m_snapTargets[i].gameObject.layer = Physics.IgnoreRaycastLayer; } GameObject closestObject = null; if (Physics.Raycast(ray, out hitInfo, float.PositiveInfinity, layerMask)) { closestObject = hitInfo.collider.gameObject; } else { float minDistance = float.MaxValue; for (int i = 0; i < m_allExposedToEditor.Length; ++i) { ExposeToEditor exposedToEditor = m_allExposedToEditor[i]; Bounds bounds = exposedToEditor.Bounds; m_boundingBoxCorners[0] = bounds.center + new Vector3(bounds.extents.x, bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[1] = bounds.center + new Vector3(bounds.extents.x, bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[2] = bounds.center + new Vector3(bounds.extents.x, -bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[3] = bounds.center + new Vector3(bounds.extents.x, -bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[4] = bounds.center + new Vector3(-bounds.extents.x, bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[5] = bounds.center + new Vector3(-bounds.extents.x, bounds.extents.y, -bounds.extents.z); m_boundingBoxCorners[6] = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, bounds.extents.z); m_boundingBoxCorners[7] = bounds.center + new Vector3(-bounds.extents.x, -bounds.extents.y, -bounds.extents.z); for (int j = 0; j < m_boundingBoxCorners.Length; ++j) { Vector2 screenPoint; if (Window.Pointer.WorldToScreenPoint(Position, exposedToEditor.BoundsObject.transform.TransformPoint(m_boundingBoxCorners[j]), out screenPoint)) { float distance = (screenPoint - mousePosition).magnitude; if (distance < minDistance) { closestObject = exposedToEditor.gameObject; minDistance = distance; } } } } } if (closestObject != null) { float minDistance = float.MaxValue; Vector3 minPoint = Vector3.zero; bool minPointFound = false; Transform meshTransform; Mesh mesh = GetMesh(closestObject, out meshTransform); GetMinPoint(meshTransform, ref minDistance, ref minPoint, ref minPointFound, mesh); if (minPointFound) { Position = minPoint; } } for (int i = 0; i < m_snapTargets.Length; ++i) { m_snapTargets[i].gameObject.layer = m_targetLayers[i]; } } } else { SelectedAxis = RuntimeHandleAxis.None; if (m_prevMousePosition != mousePosition) { m_prevMousePosition = mousePosition; float minDistance = float.MaxValue; Vector3 minPoint = Vector3.zero; bool minPointFound = false; for (int i = 0; i < RealTargets.Length; ++i) { Transform snapTarget = RealTargets[i]; Transform meshTranform; Mesh mesh = GetMesh(snapTarget.gameObject, out meshTranform); GetMinPoint(meshTranform, ref minDistance, ref minPoint, ref minPointFound, mesh); } if (minPointFound) { m_handleOffset = minPoint - transform.position; } } } } } } }
public void SetTarget(HitTester target) { this.target = target; Debug.Log(target); }
protected override bool OnBeginDrag() { if (!base.OnBeginDrag()) { return(false); } m_targetRotation = Target.rotation; m_targetInverseMatrix = Matrix4x4.TRS(Target.position, Target.rotation * StartingRotationInv, Vector3.one).inverse; SelectedAxis = HitTester.GetSelectedAxis(this); m_deltaX = 0.0f; m_deltaY = 0.0f; Vector2 point; if (Window.Pointer.XY(Target.position, out point)) { m_prevPointer = point; } else { SelectedAxis = RuntimeHandleAxis.None; } m_forceScreenRotationMode = ForceScreenRotationMode(); if (SelectedAxis == RuntimeHandleAxis.Screen || m_forceScreenRotationMode) { Vector2 center; if (Window.Pointer.WorldToScreenPoint(Target.position, Target.position, out center)) { if (Window.Pointer.XY(Target.position, out point)) { float angle = Mathf.Atan2(point.y - center.y, point.x - center.x); m_targetInverse = Quaternion.Inverse(Quaternion.AngleAxis(Mathf.Rad2Deg * angle, Vector3.forward)); m_targetInverseMatrix = Matrix4x4.TRS(Target.position, Target.rotation, Vector3.one).inverse; m_prevPointer = point; } else { SelectedAxis = RuntimeHandleAxis.None; } } else { SelectedAxis = RuntimeHandleAxis.None; } } else { if (SelectedAxis == RuntimeHandleAxis.X) { m_startingRotationAxis = (Target.rotation * Quaternion.Inverse(StartingRotation)) * Vector3.right; } else if (SelectedAxis == RuntimeHandleAxis.Y) { m_startingRotationAxis = (Target.rotation * Quaternion.Inverse(StartingRotation)) * Vector3.up; } else if (SelectedAxis == RuntimeHandleAxis.Z) { m_startingRotationAxis = (Target.rotation * Quaternion.Inverse(StartingRotation)) * Vector3.forward; } m_targetInverse = Quaternion.Inverse(Target.rotation); } return(SelectedAxis != RuntimeHandleAxis.None); }