Esempio n. 1
0
            //Travel the spline segment while not exceeding the "max" percent
            //It also supports looping splines unlike the standard Travel methods found in SplineComputer and SplineUser
            double TravelClamped(double percent, float distance, Spline.Direction direction, double max, out float moved, bool loop)
            {
                moved = 0f;
                float  traveled = 0f;
                double result   = spline.Travel(percent, distance, out traveled, direction);

                moved += traveled;
                if (loop && moved < distance)
                {
                    if (direction == Spline.Direction.Forward && Mathf.Approximately((float)result, 1f))
                    {
                        result = spline.Travel(0.0, distance - moved, out traveled, direction);
                    }
                    else if (direction == Spline.Direction.Backward && Mathf.Approximately((float)result, 0f))
                    {
                        result = spline.Travel(1.0, distance - moved, out traveled, direction);
                    }
                    moved += traveled;
                }
                if (direction == Spline.Direction.Forward && percent <= max)
                {
                    if (result > max)
                    {
                        moved -= spline.CalculateLength(result, max);
                        result = max;
                    }
                }
                else if (direction == Spline.Direction.Backward && percent >= max)
                {
                    if (result < max)
                    {
                        moved -= spline.CalculateLength(max, result);
                        result = max;
                    }
                }
                return(result);
            }
        void OnSetDistance(float distance)
        {
            SerializedObject   serializedObject = new SerializedObject(spline);
            SerializedProperty groups           = serializedObject.FindProperty("triggerGroups");
            SerializedProperty groupProperty    = groups.GetArrayElementAtIndex(setDistanceGroup);

            SerializedProperty triggersProperty = groupProperty.FindPropertyRelative("triggers");
            SerializedProperty triggerProperty  = triggersProperty.GetArrayElementAtIndex(setDistanceTrigger);

            SerializedProperty position = triggerProperty.FindPropertyRelative("position");

            double travel = spline.Travel(0.0, distance, Spline.Direction.Forward);

            position.floatValue = (float)travel;
            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 3
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();
    }