protected virtual void OnSceneGUI()
    {
        circlePath = target as CirclePath;

        Vector3 prevPathPos = circlePath.GetPoint(0f);

        int iterations = 100;

        for (int i = 1; i <= iterations; i++)
        {
            Vector3 pathPos = circlePath.GetPoint(i / (float)iterations);
            Handles.DrawLine(pathPos, prevPathPos);

            prevPathPos = pathPos;
        }

        int numIterations = 10 * Mathf.CeilToInt(circlePath.CircleRadius);

        for (int i = 1; i < numIterations; i++)
        {
            float alpha = i / (float)numIterations;

            Vector3 pos    = circlePath.GetPoint(alpha);
            Vector3 normal = circlePath.GetNormal(alpha);

            Handles.color = Color.green;
            Handles.DrawLine(pos, pos + normal * 0.4f);
        }
    }
    private void OnEnable()
    {
        Undo.undoRedoPerformed += UndoRedoPerformed;

        circlePath = target as CirclePath;
        circlePath.OnPathChanged(circlePath);
    }
Beispiel #3
0
        public static CAShapeLayer ToShape(this CirclePath element)
        {
            var shape      = new CAShapeLayer();
            var bezierPath = NSBezierPath.FromOvalInRect(new CGRect(0, 0, element.Radio * 2, element.Radio * 2));

            shape.Path = bezierPath.ToCGPath();

            if (!string.IsNullOrEmpty(element.Stroke))
            {
                shape.StrokeColor = XExtensions.ConvertToNSColor(element.Stroke).CGColor;
            }

            shape.LineWidth = element.StrokeWidth;

            if (!string.IsNullOrEmpty(element.Fill))
            {
                shape.FillColor = XExtensions.ConvertToNSColor(element.Fill).CGColor;
            }

            var diameter = element.Radio * 2;

            shape.Bounds = new CGRect(0, 0, diameter, diameter);

            return(shape);
        }
    public void Reset()
    {
        EditorOnlyToolSettings = new ToolSettings(hideHandles: true);

        Circle localCircle = new Circle(radius: 1f);
        Path = new CirclePath(this.transform, localCircle);
    }
Beispiel #5
0
    public void Reset()
    {
        EditorOnlyToolSettings = new ToolSettings(hideHandles: true);

        Circle localCircle = new Circle(radius: 1f);

        Path = new CirclePath(this.transform, localCircle);
    }
Beispiel #6
0
    private void OnEnable()
    {
        targetScript = (CirclePathComponent)target;
        circlePath   = targetScript.Path;
        settings     = targetScript.EditorOnlyToolSettings;

        if (!Safety())
        {
            SceneView.currentDrawingSceneView.ShowNotification(new GUIContent(PathEditorUtility.EditorUnavailable));
            return;
        }
    }
    public override void OnInspectorGUI()
    {
        float prevFillAmount = circlePath.FillAmount;
        bool  prevLoop       = circlePath.Loop;

        base.OnInspectorGUI();

        circlePath = target as CirclePath;

        SerializedObject so = new SerializedObject(circlePath);

        if (GUI.changed)
        {
            if (prevLoop != circlePath.Loop)
            {
                if (circlePath.Loop && circlePath.FillAmount != 1f)
                {
                    circlePath.SetFillAmount(1f);
                }

                if (prevLoop && circlePath.FillAmount == 1f)
                {
                    circlePath.SetFillAmount(0.99f);
                }

                prevFillAmount = circlePath.FillAmount;
            }

            if (prevFillAmount != circlePath.FillAmount)
            {
                if (circlePath.FillAmount == 1f && !circlePath.Loop)
                {
                    circlePath.SetLoop(true);
                }

                if (prevFillAmount == 1f && circlePath.Loop)
                {
                    circlePath.SetLoop(false);
                }

                prevLoop = circlePath.Loop;
            }

            circlePath.OnPathChanged(circlePath);
        }
    }
Beispiel #8
0
    public bool Safety()
    {
        bool safe = true;

        //~ Fixes first run issues
        if (settings == null)
        {
            targetScript.Reset();
            safe = false;
        }
        circlePath = targetScript.Path;
        settings   = targetScript.EditorOnlyToolSettings;

        //~ Fixes deleted transform issues
        if (circlePath.LocalSpaceTransform == null)
        {
            circlePath.LocalSpaceTransform = null;
            safe = false;
        }

        return(safe);
    }
