Exemplo n.º 1
0
        public void AddSpecialFeature(HexCell cell, Vector3 position)
        {
            Transform instance = Instantiate(special[cell.SpecialIndex - 1]);

            instance.localPosition = HexMetrics.Perturb(position);
            HexHash hash = HexMetrics.SampleHashGrid(position);

            instance.localRotation = Quaternion.Euler(0f, 360f * hash.e, 0f);
            instance.SetParent(container, false);
        }
Exemplo n.º 2
0
        private void AddWallSegment(
            Vector3 pivot, HexCell pivotCell,
            Vector3 left, HexCell leftCell,
            Vector3 right, HexCell rightCell
            )
        {
            if (pivotCell.IsUnderwater)
            {
                return;
            }

            bool hasLeftWall = !leftCell.IsUnderwater &&
                               pivotCell.GetEdgeType(leftCell) != HexEdgeType.Cliff;
            bool hasRighWall = !rightCell.IsUnderwater &&
                               pivotCell.GetEdgeType(rightCell) != HexEdgeType.Cliff;

            if (hasLeftWall)
            {
                if (hasRighWall)
                {
                    bool hasTower = false;
                    if (leftCell.Elevation == rightCell.Elevation)
                    {
                        HexHash hash = HexMetrics.SampleHashGrid(
                            (pivot + left + right) * (1f / 3f)
                            );
                        hasTower = hash.e < HexMetrics.wallTowerThreshold;
                    }
                    AddWallSegment(pivot, left, pivot, right, hasTower);
                }
                else if (leftCell.Elevation < rightCell.Elevation)
                {
                    AddWallWedge(pivot, left, right);
                }
                else
                {
                    AddWallCap(pivot, left);
                }
            }
            else if (hasRighWall)
            {
                if (rightCell.Elevation < leftCell.Elevation)
                {
                    AddWallWedge(right, pivot, left);
                }
                else
                {
                    AddWallCap(right, pivot);
                }
            }
        }
Exemplo n.º 3
0
        public void AddFeature(HexCell cell, Vector3 position)
        {
            if (cell.IsSpecial)
            {
                return;
            }
            HexHash   hash   = HexMetrics.SampleHashGrid(position);
            Transform prefab = PickPrefab(urbanCollections, cell.UrbanLevel, hash.a, hash.d);

            Transform otherPrefab = PickPrefab(farmCollections, cell.FarmLevel, hash.b, hash.d);
            float     usedHash    = hash.a;

            if (prefab)
            {
                if (otherPrefab && hash.b < hash.a)
                {
                    prefab   = otherPrefab;
                    usedHash = hash.b;
                }
            }
            else if (otherPrefab)
            {
                prefab   = otherPrefab;
                usedHash = hash.b;
            }

            otherPrefab = PickPrefab(plantCollections, cell.PlantLevel, hash.c, hash.d);
            if (prefab)
            {
                if (otherPrefab && hash.c < usedHash)
                {
                    prefab = otherPrefab;
                }
            }
            else if (otherPrefab)
            {
                prefab = otherPrefab;
            }
            else
            {
                return;
            }

            Transform instance = Instantiate(prefab);

            position.y            += instance.localScale.y * 0.5f;
            instance.localPosition = HexMetrics.Perturb(position);
            instance.localRotation = Quaternion.Euler(0f, 360f * hash.e, 0f);
            instance.SetParent(container, false);
        }