public Vector3 Goto(float t)
 {
     return(_spline.EvaluatePosition(t));
 }
Exemplo n.º 2
0
    void EndOfDraw()
    {
        if (spline == null)
        {
            return;
        }
        var prevLength = SplineLength;

        SplineLength = spline.CalculateLength();
        if (SplineLength < 0.01)
        {
            SplineLength = prevLength;
            return;
        }
        double  travel = spline.Travel(0, SplineLength / 2f);
        Vector3 middle = spline.EvaluatePosition(travel);



        if ((points[0].position.x < 0 && points[0].position.z >= -14f) && (points[pointCount - 1].position.x >= 1 && points[pointCount - 1].position.z <= -15))
        {
            Direction = "Right";
        }
        else if ((points[0].position.x > 0 && points[0].position.z >= -14f) && (points[pointCount - 1].position.x <= 1 && points[pointCount - 1].position.z <= -15))
        {
            Direction = "Left";
        }
        else
        {
            if (middle.x > 1f)
            {
                Direction = "Right";
            }
            else if (middle.x < -1f)
            {
                Direction = "Left";
            }
            else
            {
                Direction = "Forward";
            }
        }



        //Make disable all children of wingsPoint
        if (WingsPoint.transform.childCount != 0)
        {
            for (int i = 0; i < WingsPoint.transform.childCount; i++)
            {
                Destroy(WingsPoint.transform.GetChild(i).gameObject);
            }
        }


        Transform player = WingsPoint.GetComponentInParent <Transform>();


        GameObject transporter = (GameObject)Instantiate(DrawObjPref, closest, Quaternion.identity);

        if (createdDrawObj.GetComponent <MeshCollider>() == null)
        {
            createdDrawObj.AddComponent <MeshCollider>().convex = true;
        }
        else
        {
            createdDrawObj.GetComponent <MeshCollider>().convex = true;
        }
        createdDrawObj.AddComponent <WingCrashController>();
        createdDrawObj.transform.parent = transporter.transform;
        //createdDrawObj.transform.localPosition = Vector3.zero;

        transporter.transform.position = WingsPoint.transform.position;

        transporter.transform.rotation      = WingsPoint.GetComponentInParent <Transform>().rotation;
        transporter.transform.parent        = WingsPoint.transform;
        transporter.transform.localPosition = Vector3.zero;
        createdDrawObj.GetComponent <MeshRenderer>().enabled = true;
        isDrawComeFromOutside = true;


        Destroy(m_currentRenderer);
        Destroy(splineMesh);
        Destroy(spline);

        EventManager.FirstDrawExist.Invoke();
    }
Exemplo n.º 3
0
        public static void DrawSplineComputer(SplineComputer comp, double fromPercent = 0.0, double toPercent = 1.0, float alpha = 1f)
        {
            if (comp == null)
            {
                return;
            }
            Color prevColor   = Handles.color;
            Color orange      = new Color(1f, 0.564f, 0f);
            Color handleColor = comp.editorPathColor;

            handleColor.a = alpha;
            Handles.color = handleColor;
            if (comp.pointCount < 2)
            {
                return;
            }

            if (comp.type == Spline.Type.BSpline && comp.pointCount > 1)
            {
                SplinePoint[] compPoints = comp.GetPoints();
                Handles.color = new Color(handleColor.r, handleColor.g, handleColor.b, 0.5f * alpha);
                for (int i = 0; i < compPoints.Length - 1; i++)
                {
                    Handles.DrawLine(compPoints[i].position, compPoints[i + 1].position);
                }
                Handles.color = handleColor;
            }

            if (!comp.drawThinckness)
            {
                if (positions.Length != comp.sampleCount * 2)
                {
                    positions = new Vector3[comp.sampleCount * 2];
                }
                Vector3 prevPoint  = comp.EvaluatePosition(fromPercent);
                int     pointIndex = 0;
                for (int i = 1; i < comp.sampleCount; i++)
                {
                    positions[pointIndex] = prevPoint;
                    pointIndex++;
                    positions[pointIndex] = comp.samples[i].position;
                    pointIndex++;
                    prevPoint = positions[pointIndex - 1];
                }
                Handles.DrawLines(positions);
            }
            else
            {
                Transform editorCamera = SceneView.currentDrawingSceneView.camera.transform;
                if (positions.Length != comp.sampleCount * 6)
                {
                    positions = new Vector3[comp.sampleCount * 6];
                }
                SplineSample prevResult = comp.Evaluate(fromPercent);
                Vector3      prevNormal = prevResult.normal;
                if (comp.billboardThickness)
                {
                    prevNormal = (editorCamera.position - prevResult.position).normalized;
                }
                Vector3 prevRight  = Vector3.Cross(prevResult.direction, prevNormal).normalized *prevResult.size * 0.5f;
                int     pointIndex = 0;
                for (int i = 1; i < comp.sampleCount; i++)
                {
                    SplineSample newResult = comp.samples[i];
                    Vector3      newNormal = newResult.normal;
                    if (comp.billboardThickness)
                    {
                        newNormal = (editorCamera.position - newResult.position).normalized;
                    }
                    Vector3 newRight = Vector3.Cross(newResult.direction, newNormal).normalized *newResult.size * 0.5f;

                    positions[pointIndex] = prevResult.position + prevRight;
                    positions[pointIndex + comp.sampleCount * 2] = prevResult.position - prevRight;
                    positions[pointIndex + comp.sampleCount * 4] = newResult.position - newRight;
                    pointIndex++;
                    positions[pointIndex] = newResult.position + newRight;
                    positions[pointIndex + comp.sampleCount * 2] = newResult.position - newRight;
                    positions[pointIndex + comp.sampleCount * 4] = newResult.position + newRight;
                    pointIndex++;
                    prevResult = newResult;
                    prevRight  = newRight;
                    prevNormal = newNormal;
                }
                Handles.DrawLines(positions);
            }
            Handles.color = prevColor;
        }
Exemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     transform.position = spline.EvaluatePosition(percent);
 }