Example #1
0
        void AddConnection(SplineComputer computer, int pointIndex)
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            if (EditorUtility.DisplayDialog("Link point?", "Add point " + (pointIndex + 1) + " to connections?", "Yes", "No"))
            {
                Undo.RecordObject(addComp, "Add connection");
                Undo.RecordObject(node, "Add Connection");
                if (connections.Length == 0)
                {
                    switch (EditorUtility.DisplayDialogComplex("Align node to point?", "This is the first connection for the node, would you like to snap or align the node's Transform the spline point.", "No", "Snap", "Snap and Align"))
                    {
                    case 1: SplinePoint point = addComp.GetPoint(pointIndex);
                        node.transform.position = point.position;
                        break;

                    case 2:
                        SplineSample result = addComp.Evaluate(pointIndex);
                        node.transform.position = result.position;
                        node.transform.rotation = result.rotation;
                        break;
                    }
                }
                computer.ConnectNode(node, pointIndex);
                addComp  = null;
                addPoint = 0;
                SceneView.RepaintAll();
                Repaint();
            }
        }
Example #2
0
    private Vector3 GetInstanceDotPositionRay(Transform handTransform, Transform playerTransform)
    {
        Vector3 finalDotPosition    = spline.GetPoint(spline.GetPoints().Length - 1).position;
        Vector3 focusRay            = handTransform.forward * 30 + playerTransform.position;
        Vector3 pointToRayDirection = (focusRay - finalDotPosition).normalized;
        Vector3 newDotPosition      = finalDotPosition + pointToRayDirection * GameManager.Instance.datas.distanceInit;

        return(newDotPosition);
    }
 void InstantiateANewAnchor(bool previsualisation)
 {
     if (previsualisation == false)
     {
         double      percentPrecedent = splineFollower.result.percent;
         double      nbrPoints        = (double)spline.pointCount;
         SplinePoint lastPoint        = spline.GetPoint(spline.pointCount - 1);
         Vector3     posPop           = GetInstanceDotPositionRay();
         SplinePoint newPoint         = new SplinePoint();
         newPoint.position = posPop;
         newPoint.normal   = curveInstantiator.up;
         newPoint.size     = 1f;
         newPoint.color    = Color.white;
         Vector3 distance = lastPoint.tangent2 - newPoint.position;
         newPoint.tangent  = distance / 2f + newPoint.position;
         newPoint.tangent2 = -distance / 2f + newPoint.position;
         CreateAPoint(newPoint);
         spline.RebuildImmediate();
         splineFollower.result.percent = (double)(percentPrecedent / ((double)1 / (double)nbrPoints * ((double)nbrPoints + (double)1)));
     }
     else
     {
         SplinePoint   lastPoint = spline.GetPoint(spline.pointCount - 1);
         SplinePoint[] points    = new SplinePoint[2];
         points[0] = lastPoint;
         Vector3 newPos = GetInstanceDotPositionRay();
         points[1].position = newPos;
         points[1].normal   = curveInstantiator.transform.up;
         points[1].size     = 1f;
         points[1].color    = Color.red;
         Vector3 distance = points[0].tangent2 - points[1].position;
         points[1].tangent  = distance / 1.5f + points[1].position;
         points[1].tangent2 = -distance / 1.5f + points[1].position;
         previsualisationSpline.SetPoints(points);
     }
 }
Example #4
0
    public static bool BuildSplineComputer(GrindSegment segment)
    {
        // Create Spline Computer component and settings for GrindSpline Object
        SplineComputer sc = segment.grindRoot.gameObject.AddComponent <SplineComputer>();

        sc.type = Spline.Type.Linear;
        sc.SetPoints(segment.points, SplineComputer.Space.World);
        sc.Evaluate(0.9);

        // Shift normal vectors up a position for spline points points
        segment.normals[segment.normals.Length - 1] = segment.normals[segment.normals.Length - 2];

        // Set point normals
        for (int i = 0; i < segment.points.Length; i++)
        {
            sc.SetPointNormal(i, sc.GetPoint(i, SplineComputer.Space.World).normal + segment.normals[i], SplineComputer.Space.World);
        }

        return(true);
    }
    void InstantiateForEndOfRoad()
    {
        //new point
        SplinePoint lastPoint = spline.GetPoint(spline.pointCount - 1);

        Vector3     newPos   = GetNewPosition(spline.GetPoint(spline.pointCount - 1).tangent2 - spline.GetPoint(spline.pointCount - 1).position);
        SplinePoint newPoint = new SplinePoint();

        newPoint.position = newPos;
        newPoint.normal   = curveInstantiator.transform.up;
        newPoint.size     = 1f;
        newPoint.color    = Color.white;
        Vector3 distance = lastPoint.tangent2 - newPoint.position;

        newPoint.tangent  = distance / 1.5f + newPoint.position;
        newPoint.tangent2 = -distance / 1.5f + newPoint.position;

        //CreateAPointClampSpline(newPoint);
        CreateAPoint(newPoint);
        spline.RebuildImmediate();
        splineFollower.result.percent = (double)(splineFollower.result.percent / ((double)1 / (double)(double)spline.pointCount
                                                                                  * ((double)(double)spline.pointCount + (double)1)));
        MakeThePathSmaller();
    }