Beispiel #9
0
    private void Awake()
    {
        ar            = MusicPlayer.CurrentPlaying.DifficultySection.ApproachRate;
        cs            = MusicPlayer.CurrentPlaying.DifficultySection.CircleSize;
        hp            = MusicPlayer.CurrentPlaying.DifficultySection.HPDrainRate;
        od            = MusicPlayer.CurrentPlaying.DifficultySection.OverallDifficulty;
        rectTransform = GetComponent <RectTransform>();
        canvasGroup   = GetComponent <CanvasGroup>();
        if (ar <= 5)
        {
            fadeIn  = (int)(800 + 400 * (5 - ar) / 5);
            preempt = (int)(1200 + 600 * (5 - ar) / 5);
        }
        else
        {
            fadeIn  = (int)(800 - 500 * (ar - 5) / 5);
            preempt = (int)(1200 - 750 * (ar - 5) / 5);
        }
        lineRenderer = GetComponent <LineRenderer>();
        lineRenderer.material.SetColor
        (
            "_Color",
            new Color
            (
                lineRenderer.material.color.r,
                lineRenderer.material.color.g,
                lineRenderer.material.color.b,
                0
            )
        );
        slider = (OsuHitObjects.Slider)MusicPlayer.CurrentPlaying.HitObjects[PlayField.CurrentHitObject];
        slider.SliderPoints.Insert(0, slider.Position);
        rectTransform = GetComponent <RectTransform>();
        meshFilter    = GetComponent <MeshFilter>();
        meshRenderer  = GetComponent <MeshRenderer>();
        curves        = new List <BezierPath>();
        lineRenderer.numCornerVertices = 16;
        lineRenderer.numCapVertices    = 16;
        switch (slider.CurveType)
        {
        case CurveType.Bezier:
        {
            name = "Bezier Slider(Clone)";
            int  start            = 0;
            bool isMultipleCurves = false;
            for (int i = 1; i < slider.SliderPoints.Count; i++)
            {
                if (slider.SliderPoints[i] == slider.SliderPoints[i - 1])
                {
                    isMultipleCurves = true;
                    List <System.Numerics.Vector2> controlPoints = new List <System.Numerics.Vector2>();
                    for (int j = start; j < i; j++)     // split the SliderPoint list into separate curves(a bezier can be composed of multiple curves)
                    {
                        controlPoints.Add(Utilities.OsuPixelToScreenPoint(slider.SliderPoints[j]));
                    }
                    curves.Add(new BezierPath(controlPoints, ACCURACY, ACCURACY));
                    start = i;
                }
            }
            if (!isMultipleCurves)
            {
                curves.Add(new BezierPath(Utilities.OsuPixelsToScreenPoints(slider.SliderPoints), ACCURACY, ACCURACY));
            }
            lineRenderer.positionCount = ACCURACY * curves.Count;
            for (int i = 0; i < curves.Count; i++)     // unpack all calculated points into the line renderer
            {
                for (int j = 0; j < curves[i].Points.Count; j++)
                {
                    points.Add(Utilities.ScreenToWorldPoint2D(curves[i].Points[j].X, curves[i].Points[j].Y));
                    evenlySpacedPoints.Add(Utilities.ScreenToWorldPoint2D(curves[i].EvenlySpacedPoints[j].X, curves[i].EvenlySpacedPoints[j].Y));
                }
            }
            lineRenderer.SetPositions(points.ToArray());
            break;
        }

        case CurveType.Catmull:
        {
            name = "Catmull Slider(Clone)";
            Debug.LogWarning("Catmull sliders are currently not supproted.");
            Destroy(gameObject);
            break;
        }

        case CurveType.Linear:
        {
            name       = "Linear Slider(Clone)";
            linearPath = new LinearPath(Utilities.OsuPixelToScreenPoint(slider.SliderPoints[0]), Utilities.OsuPixelToScreenPoint(slider.SliderPoints[slider.SliderPoints.Count - 1]), ACCURACY, ACCURACY);
            lineRenderer.positionCount = ACCURACY;
            foreach (System.Numerics.Vector2 v in linearPath.Points)
            {
                points.Add(Utilities.ScreenToWorldPoint2D(v.X, v.Y));
            }
            foreach (System.Numerics.Vector2 ev in linearPath.EvenlySpacedPoints)
            {
                evenlySpacedPoints.Add(Utilities.ScreenToWorldPoint2D(ev.X, ev.Y));
            }
            lineRenderer.SetPositions(points.ToArray());
            break;
        }

        case CurveType.PerfectCurve:
        {
            name       = "Circle Slider(Clone)";
            circlePath = new CirclePath(Utilities.OsuPixelToScreenPoint(slider.SliderPoints[0]), Utilities.OsuPixelToScreenPoint(slider.SliderPoints[1]), Utilities.OsuPixelToScreenPoint(slider.SliderPoints[2]), ACCURACY, ACCURACY);
            foreach (System.Numerics.Vector2 v in circlePath.Points)
            {
                points.Add(Utilities.ScreenToWorldPoint2D(v.X, v.Y));
            }
            foreach (System.Numerics.Vector2 ev in circlePath.EvenlySpacedPoints)
            {
                evenlySpacedPoints.Add(Utilities.ScreenToWorldPoint2D(ev.X, ev.Y));
            }
            lineRenderer.positionCount = ACCURACY;
            lineRenderer.SetPositions(points.ToArray());
            break;
        }
        }
        sliderSnakingInterval = (float)fadeIn / lineRenderer.positionCount;
        originalPositionCount = lineRenderer.positionCount;
    }
    private void OnEnable()
    {
        targetScript = (CirclePathComponent)target;
        circlePath = targetScript.Path;
        settings = targetScript.EditorOnlyToolSettings;

        if (!Safety())
        {
            SceneView.currentDrawingSceneView.ShowNotification(new GUIContent(PathEditorUtility.EditorUnavailable));
            return;
        }
    }
    private void Draw()
    {
        Vector3 startPoint = circlePath.Evaluate(0f);
        Vector3 endPoint = circlePath.Evaluate(1f);
        CirclePath reducedCirclePath = new CirclePath(
            circlePath.LocalSpaceTransform,
            new Circle(circlePath.LocalCircle.Center, circlePath.LocalCircle.Radius),
            circlePath.MaxAngle % Circle.TwoPI // remove loops
            );
        if (circlePath.MaxAngle >= Circle.TwoPI) // add back a single loop if it loops
            reducedCirclePath.MaxAngle += Circle.TwoPI;
        else if (Mathf.Abs(circlePath.MaxAngle) >= Circle.TwoPI) // if negative maxAngle and is still at least one loop
            reducedCirclePath.MaxAngle -= Circle.TwoPI;

        // draw circle
        var cPointCache = new EvaluationCache(reducedCirclePath, 128).Values;
        /*Handles.color = Color.yellow;
        Handles.DrawAAPolyLine(cPointCache);
        */
        for (int i = 0; i < cPointCache.Length - 1; i++)
        {
            Handles.color = Color.Lerp(Color.yellow, Color.magenta, (float)i / cPointCache.Length);
            var lineSegment = new Vector3[2];
            lineSegment[0] = cPointCache[i];
            lineSegment[1] = cPointCache[i + 1];
            Handles.DrawAAPolyLine(lineSegment);
        }

        // draw direction cone cap
        if (!settings.HideDirectionCones
            && circlePath.LocalSpaceTransform.lossyScale != Vector3.zero
            && circlePath.LocalCircle.Radius != 0f
            && Mathf.Abs(reducedCirclePath.MaxAngle * Mathf.Rad2Deg) > 10.0f) // also hide cones if virtually a dot
        {
            float startConeSize = PathEditorUtility.Nice3DHandleSize(startPoint);
            float endConeSize = PathEditorUtility.Nice3DHandleSize(endPoint);

            Handles.color = Color.yellow;
            Handles.ConeCap(0, startPoint, Quaternion.LookRotation(circlePath.Tangent(0f)), startConeSize);
            Handles.color = Color.magenta;
            Handles.ConeCap(0, endPoint, Quaternion.LookRotation(circlePath.Tangent(1f)), endConeSize);
        }

        // test t
        if (settings.TestInterpolate)
            PathEditorUtility.DrawTestInterpolate(circlePath, settings.EditorData.T);

        #region Scene View GUI

        Handles.BeginGUI(); //Note: GUILayout.BeginArea() deprecates Handles, however it behaves incorrectly (debug lines offset)
        {
            GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
            {
                GUILayout.Space(20.0f);
                targetScript.EditorOnlyToolSettings.TestInterpolate
                    = GUILayout.Toggle(targetScript.EditorOnlyToolSettings.TestInterpolate, "Test Interpolate", GUILayout.ExpandWidth(false));
                if (targetScript.EditorOnlyToolSettings.TestInterpolate)
                {
                    settings.EditorData.T
                        = GUILayout.HorizontalSlider(settings.EditorData.T, 0f, 1.0f, GUILayout.Width(100.0f));
                    GUILayout.Label(settings.EditorData.T.ToString(), GUILayout.Width(75.0f));
                    GUILayout.Label("Custom: ", GUILayout.Width(60.0f));
                    settings.EditorData.CustomT
                        = GUILayout.TextField(settings.EditorData.CustomT, GUILayout.Width(100.0f));
                    if (Event.current.keyCode == KeyCode.Return)
                    {
                        float tempT;
                        if (System.Single.TryParse(settings.EditorData.CustomT, out tempT))
                            settings.EditorData.T = tempT;
                    }
                }
            }
            GUILayout.EndHorizontal();
        }

        Handles.EndGUI();

        #endregion Scene View GUI

        ToolShelf();
    }
    public bool Safety()
    {
        bool safe = true;

        //~ Fixes first run issues
        if (settings == null)
        {
            targetScript.Reset();
            safe = false;
        }
        circlePath = targetScript.Path;
        settings = targetScript.EditorOnlyToolSettings;

        //~ Fixes deleted transform issues
        if (circlePath.LocalSpaceTransform == null)
        {
            circlePath.LocalSpaceTransform = null;
            safe = false;
        }

        return safe;
    }
 public CirclePathModel(CirclePath ps)
     : base(ps)
 {
     PathShape = ps;
 }
