public void CreateSegmentsForPath(IEnumerable <Point> path) { _segments.Clear(); foreach (Point[] segments in path.GetCorners().ScanWindow(2)) { ConveyorSegment s = new ConveyorSegment(); s._start = segments[0]; s._end = segments[1]; s._linearDirection = s._start.DirectionTo(s._end); _segments.Add(s); } //Trim starts for (int i = 0; i < _segments.Count; i++) { ConveyorSegment s = _segments[i]; if (_segments.First() != s) { s._start += s._linearDirection; } } //Set curve directions foreach (ConveyorSegment[] segments in _segments.ScanWindow(2)) { segments[0]._endCurveDirection = segments[0]._end.DirectionTo(segments[1]._start); segments[0]._startCurveDirection = segments[0]._linearDirection; segments[1]._startCurveDirection = segments[1]._linearDirection; } ConveyorSegment firstSegment = _segments.First(); firstSegment._startCurveDirection = _output.GetWorldPosition().DirectionTo(firstSegment._start); ConveyorSegment lastSegment = _segments.Last(); lastSegment._endCurveDirection = lastSegment._end.DirectionTo(_input.GetWorldPosition()); if ((lastSegment._end - lastSegment._start).ManhattanLength == 0) { lastSegment._startCurveDirection = lastSegment._linearDirection; lastSegment._linearDirection = lastSegment._endCurveDirection; } //Set start 'phase' float length = 0; foreach (ConveyorSegment s in _segments) { s._startLength = length; length += s.Length; } _length = length; }
private void OnEnable() { conveyorSegment = (ConveyorSegment)target; conveyorBelt = serializedObject.FindProperty("conveyorBelt"); activated = serializedObject.FindProperty("m_activated"); physicMode = serializedObject.FindProperty("physicMode"); forceMultiplier = serializedObject.FindProperty("m_forceMultiplier"); maxSpeed = serializedObject.FindProperty("m_maxSpeed"); animationSpeedScaling = serializedObject.FindProperty("animationSpeedScaling"); alignment = serializedObject.FindProperty("alignment"); isHorizontal = serializedObject.FindProperty("m_isHorizontal"); flipDirection = serializedObject.FindProperty("m_flipDirection"); conveyorTheme = serializedObject.FindProperty("conveyorTheme"); }
public void GetSave(out Save save) { if (this.save.outputs.Any()) { Directions[] directions = EnumUtil <Directions> .values; int lenDirections = directions.Length; ConveyorSegment.Save[] saveOutputQueues = new ConveyorSegment.Save[lenDirections]; this.save.outputQueues = saveOutputQueues; for (int i = 0; i < lenDirections; ++i) { ConveyorSegment conveyorSegment = conveyorSegments[i]; if (conveyorSegment.valid) { conveyorSegment.GetSave(out saveOutputQueues[i]); } } } else { save.outputQueues = Array.Empty <ConveyorSegment.Save>(); } save = this.save; }