private void DoResetModeHandles(Ferr2D_Path path, Ferr2DT_PathTerrain terrain, int i, Matrix4x4 mat, Matrix4x4 invMat, Transform camTransform) { int nextId = i == path.Count - 1?(path.closed?i % path.Count:i - 1):i + 1; Vector3 pos = mat.MultiplyPoint3x4(path.pathVerts[i]); Vector3 posNext = mat.MultiplyPoint3x4(path.pathVerts[nextId]); Vector3 normal = -(Vector3)Ferr2D_Path.GetNormal(path.pathVerts, i, path.closed); Vector3 posStart = pos; bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } float handleScale = HandleScale(posStart); CapFunction cap = (isSelected || selectedPoints.Count <= 0) ? (CapFunction)CapDotMinusSelected : (CapFunction)CapDotMinus; if (Handles.Button(posStart, camTransform.rotation, handleScale, handleScale, cap)) { EnsureVertSelected(i, ref isSelected); deleteSelected = true; GUI.changed = true; } else if (!Ferr2DT_SceneOverlay.segmentLockMode) { handleScale = handleScale * 0.5f; // do scaling Vector3 displayPos = pos + normal * terrain.vertScales[i] * 2 * Ferr2DT_Menu.PathScale; if (IsVisible(displayPos) && Handles.Button(displayPos, camTransform.rotation, handleScale, handleScale, CapDotReset)) { EnsureVertSelected(i, ref isSelected); Undo.RecordObject(terrain, "Scale Path Vert"); for (int s = 0; s < selectedPoints.Count; s++) { terrain.vertScales[selectedPoints[s]] = 1; } EditorUtility.SetDirty(terrain); GUI.changed = true; } // do edge overrides displayPos = GetOverridePos(i, path, mat, pos, posNext); if (IsVisible(displayPos) && Handles.Button(displayPos, camTransform.rotation, handleScale, handleScale, CapDotReset)) { EnsureVertSelected(i, ref isSelected); Undo.RecordObject(terrain, "Override Vert Direction"); for (int s = 0; s < selectedPoints.Count; s++) { terrain.directionOverrides[selectedPoints[s]] = Ferr2DT_TerrainDirection.None; } EditorUtility.SetDirty(terrain); GUI.changed = true; } } }
private void OnSceneGUI() { RenderAttenuationSpheres(); if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.Simple_Mode) { return; } var someHashCode = GetHashCode(); UnityEditor.Handles.matrix = m_AkAmbient.transform.localToWorldMatrix; for (var i = 0; i < m_AkAmbient.multiPositionArray.Count; i++) { var pos = m_AkAmbient.multiPositionArray[i]; UnityEditor.Handles.Label(pos, "Point_" + i); var handleSize = UnityEditor.HandleUtility.GetHandleSize(pos); // Get the needed data before the handle var controlIDBeforeHandle = UnityEngine.GUIUtility.GetControlID(someHashCode, UnityEngine.FocusType.Passive); var isEventUsedBeforeHandle = UnityEngine.Event.current.type == UnityEngine.EventType.Used; UnityEditor.Handles.color = UnityEngine.Color.green; #if UNITY_5_6_OR_NEWER UnityEditor.Handles.CapFunction capFunc = UnityEditor.Handles.SphereHandleCap; #else UnityEditor.Handles.DrawCapFunction capFunc = UnityEditor.Handles.SphereCap; #endif UnityEditor.Handles.ScaleValueHandle(0, pos, UnityEngine.Quaternion.identity, handleSize, capFunc, 0); if (curPointIndex == i) { pos = UnityEditor.Handles.PositionHandle(pos, UnityEngine.Quaternion.identity); } // Get the needed data after the handle var controlIDAfterHandle = UnityEngine.GUIUtility.GetControlID(someHashCode, UnityEngine.FocusType.Passive); var isEventUsedByHandle = !isEventUsedBeforeHandle && UnityEngine.Event.current.type == UnityEngine.EventType.Used; if (controlIDBeforeHandle < UnityEngine.GUIUtility.hotControl && UnityEngine.GUIUtility.hotControl < controlIDAfterHandle || isEventUsedByHandle) { curPointIndex = i; } m_AkAmbient.multiPositionArray[i] = pos; } if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.Large_Mode) { UnityEditor.Handles.BeginGUI(); var size = new UnityEngine.Rect(0, 0, 200, 70); UnityEngine.GUI.Window(0, new UnityEngine.Rect(UnityEngine.Screen.width - size.width - 10, UnityEngine.Screen.height - size.height - 50, size.width, size.height), DoMyWindow, "AkAmbient Tool Bar"); UnityEditor.Handles.EndGUI(); } }
private void DoCutOverrideModeHandles(Ferr2D_Path path, Ferr2DT_PathTerrain terrain, Matrix4x4 mat, Transform camTransform) { List <List <int> > segments = new List <List <int> >(); List <Ferr2DT_TerrainDirection> dirs = new List <Ferr2DT_TerrainDirection>(); List <Vector2> rawVerts = path.GetVertsRaw(); // cut the terrain into segments, we need segment info to draw these points segments = terrain.GetSegments(rawVerts, out dirs); for (int s = 0; s < segments.Count; s++) { List <int> currSeg = segments[s]; List <Vector2> currVerts = Ferr2D_Path.IndicesToList(rawVerts, currSeg); List <Ferr2DT_PathTerrain.CutOverrides> overrides = Ferr2D_Path.IndicesToList(terrain.cutOverrides, currSeg); // find information about this segment Ferr2DT_TerrainDirection currDir = dirs[s]; Ferr2DT_SegmentDescription desc = default(Ferr2DT_SegmentDescription); if (currDir != Ferr2DT_TerrainDirection.None) { desc = terrain.TerrainMaterial.GetDescriptor(currDir); } else { desc = terrain.GetDescription(currSeg); } // if there's no body segment choices, don't bother with the rest of this if (desc.body.Length < 2) { continue; } Vector2 capLeftSlideDir = (currVerts[1] - currVerts[0]); Vector2 capRightSlideDir = (currVerts[currVerts.Count - 2] - currVerts[currVerts.Count - 1]); capLeftSlideDir.Normalize(); capRightSlideDir.Normalize(); currVerts[0] -= capLeftSlideDir * desc.capOffset; currVerts[currVerts.Count - 1] -= capRightSlideDir * desc.capOffset; float distance = Ferr2D_Path.GetSegmentLength(currVerts); // how many texture cuts are there on the segment float bodyWidth = desc.body[0].width * (terrain.TerrainMaterial.edgeMaterial.mainTexture.width / terrain.pixelsPerUnit); int textureCuts = Mathf.Max(1, Mathf.FloorToInt(distance / bodyWidth + 0.5f)); // data is attached to the points still, check if we've switched to a new point int activePt = -1; int activeLocalCut = -1; for (int c = 0; c < textureCuts; c++) { float pctGlobal = c / (float)textureCuts; int ptLocal = 0; float pctLocal = 0; Ferr2D_Path.PathGlobalPercentToLocal(currVerts, pctGlobal, out ptLocal, out pctLocal, distance, false); if (ptLocal != activePt) { // if they size down, we need to shorten the data too if (activePt != -1) { CapListSize <int>(ref overrides[activePt].data, activeLocalCut + 3); } activePt = ptLocal; activeLocalCut = 0; if (overrides[activePt].data == null) { overrides[activePt].data = new List <int>(); } } while (activeLocalCut >= overrides[activePt].data.Count) { overrides[activePt].data.Add(0); } CapFunction cap = CapDotAuto; int activeOverride = overrides[activePt].data[activeLocalCut]; if (activeOverride != 0) { if (activeOverride == 1) { cap = CapDot1; } else if (activeOverride == 2) { cap = CapDot2; } else if (activeOverride == 3) { cap = CapDot3; } else if (activeOverride == 4) { cap = CapDot4; } else if (activeOverride == 5) { cap = CapDot5; } else if (activeOverride >= 6) { cap = CapDotN; } } if (Event.current.alt) { cap = CapDotReset; } int ptShow = 0; float pctShow = 0; Ferr2D_Path.PathGlobalPercentToLocal(currVerts, pctGlobal + (1f / textureCuts) * 0.5f, out ptShow, out pctShow, distance, false); Vector2 pt = Ferr2D_Path.LinearGetPt(currVerts, ptShow, pctShow, false); Vector3 pos = mat.MultiplyPoint3x4(pt); float sc = HandleScale(pos) * 0.5f; if (Handles.Button(pos, camTransform.rotation, sc, sc, cap)) { Undo.RecordObject(terrain, "Lock Texture Segment"); overrides[activePt].data[activeLocalCut] = Event.current.alt ? 0 : (activeOverride + 1) % (desc.body.Length + 1); EditorUtility.SetDirty(terrain); GUI.changed = true; } activeLocalCut += 1; } if (activePt != -1) { CapListSize <int>(ref overrides[activePt].data, activeLocalCut + 3); } } }
private void DoNormalModeHandles(Ferr2D_Path path, Ferr2DT_PathTerrain terrain, int i, Matrix4x4 mat, Matrix4x4 invMat, Transform camTransform) { int nextId = i == path.Count - 1?(path.closed?0:i - 1):i + 1; Vector3 pos = mat.MultiplyPoint3x4(path.pathVerts[i]); Vector3 posNext = mat.MultiplyPoint3x4(path.pathVerts[nextId]); Vector3 normal = -(Vector3)Ferr2D_Path.GetNormal(path.pathVerts, i, path.closed); bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } // check for moving the point CapFunction cap = CapDot; if (Event.current.control) { cap = isSelected ? (CapFunction)CapDotSelectedSnap : (CapFunction)CapDotSnap; } else { cap = isSelected ? (CapFunction)CapDotSelected : (CapFunction)CapDot; } Vector3 result = Handles.FreeMoveHandle(pos, camTransform.rotation, HandleScale(pos), snap, cap); if (result != pos) { EnsureVertSelected(i, ref isSelected); Vector2 relative = GetRelativeMovementWithSnap(result, invMat, i, path); for (int s = 0; s < selectedPoints.Count; s++) { path.pathVerts[selectedPoints[s]] += relative; } } if (Ferr2DT_SceneOverlay.showIndices) { Vector3 labelPos = pos + normal; Handles.color = Color.white; Handles.Label(labelPos, "" + i); } if (!Ferr2DT_SceneOverlay.segmentLockMode) { float scale = HandleScale(pos) * 0.5f; Vector3 displayPos = pos; if (path.closed || i + 1 < path.pathVerts.Count) { displayPos = GetOverridePos(i, path, mat, pos, posNext); if (IsVisible(displayPos) && terrain.directionOverrides != null) { cap = Event.current.alt ? (CapFunction)CapDotReset : GetDirIcon(terrain.directionOverrides[i]); if (Handles.Button(displayPos, camTransform.rotation, scale, scale, cap)) { EnsureVertSelected(i, ref isSelected); Undo.RecordObject(terrain, "Override Vert Direction"); Ferr2DT_TerrainDirection dir = NextDir(terrain.directionOverrides[i]); for (int s = 0; s < selectedPoints.Count; s++) { terrain.directionOverrides[selectedPoints[s]] = dir; } EditorUtility.SetDirty(terrain); GUI.changed = true; } } } displayPos = pos + normal * terrain.vertScales[i] * 2 * Ferr2DT_Menu.PathScale; if (IsVisible(displayPos)) { cap = Event.current.alt ? (CapFunction)CapDotReset : (CapFunction)CapDotScale; Vector3 scaleMove = Handles.FreeMoveHandle(displayPos, camTransform.rotation, scale, Vector3.zero, cap); float scaleAmt = Vector3.Distance(displayPos, scaleMove); if (Mathf.Abs(scaleAmt) > 0.01f) { EnsureVertSelected(i, ref isSelected); Undo.RecordObject(terrain, "Scale Path Vert"); float vertScale = Vector3.Distance(scaleMove, pos) / 2 / Ferr2DT_Menu.PathScale; vertScale = Mathf.Clamp(vertScale, 0.2f, 3f); for (int s = 0; s < selectedPoints.Count; s++) { terrain.vertScales[selectedPoints[s]] = vertScale; } EditorUtility.SetDirty(terrain); GUI.changed = true; } } // make sure we can add new point at the midpoints! if (i + 1 < path.pathVerts.Count || path.closed == true) { Vector3 mid = (pos + posNext) / 2; float handleScale = HandleScale(mid); if (Handles.Button(mid, camTransform.rotation, handleScale, handleScale, CapDotPlus)) { Vector2 pt = invMat.MultiplyPoint3x4(mid); terrain.AddPoint(pt, nextId); EditorUtility.SetDirty(terrain); GUI.changed = true; } } } }
Rect ResizeRect(Rect rect, UnityEditor.Handles.CapFunction capFunc, Color capCol, Color fillCol, float capSize, float snap)