public override void Place(TrackSegment segment, int[,] spots)
        {
            base.Place(segment, spots);

            PlacerSpot spot = new PlacerSpot();              //be gentle with the stack, allocate only once

            //iterate on each row
            for (int i = 0; i < TrackSegment.LENGTH; i++)
            {
                //get curent deviation
                int shift = stretch.Get();

                //mark and add assets along path's width
                for (int j = 0; j < thickness; j++)
                {
                    spot.x = column + shift + j;
                    spot.y = i;

                    Mark(spot);
                    AddAsset(spot);
                }

                //increment stretch and start a new one if needed
                if (!stretch.Advance())
                {
                    //save column for the next stretch
                    column += shift;
                    StartStretch();
                }
            }
        }
Exemple #2
0
        public override void Place(TrackSegment segment, int[,] spots)
        {
            base.Place(segment, spots);

            MapAreas();             //build list

            if (areas.Count == 0)   //nothing to do, exit
            {
                return;
            }

            //determine actual possible pathes count - not all may fit
            int count = (areas.Count < targetCount)? areas.Count : targetCount;

            //place patches towards the target count
            for (int i = 0; i < count && areas.Count > 0; i++)
            {
                //choose area
                PlacerArea area = areas[Random.Range(0, areas.Count)];
                //builds free spots list
                area.GetSpots(PlacerSpot.Type.Empty, free);

                //choose from free spots and place assets
                for (int j = 0; j < assetsPerPatch; j++)
                {
                    int        index = Random.Range(0, free.Count);
                    PlacerSpot spot  = free[index];

                    Mark(spot);
                    AddAsset(spot);

                    free.RemoveAt(index);
                }

                //prepare for next patch
                free.Clear();
                areas.RemoveAll(item => area.Overlaps(item) && (!allowIntertwined || allowIntertwined && item.GetSpotRatio(PlacerSpot.Type.Empty) < targetFillRatio));
            }

            //cleanup
            areas.Clear();
        }
Exemple #3
0
        /// <summary>
        /// Lays segment of track and ads assets to them.
        /// </summary>
        public void Build()
        {
            Clear();

                        #if UNITY_EDITOR
            if (!EditorApplication.isPlaying)
            {
                Undo.RecordObject(this, "Create World");
            }
                        #endif

            Init();
            Vector3 position = Vector3.zero;

            for (int i = 0; i < segmentsToAdd; i++)
            {
                TrackSegment segment = Instantiate(segmentAsset, position, Quaternion.identity, segmentsContainer);

                                #if UNITY_EDITOR
                if (!EditorApplication.isPlaying)
                {
                    Undo.RegisterCreatedObjectUndo(segment.gameObject, "Create Track");
                }
                                #endif

                segments.Add(segment);
                //prepare for next
                position = segment.EndMarkerPos;

                //populate
                for (int p = 0; p < placers.Length; p++)
                {
                    placers[p].Place(segment, spots);
                }

                ClearSpots();
            }

            UnInit();
        }
Exemple #4
0
 /// <summary>
 /// Called for each segment. Asset placement logic goes in here.
 /// </summary>
 /// <param name="segment">Current processed segment.</param>
 /// <param name="spots">Occupancy status of the segment.</param>
 public virtual void Place(TrackSegment segment, int[,] spots)
 {
     this.segment = segment;
     this.spots   = spots;
 }
Exemple #5
0
 /// <summary>
 /// Called after build process ended.
 /// All deallocations go in here.
 /// </summary>
 public virtual void UnInit()
 {
     segment = null;
     spots   = null;
 }