コード例 #1
0
    public override void OnTrackActivate(TrackSectionComponent track, ActivateInfo info)
    {
        bool selectStart;

        if (info.button == ActivateButton.LeftClick && HighlightClosestEnd(track.trackSection, true, info.hit.point, out selectStart))
        {
            if (state == State.Idle)
            {
                fromSection = track.trackSection;
                fromEnd     = !selectStart;
                ToState(State.SelectedStart);
            }
            else if (state == State.SelectedStart)
            {
                // Try to place the track
                var toSection = track.trackSection;
                var toEnd     = !selectStart;
                if (!TryPlaceTrack(fromSection, fromEnd, toSection, toEnd))
                {
                    Debug.Log("Unable to place flex section!");
                }

                ToState(State.Idle);
            }
        }
        else if (info.button == ActivateButton.RightClick)
        {
            ToState(State.Idle);
        }
    }
コード例 #2
0
 public override void OnTrackActivate(TrackSectionComponent track, ActivateInfo info)
 {
     if (info.button == ActivateButton.LeftClick && selectedWagon != null)
     {
         // Place the selected wagon on the track
         float distance;
         GetSnappedTrackPosition(track.trackSection, info.hit.point, out distance);
         PlaceSelected(track.trackSection, distance);
     }
 }
コード例 #3
0
 public override void OnTrackHover(TrackSectionComponent track, ActivateInfo info)
 {
     if (HighlightClosestEnd(track.trackSection, true, info.hit.point, out shouldInvertOnReposition))
     {
         lastHighlightedSection = track.trackSection;
     }
     else
     {
         lastHighlightedSection = null;
     }
 }
コード例 #4
0
    public override void OnTrackHover(TrackSectionComponent track, ActivateInfo info)
    {
        if (selectedWagon != null)
        {
            float distance;
            // TODO: Draw ghost instead
            var matrix = Matrix4x4.TRS(GetSnappedTrackPosition(track.trackSection, info.hit.point, out distance),
                                       track.trackSection.GetRotationOnTrack(distance),
                                       Vector3.one);

            Highlighter.DrawHighlighter(matrix);

            Graphics.DrawMesh(selectedWagon.GetComponent <MeshFilter>().sharedMesh, matrix, selectedWagon.GetComponent <MeshRenderer>().sharedMaterial, gameObject.layer);
        }
    }
コード例 #5
0
    private void Serialize(TrackSectionComponent component)
    {
        Serialize(component.trackSection);
        ushort id = 0;

        if (component.InGroup)
        {
            if (!trackGroupIds.ContainsKey(component.group))
            {
                trackGroupIds.Add(component.group, (ushort)(trackGroupIds.Count + 1));
            }
            id = trackGroupIds[component.group];
        }
        writer.Write(id);
    }
コード例 #6
0
 public override void OnTrackActivate(TrackSectionComponent track, ActivateInfo info)
 {
     if (lastHighlightedSection == track.trackSection && info.button == ActivateButton.LeftClick)
     {
         // Reposition on track section, or deselect
         trackLayer.Reposition(lastHighlightedSection != trackLayer.CurrentSection ? lastHighlightedSection : null, shouldInvertOnReposition);
     }
     else if (info.button == ActivateButton.RightClick)
     {
         // Delete track
         if (track.trackSection == trackLayer.CurrentSection)
         {
             trackLayer.CurrentSection = null;
         }
         RemoveTrackSection(track);
     }
 }
コード例 #7
0
    public static void RemoveTrackSection(TrackSectionComponent component)
    {
        List <TrackSectionComponent> toRemove = new List <TrackSectionComponent> {
            component
        };

        if (component.InGroup)
        {
            toRemove = component.group;
        }

        foreach (var track in toRemove)
        {
            // Unlink track sections
            if (track.trackSection.Next != null)
            {
                if (track.trackSection.Next.Previous == track.trackSection)
                {
                    track.trackSection.Next.Previous = null;
                }
                else if (track.trackSection.Next.Next == track.trackSection)
                {
                    track.trackSection.Next.Next = null;
                }
            }
            if (track.trackSection.Previous != null)
            {
                if (track.trackSection.Previous.Previous == track.trackSection)
                {
                    track.trackSection.Previous.Previous = null;
                }
                else if (track.trackSection.Previous.Next == track.trackSection)
                {
                    track.trackSection.Previous.Next = null;
                }
            }
            TrackDatabase.Instance.DeregisterTrack(track.trackSection);
            GameObject.Destroy(track.gameObject);
        }
    }
コード例 #8
0
 public virtual void OnTrackActivate(TrackSectionComponent track, ActivateInfo info)
 {
 }