Пример #1
0
        // This building method will firstly try to join N loop tiles and a left and right tile,
        // so that the total width is close but smaller than the actual size.
        // If the rest size is equal to or greater than 'minimumValidLoopTile', we will put another loop tile.
        protected override float BuildGraphics(TerrainData data, TerrainStyle style)
        {
            var ground_style = style.groundStyle;

            if (!ground_style.isValid)
            {
                Debug.LogError("GroundStyle is not valid!");
                return(0);
            }

            float loop_ratio = (data.region.width - ground_style.edgeSize) / ground_style.loopSize;
            int   loop_cnt   = (int)Mathf.Ceil(loop_ratio - ground_style.minimumValidLoopTile);

            float accumulate_size = 0;

            tiles_.Clear();

            tiles_.Add(CreateGroundTile(ground_style.leftTile, ground_style, accumulate_size));
            accumulate_size += ground_style.leftEdgeSize;
            for (int i = 0; i < loop_cnt; i++)
            {
                tiles_.Add(CreateGroundTile(ground_style.RandomSelectLoopTile(), ground_style, accumulate_size));
                accumulate_size += ground_style.loopSize;
            }
            tiles_.Add(CreateGroundTile(ground_style.rightTile, ground_style, accumulate_size));
            accumulate_size += ground_style.rightEdgeSize;

            return(accumulate_size);
        }
Пример #2
0
        public void BuildSelf(TerrainData data, TerrainStyle style, Transform parent_tranform)
        {
            if (is_dirty)
            {
                Cleanup();
            }
            is_dirty = true;

            transform.parent     = parent_tranform;
            transform.localScale = Vector3.one;
            this.data            = data;

            Init();
            float real_width = BuildGraphics(data, style);

            collider = BuildCollider(data, real_width);

            bound = new Rect(
                collider.bounds.center.x - collider.bounds.size.x * 0.5f,
                collider.bounds.center.y - collider.bounds.size.y * 0.5f,
                collider.bounds.size.x, collider.bounds.size.y);
        }
Пример #3
0
 /// <summary>
 /// The return value is the real size generated by this method.
 /// </summary>
 protected abstract float BuildGraphics(TerrainData data, TerrainStyle style);