示例#1
0
 public void Reset(Spline2DRoadComponent path)
 {
     onDeath            = null;
     onPathFinished     = null;
     this.path          = path;
     distanceTraveled   = 0;
     transform.position = path.GetPointWorldSpace(0);
     health             = m_maxHealth;
 }
示例#2
0
    private void Awake()
    {
        m_collider = GetComponent <PolygonCollider2D>();
        m_spline   = GetComponent <Spline2DRoadComponent>();

        List <Tuple <Vector2, Vector2> > sidePoints = new List <Tuple <Vector2, Vector2> >();
        float t = 0;

        for (; t <= 1.0f; t += iterpolationAccuracy)
        {
            Vector2[] p = m_spline.InterpolateSides(t);
            sidePoints.Add(new Tuple <Vector2, Vector2>(p[0], p[1]));
        }
        if (t > 1.0f)
        {
            Vector2[] p = m_spline.InterpolateSides(1.0f);
            sidePoints.Add(new Tuple <Vector2, Vector2>(p[0], p[1]));
        }
        //var sidePoints = m_spline.GetAllSidePoints();

        int pathCount = sidePoints.Count - 1;

        m_collider.pathCount = pathCount;
        Vector2[] path = new Vector2[4];
        for (int i = 0; i < pathCount; i++)
        {
            path[0] = sidePoints[i].Item1;
            path[1] = sidePoints[i + 1].Item1;
            path[2] = sidePoints[i + 1].Item2;
            path[3] = sidePoints[i].Item2;

            m_collider.SetPath(i, path);
        }
        //Vector2[] path = new Vector2[sidePoints.Count * 2];
        //int index = 0;
        //foreach(Tuple<Vector2, Vector2> points in sidePoints)
        //{
        //    path[index] = points.Item1;
        //    path[index + 1] = points.Item2;
        //    index += 2;
        //}
        //m_collider.SetPath(0, path);
    }
示例#3
0
    private void OnSceneGUI()
    {
        spline = target as Spline2DRoadComponent;

        DrawPoints();
    }
示例#4
0
    public override void OnInspectorGUI()
    {
        spline = target as Spline2DRoadComponent;

        EditorGUILayout.Space();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Add Point"))
        {
            Undo.RecordObject(spline, "Add Point");
            AddNewPoint();
        }

        if (selectedIndex == -1)
        {
            GUI.enabled = false;
        }
        if (GUILayout.Button("Insert Point"))
        {
            Undo.RecordObject(spline, "Insert Point");
            InsertNewPoint();
        }
        if (GUILayout.Button("Remove Point"))
        {
            Undo.RecordObject(spline, "Remove Point");
            RemovePoint();
        }
        GUILayout.EndHorizontal();
        GUI.enabled = true;

        EditorGUILayout.Space();
        EditorGUI.indentLevel += 2;
        DrawSelectedPointInspector();
        EditorGUI.indentLevel -= 2;

        EditorGUILayout.Space();
        // DON'T use the default inspector, it will bypass setters and we need
        // those to be called to properly dirty the state
        EditorGUI.BeginChangeCheck();
        bool closed = EditorGUILayout.Toggle("Closed", spline.IsClosed);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Closed");
            spline.IsClosed = closed;
        }
        EditorGUI.BeginChangeCheck();
        bool xz = EditorGUILayout.Toggle("X/Z Mode", spline.displayXZ);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle XZ Mode");
            spline.displayXZ = xz;
        }
        EditorGUI.BeginChangeCheck();
        float curve = EditorGUILayout.FloatField("Curvature", spline.Curvature);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Set Curvature");
            spline.Curvature = curve;
        }
        EditorGUI.BeginChangeCheck();
        int lenSamples = EditorGUILayout.IntSlider("Length Sampling", spline.LengthSamplesPerSegment, 1, 20);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Set Length Sampling");
            spline.LengthSamplesPerSegment = lenSamples;
        }


        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        EditorGUI.BeginChangeCheck();
        bool showDistance = EditorGUILayout.Toggle("Show Distance", spline.showDistance);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Show Distance");
            spline.showDistance = showDistance;
        }
        EditorGUI.BeginChangeCheck();
        float dist = EditorGUILayout.FloatField("Interval", spline.distanceMarker);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Set Distance Interval");
            spline.distanceMarker = dist;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUI.BeginChangeCheck();
        bool showNormals = EditorGUILayout.Toggle("Show Normals", spline.showNormals);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Toggle Show Normals");
            spline.showNormals = showNormals;
        }

        EditorGUI.BeginChangeCheck();
        float nmlen = EditorGUILayout.FloatField("Length", spline.normalDisplayLength);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Set Normal Display Length");
            spline.normalDisplayLength = nmlen;
        }

        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        EditorGUI.BeginChangeCheck();
        float width = EditorGUILayout.FloatField("Road Width", spline.Width);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Set road width");
            spline.Width = width;
        }
        EditorGUILayout.EndHorizontal();
    }