Ejemplo n.º 1
0
    public override List <Vector3> GetBackbonePoints(RailSection section)
    {
        List <Vector3> p = new List <Vector3>();

        p.Add(transform.position + transform.TransformVector(Vector3.forward) * 9);
        p.Add(transform.position + transform.TransformVector(Vector3.back) * 9);

        return(p);
    }
Ejemplo n.º 2
0
    public override List <Vector3> GetBackbonePoints(RailSection section)
    {
        List <Vector3> p = new List <Vector3>();

        Vector3 center = transform.position + transform.TransformVector(Vector3.left) * R;
        Vector3 dir    = transform.position - center;

        bool returnSwitched = false;

        if (section.gameObject.GetInstanceID() == this.gameObject.GetInstanceID())
        {
            returnSwitched = switchedToSide;
        }
        if (section.gameObject.GetInstanceID() == railSectionThird.gameObject.GetInstanceID())
        {
            returnSwitched = true;
            SetSwitched(true);
        }
        if (section.gameObject.GetInstanceID() == railSectionPrev.gameObject.GetInstanceID())
        {
            returnSwitched = switchedToSide;
        }
        if (section.gameObject.GetInstanceID() == railSectionNext.gameObject.GetInstanceID())
        {
            returnSwitched = false;
            SetSwitched(false);
        }


        if (returnSwitched)
        {
            dir = Quaternion.Euler(0, -22.5f, 0) * dir;
            p.Add(center + dir);

            for (int a = 0; a < 8; a++)
            {
                dir = Quaternion.Euler(0, 45f / 8f, 0) * dir;
                p.Add(center + dir);
            }
        }
        else
        {
            dir = Quaternion.Euler(0, -22.5f, 0) * dir;
            Vector3 point = center + dir;

            dir = Quaternion.Euler(0, 90f, 0) * dir;
            dir.Normalize();


            p.Add(point + dir * 2);
            p.Add(point + dir * 18);
        }

        return(p);
    }
Ejemplo n.º 3
0
    private RailSection GetRailSectionUnder(Transform transform)
    {
        RailSection result = null;

        float d = float.MaxValue;

        foreach (var rail in railroad.GetComponentsInChildren <RailSection>())
        {
            float _d = (rail.transform.position - transform.position).sqrMagnitude;
            if (_d < d)
            {
                d      = _d;
                result = rail;
            }
        }

        return(result);
    }
Ejemplo n.º 4
0
    public override List <Vector3> GetBackbonePoints(RailSection section)
    {
        List <Vector3> p = new List <Vector3>();

        Vector3 center = transform.position + transform.TransformVector(Vector3.left) * R;
        Vector3 dir    = transform.position - center;

        dir = Quaternion.Euler(0, 22.5f, 0) * dir;
        p.Add(center + dir);

        for (int a = 0; a < 8; a++)
        {
            dir = Quaternion.Euler(0, -45f / 8f, 0) * dir;
            p.Add(center + dir);
        }


        return(p);
    }
Ejemplo n.º 5
0
    public void Move(float distance)
    {
        if (distance == 0)
        {
            return;
        }

        RailSection rails = GetRailSectionUnder(transform);

        List <Vector3> backbone = rails.GetBackbonePoints(rails);

        foreach (var section in rails.GetAdjacentSections())
        {
            backbone.AddRange(section.GetBackbonePoints(rails));
        }

        Vector3 fwd = transform.TransformVector(Vector3.forward * distance);

        backbone.Sort(delegate(Vector3 v1, Vector3 v2)
        {
            return(Vector3.Dot(v1, fwd).CompareTo(Vector3.Dot(v2, fwd)));
        });

        if (GetComponent <LineRenderer>() != null)
        {
            GetComponent <LineRenderer>().SetVertexCount(backbone.Count);
            GetComponent <LineRenderer>().SetPositions(backbone.ToArray());
        }

        Vector3    bogieFwdMoved, bogieBwdMoved;
        Quaternion bogieFwdRotated, bogieBwdRotated;

        MoveBogie(backbone, bogieFwd.transform, distance, out bogieFwdMoved, out bogieFwdRotated);
        MoveBogie(backbone, bogieBwd.transform, distance, out bogieBwdMoved, out bogieBwdRotated);

        transform.position = (bogieFwdMoved + bogieBwdMoved) / 2 + new Vector3(0, -0.072f, 0);
        transform.rotation = Quaternion.LookRotation(bogieFwdMoved - bogieBwdMoved, Vector3.up);

        bogieBwd.transform.rotation = Quaternion.Slerp(bogieBwd.transform.rotation, bogieBwdRotated, Time.deltaTime);
        bogieFwd.transform.rotation = Quaternion.Slerp(bogieFwd.transform.rotation, bogieFwdRotated, Time.deltaTime);
    }
Ejemplo n.º 6
0
 public virtual List <Vector3> GetBackbonePoints(RailSection section)
 {
     return(new List <Vector3>());
 }
Ejemplo n.º 7
0
 public RailSection previousSection(RailSection currentSection)
 {
     foreach(var road in GetComponentsInChildren<RailSection>())
         if(road.end == currentSection.start)
             return road;
     //Debug.LogError ("'TrackManager::previousSection' failed to find section before " + currentSection);
     return null;
 }
Ejemplo n.º 8
0
 public RailSection nextSection(RailSection currentSection)
 {
     foreach(var road in GetComponentsInChildren<RailSection>())
         if(road.start == currentSection.end)
             return road;
     //Debug.LogError ("'TrackManager::nextSection' failed to find section after " + currentSection);
     return null;
 }
Ejemplo n.º 9
0
 public IEnumerable<RailSection> iterateForwards(RailSection start = null)
 {
     RailSection currentSection = (start ?? firstSection);
     while(currentSection != null)
     {
         yield return currentSection;
         currentSection = nextSection(currentSection);
     }
     yield break;
 }
Ejemplo n.º 10
0
 public IEnumerable<RailSection> iterateBackwards(RailSection start = null)
 {
     RailSection currentSection = (start ?? lastSection);
     while(currentSection != null)
     {
         yield return currentSection;
         currentSection = previousSection(currentSection);
     }
     yield break;
 }