Пример #1
0
    override public void InitGrid()
    {
        var imageRectHeight    = new Rect(0, 0, heightMap.width, heightMap.height);
        var imageRectPolitical = new Rect(0, 0, politicalMap.width, politicalMap.height);
        var map          = new FlatHexMap(new Vector2(80, 69));
        var mapHeight    = new ImageMap <FlatHexPoint>(imageRectHeight, Grid, map);
        var mapPolitical = new ImageMap <FlatHexPoint>(imageRectPolitical, Grid, map);

        WaterHexes    = new List <FlatHexPoint>();
        MountainHexes = new List <FlatHexPoint>();
        LandHexes     = new List <FlatHexPoint>();

        foreach (var point in Grid)
        {
            int   x      = Mathf.FloorToInt(mapHeight[point].x);
            int   y      = Mathf.FloorToInt(mapHeight[point].y);
            float height = heightMap.GetPixel(x, y).r *HeightScale;

            if (height <= 0)
            {
                height = 0.01f;
            }

            var block = Grid[point];

            if (block == null)
            {
                Debug.LogWarning("block is null " + point);
            }
            else
            {
                if (height < HeightScale * 0.3f)
                {
                    UVCell thisHex = block.GetComponentInChildren <UVCell>();
                    thisHex.GetComponent <Renderer>().material = baseWater;
                    block.GetComponent <Renderer>().material   = baseWater;
                    block.transform.localScale = new Vector3(1, WaterHeight, 1);
                    //block.transform.position += new Vector3(0f, (BaseHeight + WaterHeight) / 4f, 0f);
                    WaterHexes.Add(point);
                }
                else if (height >= HeightScale * 0.3f && height < HeightScale * 0.7f)
                {
                    UVCell thisHex = block.GetComponentInChildren <UVCell>();
                    thisHex.GetComponent <Renderer>().material = baseGrass;
                    block.transform.localScale = new Vector3(1, BaseHeight, 1);
                    LandHexes.Add(point);
                }
                else
                {
                    UVCell thisHex = block.GetComponentInChildren <UVCell>();
                    thisHex.GetComponent <Renderer>().material = baseRocky;
                    block.transform.localScale = new Vector3(1, MountainHeight, 1);
                    MountainHexes.Add(point);
                }
            }
        }
    }
Пример #2
0
    override public void InitGrid()
    {
        var imageRect = new Rect(0, 0, heightMap.width, heightMap.height);
        var map       = new FlatHexMap(new Vector2(80, 69));
        var map2D     = new ImageMap <FlatHexPoint>(imageRect, Grid, map);

        foreach (var point in Grid)
        {
            int   x      = Mathf.FloorToInt(map2D[point].x);
            int   y      = Mathf.FloorToInt(map2D[point].y);
            float height = heightMap.GetPixel(x, y).r *HeightScale;

            if (height <= 0)
            {
                height = 0.01f;
            }


            var block = Grid[point];

            if (block == null)
            {
                Debug.LogWarning("block is null " + point);
            }
            else
            {
                //block.Color = ExampleUtils.Blend(height, ExampleUtils.DefaultColors[0], ExampleUtils.DefaultColors[1]);
                //block.transform.localScale = new Vector3(1, height, 1);


                if (height < HeightScale * 0.3f)
                {
                    UVCell thisHex = block.GetComponentInChildren <UVCell>();
                    thisHex.GetComponent <Renderer>().material = baseSandy;
                }
                if (height > HeightScale * 0.6f && height < HeightScale * 0.8f)
                {
                    UVCell thisHex = block.GetComponentInChildren <UVCell>();
                    thisHex.GetComponent <Renderer>().material = baseRockyGrass;
                }
                if (height >= HeightScale * 0.8f)
                {
                    UVCell thisHex = block.GetComponentInChildren <UVCell>();
                    thisHex.GetComponent <Renderer>().material = baseRocky;
                }
            }
        }
    }
Пример #3
0
        void DoSpawn(SpriteSpawnerTest.SpawnData spawner, Material mat)
        {
            ComponentType[] type = new ComponentType[]
            {
                typeof(Position2D),
                typeof(Rotation2D),
                typeof(Scale),
                typeof(SpriteSheetAnimation),
                typeof(SpriteSheetMaterial),
                typeof(SpriteSheetColor),
                typeof(UVCell)
            };

            var em        = EntityManager;
            var archetype = em.CreateArchetype(type);

            NativeArray <Entity> entities = new NativeArray <Entity>(spawner.spriteCount, Allocator.Temp);

            em.CreateEntity(archetype, entities);

            int cellCount = CachedUVData.GetCellCount(mat);

            Random rand = new Random((uint)UnityEngine.Random.Range(0, int.MaxValue));
            Rect   area = spawner.GetSpawnArea();
            SpriteSheetMaterial material = new SpriteSheetMaterial {
                material = mat
            };
            var maxFrames = CachedUVData.GetCellCount(mat);

            //Debug.Log("Spawning entities and setting components");
            for (int i = 0; i < entities.Length; i++)
            {
                Entity e = entities[i];


                Scale scale = new Scale {
                    Value = rand.NextFloat(spawner.minScale, spawner.maxScale)
                };
                float2 p = rand.NextFloat2(area.min, area.max);


                Position2D pos = spawner.origin.xy + p;
                Rotation2D rot = new Rotation2D {
                    angle = spawner.rotation
                };

                int numFrames             = rand.NextInt(3, maxFrames / 2);
                int minFrame              = rand.NextInt(0, maxFrames - numFrames);
                SpriteSheetAnimation anim = new SpriteSheetAnimation
                {
                    play       = true,
                    repetition = SpriteSheetAnimation.RepetitionType.Loop,
                    fps        = rand.NextFloat(spawner.minFPS_, spawner.maxFPS_),
                    frameMin   = minFrame,
                    frameMax   = minFrame + numFrames
                };
                SpriteSheetColor color = UnityEngine.Random.ColorHSV(.35f, .75f);
                UVCell           cell  = new UVCell {
                    value = rand.NextInt(0, maxFrames)
                };

                em.SetComponentData(e, scale);
                em.SetComponentData(e, pos);
                em.SetComponentData(e, anim);
                em.SetComponentData(e, color);
                em.SetComponentData(e, cell);
                em.SetComponentData(e, rot);
                em.SetSharedComponentData(e, material);
            }
        }