Ejemplo n.º 1
0
 private void DrawStraightLine(RiverSystem river)
 {
     foreach (var pair in river.GetControlPointPairs(river.ControlPoints))
     {
         Handles.DrawLine(river.transform.position + pair.First.Position, river.transform.position + pair.Second.Position);
     }
 }
Ejemplo n.º 2
0
        private void DrawCurvedLine(RiverSystem river)
        {
            var leftRotation = Quaternion.LookRotation(Vector3.left);
            var rightotation = Quaternion.LookRotation(Vector3.right);

            foreach (var pair in river.GetControlPointPairs(river.ControlPoints))
            {
                var distance        = (pair.Second.Position - pair.First.Position).magnitude / 3;
                var firstPoint      = pair.First.Position + river.transform.position;
                var lastPoint       = pair.Second.Position + river.transform.position;
                var extraPosition01 = pair.First.Position + pair.First.Direction * Vector3.forward * distance + river.transform.position;
                var extraPosition02 = pair.Second.Position + pair.Second.Direction * Vector3.back * distance + river.transform.position;

                Handles.DrawBezier(firstPoint, lastPoint, extraPosition01, extraPosition02, Color.green, null, 2);
            }
        }
Ejemplo n.º 3
0
        private void ShowControlPoint(RiverSystem.RiverControlPoint controlPoint, RiverSystem river)
        {
            var   position = river.transform.position + controlPoint.Position;
            float size     = HandleUtility.GetHandleSize(position) * 1f;

            EditorGUI.BeginChangeCheck();
            controlPoint.Position  = Handles.DoPositionHandle(position, controlPoint.Direction) - river.transform.position;
            controlPoint.Direction = Handles.Disc(controlPoint.Direction, position, Vector3.up, 1, false, 0);
            controlPoint.Width     = Mathf.Clamp(Handles.ScaleSlider(controlPoint.Width, position, controlPoint.Direction * Vector3.left, controlPoint.Direction, 2, 0), 0.2f, float.MaxValue);
            Handles.DrawLine(position + controlPoint.Direction * Vector3.left * controlPoint.Width, position);
            Handles.DrawLine(position + controlPoint.Direction * Vector3.right * controlPoint.Width, position);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(river, "Edited River controlpoint");
                river.UpdateRiverMesh();
                EditorUtility.SetDirty(river);
            }
        }
Ejemplo n.º 4
0
 private InWorldPosition GetInWorldPoint(Vector2 position, RiverSystem river)
 {
     if (Physics.Raycast(HandleUtility.GUIPointToWorldRay(position), out RaycastHit raycastHit))
     {
         if (raycastHit.collider.gameObject == river.gameObject)
         {
             return(new InWorldPosition {
                 Position = raycastHit.point, IsInWorld = true, IsInRiver = true, ControlPoints = GetSelectedControlPoint(raycastHit, river)
             });
         }
         else
         {
             return(new InWorldPosition {
                 Position = raycastHit.point, IsInWorld = true, IsInRiver = false
             });
         }
     }
     else
     {
         return(new InWorldPosition {
             Position = Vector3.zero, IsInWorld = false
         });
     }
 }
Ejemplo n.º 5
0
        private RiverSystem.ControlPointPair GetSelectedControlPoint(RaycastHit raycastHit, RiverSystem river)
        {
            // Each segment consist of a quad(2 tris, 6 indices)
            var segmentIndex         = raycastHit.triangleIndex / 2;
            var placedSegmentIndex   = Mathf.Clamp((segmentIndex + 1) / (river.SmoothingLevel + 1), 0, int.MaxValue);
            var previousSegmentIndex = Mathf.Clamp(segmentIndex / (river.SmoothingLevel + 1), 0, int.MaxValue);

            if (previousSegmentIndex == placedSegmentIndex)
            {
                previousSegmentIndex = placedSegmentIndex + 1;
            }

            return(new RiverSystem.ControlPointPair(river.ControlPoints [placedSegmentIndex], river.ControlPoints[previousSegmentIndex]));
        }