Beispiel #14
0
    private void Draw()
    {
        Vector3    startPoint        = circlePath.Evaluate(0f);
        Vector3    endPoint          = circlePath.Evaluate(1f);
        CirclePath reducedCirclePath = new CirclePath(
            circlePath.LocalSpaceTransform,
            new Circle(circlePath.LocalCircle.Center, circlePath.LocalCircle.Radius),
            circlePath.MaxAngle % Circle.TwoPI // remove loops
            );

        if (circlePath.MaxAngle >= Circle.TwoPI) // add back a single loop if it loops
        {
            reducedCirclePath.MaxAngle += Circle.TwoPI;
        }
        else if (Mathf.Abs(circlePath.MaxAngle) >= Circle.TwoPI) // if negative maxAngle and is still at least one loop
        {
            reducedCirclePath.MaxAngle -= Circle.TwoPI;
        }

        // draw circle
        var cPointCache = new EvaluationCache(reducedCirclePath, 128).Values;

        /*Handles.color = Color.yellow;
         * Handles.DrawAAPolyLine(cPointCache);
         */
        for (int i = 0; i < cPointCache.Length - 1; i++)
        {
            Handles.color = Color.Lerp(Color.yellow, Color.magenta, (float)i / cPointCache.Length);
            var lineSegment = new Vector3[2];
            lineSegment[0] = cPointCache[i];
            lineSegment[1] = cPointCache[i + 1];
            Handles.DrawAAPolyLine(lineSegment);
        }

        // draw direction cone cap
        if (!settings.HideDirectionCones &&
            circlePath.LocalSpaceTransform.lossyScale != Vector3.zero &&
            circlePath.LocalCircle.Radius != 0f &&
            Mathf.Abs(reducedCirclePath.MaxAngle * Mathf.Rad2Deg) > 10.0f)    // also hide cones if virtually a dot
        {
            float startConeSize = PathEditorUtility.Nice3DHandleSize(startPoint);
            float endConeSize   = PathEditorUtility.Nice3DHandleSize(endPoint);

            Handles.color = Color.yellow;
            Handles.ConeCap(0, startPoint, Quaternion.LookRotation(circlePath.Tangent(0f)), startConeSize);
            Handles.color = Color.magenta;
            Handles.ConeCap(0, endPoint, Quaternion.LookRotation(circlePath.Tangent(1f)), endConeSize);
        }

        // test t
        if (settings.TestInterpolate)
        {
            PathEditorUtility.DrawTestInterpolate(circlePath, settings.EditorData.T);
        }

        #region Scene View GUI

        Handles.BeginGUI(); //Note: GUILayout.BeginArea() deprecates Handles, however it behaves incorrectly (debug lines offset)
        {
            GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
            {
                GUILayout.Space(20.0f);
                targetScript.EditorOnlyToolSettings.TestInterpolate
                    = GUILayout.Toggle(targetScript.EditorOnlyToolSettings.TestInterpolate, "Test Interpolate", GUILayout.ExpandWidth(false));
                if (targetScript.EditorOnlyToolSettings.TestInterpolate)
                {
                    settings.EditorData.T
                        = GUILayout.HorizontalSlider(settings.EditorData.T, 0f, 1.0f, GUILayout.Width(100.0f));
                    GUILayout.Label(settings.EditorData.T.ToString(), GUILayout.Width(75.0f));
                    GUILayout.Label("Custom: ", GUILayout.Width(60.0f));
                    settings.EditorData.CustomT
                        = GUILayout.TextField(settings.EditorData.CustomT, GUILayout.Width(100.0f));
                    if (Event.current.keyCode == KeyCode.Return)
                    {
                        float tempT;
                        if (System.Single.TryParse(settings.EditorData.CustomT, out tempT))
                        {
                            settings.EditorData.T = tempT;
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
        }

        Handles.EndGUI();

        #endregion Scene View GUI

        ToolShelf();
    }