Exemple #1
0
    public void FillAtPosition(Vector2 uv, WaterColor waterColor)
    {
        Vector2 startPoint = new Vector2(Mathf.Floor(uv.x * width), Mathf.Floor(uv.y * height)) * gridSize;

        for (float i = 0; i < gridSize; i++)
        {
            for (float j = 0; j < gridSize; j++)
            {
                float px    = i + startPoint.x;
                float py    = j + startPoint.y;
                Color color = new Color(1, 0, 0, 1);
                if (waterColor == WaterColor.BLUE)
                {
                    color.g = 1;
                }
                else
                {
                    color.b = 1;
                }
                mask.SetPixel((int)px, (int)py, color);
            }
        }
        mask.Apply();
        GetComponent <MeshRenderer>().material.SetTexture("_SpawnMask", mask);
    }
Exemple #2
0
    public void FillAtPosition(Vector3 pos, WaterColor color)
    {
        LevelGrid grid = GetGridAtPosition(pos);

        if (grid.type == GridType.SOIL)
        {
            Vector2 uv   = GetUVAtPosition(grid, pos);
            Lawn    lawn = GetLawnAtPosition(grid);
            if (lawn != null)
            {
                lawn.FillAtPosition(uv, color);
            }
        }
    }
Exemple #3
0
    public void DrawAtPosition(Vector2 uv, WaterColor waterColor)
    {
        Color blackColor = new Color(0, 0, 0, 0);

        uv.x = uv.x * mask.width - 1;
        uv.y = uv.y * mask.height - 1;

        for (float i = 0; i < brushTexture.width; i++)
        {
            for (float j = 0; j < brushTexture.height; j++)
            {
                float px = i + uv.x - brushTexture.width / 2;
                float py = j + uv.y - brushTexture.height / 2;
                if (px < 0 || px >= mask.width || py < 0 || py >= mask.height)
                {
                    continue;
                }
                Vector4 brushColor = brushTexture.GetPixel((int)i, (int)j) * Time.deltaTime * 7;

                if (waterColor == WaterColor.BLUE)
                {
                    brushColor.z *= -1;
                }
                else
                {
                    brushColor.y *= -1;
                }

                Color color = mask.GetPixel((int)px, (int)py);
                color.r += brushColor.x;
                color.g += brushColor.y;
                color.b += brushColor.z;
                color.a += brushColor.w;

                color.r = Mathf.Clamp(color.r, 0, 1);
                color.g = Mathf.Clamp(color.g, 0, 1);
                color.b = Mathf.Clamp(color.b, 0, 1);

                if (color.a > 0)
                {
                    color.a = 1;
                }

                mask.SetPixel((int)px, (int)py, color);
            }
        }
        mask.Apply();
        GetComponent <MeshRenderer>().material.SetTexture("_SpawnMask", mask);
    }
Exemple #4
0
    public void DrawGridAtPosition(Vector2 uv, WaterColor waterColor, int state, bool right = false, bool left = false, bool forward = false, bool back = false)
    {
        Vector2 startPoint = new Vector2(Mathf.Floor(uv.x * width), Mathf.Floor(uv.y * height)) * gridSize;

        for (float i = 0; i < gridSize; i++)
        {
            for (float j = 0; j < gridSize; j++)
            {
                float px    = i + startPoint.x;
                float py    = j + startPoint.y;
                Color color = new Color(1, 1, 1, 1);
                if (waterColor == WaterColor.BLUE)
                {
                    color.b = 0;
                }
                else
                {
                    color.g = 0;
                }

                if (state <= 1)
                {
                    color.r = 0.3f;
                }
                else if (state == 2)
                {
                    color.r = 0.6f;
                }
                else
                {
                    color.r = 1f;
                }

                //if (color.a > 0)
                //{
                //    color.a = 1;
                //}
                groundMask.SetPixel((int)px, (int)py, color);
            }
        }
        groundMask.Apply();
        GetComponent <MeshRenderer>().material.SetTexture("_GroundMask", groundMask);
    }
Exemple #5
0
 // Update is called once per frame
 void Update()
 {
     waterColor = firstPerosonShooting.getWaterColor();
     if (waterColor == WaterColor.BLUE)
     {
         redUI.SetActive(false);
         blueUI.SetActive(true);
     }
     else if (waterColor == WaterColor.RED)
     {
         blueUI.SetActive(false);
         redUI.SetActive(true);
     }
     else
     {
         blueUI.SetActive(false);
         redUI.SetActive(false);
     }
 }
Exemple #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            if (Source != null)
            {
                float tileSize = Width / 10f;

                var water = new SolidBrush(Enabled ? WaterColor : WaterColor.HalveHue());
                var hit   = new SolidBrush(Enabled ? HitColor : HitColor.HalveHue());
                var miss  = new SolidBrush(Enabled ? MissColor : MissColor.HalveHue());
                var ship  = new SolidBrush(Enabled ? ShipColor : ShipColor.HalveHue());

                for (int x = 0; x < 10; x++)
                {
                    for (int y = 0; y < 10; y++)
                    {
                        switch (Source[x, y])
                        {
                        case PrimaryTile.Ship:
                            g.FillRectangle(ship, tileSize * x, tileSize * y, tileSize, tileSize);
                            break;

                        case PrimaryTile.Miss:
                            g.FillRectangle(miss, tileSize * x, tileSize * y, tileSize, tileSize);
                            break;

                        case PrimaryTile.Hit:
                            g.FillRectangle(hit, tileSize * x, tileSize * y, tileSize, tileSize);
                            break;

                        case PrimaryTile.Water:
                            g.FillRectangle(water, tileSize * x, tileSize * y, tileSize, tileSize);
                            break;
                        }
                    }
                }
            }
            base.OnPaint(e);
        }
Exemple #7
0
        private static bool ApplyColor(WaterColor color)
        {
            // Must be in the right location.
            var location = Game1.player.currentLocation;

            if (location.Name != color.Location)
            {
                return(false);
            }

            // Conditions must hold.
            if (!color.Conditions.check())
            {
                return(false);
            }

            // Set the color.
            Monitor.Log($"Setting water color for location '{location.Name}' to {color.Color}.",
                        LogLevel.Trace);
            location.waterColor.Value = color.Color;
            return(true);
        }
Exemple #8
0
    //给方块染色
    public void SprayWater(WaterColor waterColor)
    {
        //不是可染色的地面或已染色
        if (type != GridType.SOIL || (state > 0 && groundColor == waterColor))
        {
            return;
        }

        GameManager.VisualUpdate();
        colorOn = false;

        //更新原连通区域
        ClearGrid();

        //更新地块颜色
        groundColor = waterColor;
        state       = 1;
        int[] change_state = new int[GRASSTYPE];
        //判断现连通区域
        int       count = 0;
        bool      is_start = false, is_active = false;
        LevelGrid tmp;

        for (int i = 1; i <= 4; i++)
        {
            tmp = GetNearGrid((NearGridDirection)i);
            if (tmp == null)
            {
                continue;
            }
            if (tmp.state > 0 && (tmp.groundColor == groundColor || tmp.groundColor == WaterColor.DEFAULT))
            {
                count++;
                if (tmp.state == 1)
                {
                    continue;
                }
                for (int g = 0; g < GRASSTYPE; g++)
                {
                    if (tmp.grassStates[g] == 1)
                    {
                        change_state[g] = 1;
                    }
                }
                if (tmp.state == 2)
                {
                    is_start = true;
                }
                else if (tmp.state == 3)
                {
                    is_active = true;
                }
            }
        }

        if (count <= 0) //周围无同色地块
        {
            state = 1;
            return;
        }
        if (is_start == true)
        {
            if (count == 1) //只有一个与起点联通的同色地块
            {
                state = 2;
                change_state.CopyTo(grassStates, 0);
            }
            else
            {
                GameManager.ResetScanGrid();
                ScanGrids();
            }
        }
        else
        {   //四周地块的状态只有1或3
            if (is_active == true)
            {
                ChangeState(3, change_state);
            }
            else
            {
                state = 1;
            }
        }
    }
Exemple #9
0
    // Update is called once per frame
    void Update()
    {
        //fs = GameObject.FindGameObjectsWithTag("FrontSight");
        //fs[0].SetActive(true);
        //fs[1].SetActive(false);
        //输入判断
        switch (mouseButtonDown)
        {
        case 0:
        {
            if (Input.GetMouseButtonDown(0))
            {
                mouseButtonDown = 1;
            }

            if (Input.GetMouseButtonDown(1))
            {
                if (mouseButtonDown == 0)
                {
                    mouseButtonDown = 2;
                }
                else
                {
                    mouseButtonDown = 0;
                }
            }

            if (mouseButtonDown == 0)
            {
                if (Input.GetAxis("Mouse ScrollWheel") < 0)         //鼠标后滚
                {
                    //Done:Change Water color
                    //如果此时已经是最后一个颜色,那么就从第一个开始重新后滚(形成循环)
                    if (waterColor == WaterColor.BLUE)
                    {
                        waterColor = WaterColor.RED;
                    }
                    else
                    {
                        waterColor = waterColor + 1;
                    }
                    //Debug.Log("Hougun--");
                    //Debug.Log((int)waterColor);
                }
                else if (Input.GetAxis("Mouse ScrollWheel") > 0)         //鼠标前滚
                {
                    //Done:Change Water color
                    if (waterColor == WaterColor.RED)
                    {
                        waterColor = WaterColor.BLUE;
                    }
                    else
                    {
                        waterColor = waterColor - 1;
                    }
                    //Debug.Log("Qiangun--");
                    //Debug.Log((int)waterColor);
                }

                //waterParticle = particles[(int)waterColor - 1];
            }
            break;
        }

        case 1:
        {
            if (Input.GetMouseButtonUp(0))
            {
                mouseButtonDown = 0;
                //waterParticle.Stop();
                //TODO:修改UI
                fs_big.SetActive(true);
                fs_small.SetActive(false);
            }
            else
            {
                if (selectingGrid != null)
                {
                    selectingGrid.SprayWater(waterColor);
                    selectingCube.SprayWaterAtPosition(targetPoint, waterColor);
                }
                //WaterAnimation();

                //TODO:修改UI
                fs_big.SetActive(false);
                fs_small.SetActive(true);
            }
            break;
        }

        case 2:
        {
            if (Input.GetMouseButtonUp(1))
            {
                mouseButtonDown = 0;
            }
            else
            {
                if (selectingGrid != null)
                {
                    selectingGrid.ClearGrid();
                }
            }
            break;
        }
        }

        //Raycast
        int        layerMask = 1 << 9 | 1 << 10;
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, waterGunRange, layerMask))
        {
            targetPoint   = hit.point;
            selectingCube = hit.collider.GetComponent <LevelCube>();
            if (selectingCube != null)
            {
                selectingGrid = selectingCube.GetGridAtPosition(hit.point);
            }
            else
            {
                selectingGrid = null;
            }
            //selectingGrid = hit.collider.GetComponent<GridSplitter>().GetGridAtPosition(hit.point);
            //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
        }
        else
        {
            targetPoint   = transform.position + transform.TransformDirection(Vector3.forward) * waterGunRange; //这里可能有问题
            selectingGrid = null;
            //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
        }

        //高亮
        HighlightGrid();

        //if (selectingGrid != null)
        //{
        //    debugText.text = $"Position:{selectingGrid.position}   State:{selectingGrid.state}   Luminance:{selectingGrid.luminance}   Type:{selectingGrid.type}";
        //    for(int i = 0;i < selectingGrid.grassStates.Length; i++)
        //    {
        //        debugText.text += $"\ngrassState[{i}] = {selectingGrid.grassStates[i]}";
        //    }
        //    //LevelGrid grid = selectingGrid.GetNearGrid(NearGridDirection.LEFT);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nLEFT:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nLEFT:NULL";
        //    //}
        //    //grid = selectingGrid.GetNearGrid(NearGridDirection.RIGHT);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nRIGHT:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nRIGHT:NULL";
        //    //}
        //    //grid = selectingGrid.GetNearGrid(NearGridDirection.FORWARD);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nFORWARD:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nFORWARD:NULL";
        //    //}
        //    //grid = selectingGrid.GetNearGrid(NearGridDirection.BACK);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nBACK:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nBACK:NULL";
        //    //}

        //}
        //else
        //{
        //    debugText.text = "NULL";
        //}
    }
    void Update()
    {
        //鼠标输入判断
        switch (mouseButtonDown)
        {
        case 0:    //没有按下任何键
        {
            if (Input.GetMouseButtonDown(0))
            {
                mouseButtonDown = 1;
            }

            if (Input.GetMouseButtonDown(1))
            {
                if (mouseButtonDown == 0)
                {
                    mouseButtonDown = 2;
                }
                else
                {
                    mouseButtonDown = 0;
                }
            }

            if (mouseButtonDown == 0)
            {
                if (hasGun)
                {
                    if (Input.GetAxis("Mouse ScrollWheel") < 0)         //鼠标后滚
                    {
                        //如果此时已经是最后一个颜色,那么就从第一个开始重新后滚(形成循环)
                        if (currentColor == enabledWaterColors.Count - 1)
                        {
                            currentColor = 0;
                        }
                        else
                        {
                            currentColor += 1;
                        }

                        waterColor = enabledWaterColors[currentColor];
                    }
                    else if (Input.GetAxis("Mouse ScrollWheel") > 0)         //鼠标前滚
                    {
                        //Done:Change Water color
                        if (currentColor == 0)
                        {
                            currentColor = enabledWaterColors.Count - 1;
                        }
                        else
                        {
                            currentColor -= 1;
                        }

                        waterColor = enabledWaterColors[currentColor];
                    }
                }        //有枪的时候切枪
            }
            break;
        }

        case 1:    //按下左键
        {
            if (Input.GetMouseButtonUp(0))
            {
                mouseButtonDown = 0;
                if (hasGun)
                {
                    fs_big.SetActive(true);
                    fs_small.SetActive(false);
                }
            }
            else
            {
                if (hasGun)
                {
                    if (selectingGrid != null)
                    {
                        selectingGrid.SprayWater(waterColor);
                        //selectingCube.SprayAtPosition(targetPoint, waterColor);
                    }
                    fs_big.SetActive(false);
                    fs_small.SetActive(true);
                }
                else
                {
                }
            }
            break;
        }

        case 2:    //按下右键
        {
            if (Input.GetMouseButtonUp(1))
            {
                mouseButtonDown = 0;
            }
            else
            {
                if (hasGun && selectingGrid != null)
                {
                    selectingGrid.ClearGrid();
                }
            }
            break;
        }
        }

        //E键输入判断
        if (trigger != null && Input.GetKeyDown(KeyCode.E))
        {
            trigger.Interact();
        }

        //如果有枪需要找选中格子
        if (hasGun)
        {
            RaycastGrid();
            HighlightGrid();
        }

        //找选中trigger
        RaycastTrigger();

        //Debug
        if (debugTextEnabled)
        {
            if (selectingGrid != null)
            {
                debugText.text = $"Position:{selectingGrid.position}   State:{selectingGrid.state}     Type:{selectingGrid.type}";
                LevelGrid grid = selectingGrid.GetNearGrid(Direction.LEFT);

                if (grid != null)
                {
                    debugText.text += $"\nLEFT:{grid.position} - {grid.groundColor}";
                }
                else
                {
                    debugText.text += "\nLEFT:NULL";
                }
                grid = selectingGrid.GetNearGrid(Direction.RIGHT);
                if (grid != null)
                {
                    debugText.text += $"\nRIGHT:{grid.position} - {grid.groundColor}";
                }
                else
                {
                    debugText.text += "\nRIGHT:NULL";
                }
                grid = selectingGrid.GetNearGrid(Direction.FORWARD);
                if (grid != null)
                {
                    debugText.text += $"\nFORWARD:{grid.position} - {grid.groundColor}";
                }
                else
                {
                    debugText.text += "\nFORWARD:NULL";
                }
                grid = selectingGrid.GetNearGrid(Direction.BACK);
                if (grid != null)
                {
                    debugText.text += $"\nBACK:{grid.position} - {grid.groundColor}";
                }
                else
                {
                    debugText.text += "\nBACK:NULL";
                }
            }
            else
            {
                debugText.text = "NULL";
            }
        }
    }
    }//打开或关闭枪

    public void AddGunColor(WaterColor color)
    {
        enabledWaterColors.Add(color);
        waterColor = enabledWaterColors[currentColor];
    }//增加枪可用颜色
Exemple #12
0
 public void AddColor(WaterColor color)
 {
     shootingComponent.AddColor(color);
 }
Exemple #13
0
        public void PaintChunk(VoxelChunk chunk)
        {
            Vector3 position = chunk.Position;

            if (position.Y + TerrainEnvironment.CHUNK_HALF_SIZE < MinHeight)
            {
                return;
            }

            int bedrockRow = -1;

            if (position.Y < MinHeight + TerrainEnvironment.CHUNK_HALF_SIZE)
            {
                bedrockRow = (int)(MinHeight - (position.Y - TerrainEnvironment.CHUNK_HALF_SIZE) + 1) * ONE_Y_ROW - 1;
            }

            position.X -= TerrainEnvironment.CHUNK_HALF_SIZE;
            position.Y -= TerrainEnvironment.CHUNK_HALF_SIZE;
            position.Z -= TerrainEnvironment.CHUNK_HALF_SIZE;
            Vector3 pos        = new Vector3();
            int     waterLevel = WaterLevel > 0 ? WaterLevel : -1;

            Voxel[] voxels = chunk.Voxels;
            mGeneration++;
            TerrainEnvironment.Instance.GetHeightMapInfo(position.X, position.Z, mHeightChunkData);
            int shiftAmount = (int)MathF.Log(TerrainEnvironment.CHUNK_SIZE, 2);

            for (int arrayIndex = 0; arrayIndex < TerrainEnvironment.CHUNK_SIZE * TerrainEnvironment.CHUNK_SIZE; arrayIndex++)
            {
                float groundLevel  = mHeightChunkData[arrayIndex].GroundLevel;
                float surfaceLevel = waterLevel > groundLevel ? waterLevel : groundLevel;
                if (surfaceLevel < pos.Y)
                {
                    continue;
                }

                BiomeSettings biome = mHeightChunkData[arrayIndex].Biome;
                if (biome == null)
                {
                    biome = TerrainEnvironment.Instance.WorldTerrainData.DefaultBiome;
                    if (biome == null)
                    {
                        continue;
                    }
                }

                int y = (int)(surfaceLevel - position.Y);
                if (y >= TerrainEnvironment.CHUNK_SIZE)
                {
                    y = TerrainEnvironment.CHUNK_SIZE - 1;
                }

                pos.Y = position.Y + y;
                pos.X = position.X + (arrayIndex & (TerrainEnvironment.CHUNK_SIZE - 1));
                pos.Z = position.Z + (arrayIndex >> shiftAmount);

                int voxelIndex = y * ONE_Y_ROW + arrayIndex;
                if (voxelIndex < 0)
                {
                    continue;
                }
                if (pos.Y > groundLevel)
                {
                    while (pos.Y > groundLevel && voxelIndex >= 0)
                    {
                        voxels[voxelIndex].Color = WaterColor.ColorToUInt();
                        voxelIndex -= ONE_Y_ROW;
                        pos.Y--;
                    }
                }
                else if (pos.Y == groundLevel)
                {
                    voxels[voxelIndex].Color = 0;

                    if (voxels[voxelIndex].Color == 0)
                    {
                        if (pos.Y == waterLevel)
                        {
                            voxels[voxelIndex].Color = ShoreColor.ColorToUInt();
                        }
                        else
                        {
                            voxels[voxelIndex].Color = biome.VoxelTop.ColorToUInt();
                            if (pos.Y > waterLevel)
                            {
                                float rdn = WorldRandom.GetValue(pos);
                                if (biome.TreeDensity > 0 && rdn < biome.TreeDensity && biome.Trees.Length > 0)
                                {
                                    TerrainEnvironment.Instance.RequestTreeCreation(chunk, pos, TerrainEnvironment.Instance.GetTree(biome.Trees, rdn / biome.TreeDensity));
                                }
                                else if (biome.VegetationDensity > 0 && rdn < biome.VegetationDensity && biome.Vegetation.Length > 0)
                                {
                                    if (voxelIndex >= (TerrainEnvironment.CHUNK_SIZE - 1) * ONE_Y_ROW)
                                    {
                                        TerrainEnvironment.Instance.RequestVegetationCreation(chunk.Top, voxelIndex - ONE_Y_ROW * (TerrainEnvironment.CHUNK_SIZE - 1), TerrainEnvironment.Instance.GetVegetation(biome, rdn / biome.VegetationDensity));
                                    }
                                    else
                                    {
                                        voxels[voxelIndex + ONE_Y_ROW].Color = TerrainEnvironment.Instance.GetVegetation(biome, rdn / biome.VegetationDensity).ColorToUInt();
                                    }
                                }
                            }
                        }

                        voxelIndex -= ONE_Y_ROW;
                        pos.Y--;
                    }
                }

                biome.BiomeGeneration = mGeneration;

                while (voxelIndex >= 0 && voxels[voxelIndex].Color == 0 && pos.Y <= waterLevel)
                {
                    voxels[voxelIndex].Color = WaterColor.ColorToUInt();
                    voxelIndex -= ONE_Y_ROW;
                    pos.Y--;
                }

                for (; voxelIndex > bedrockRow; voxelIndex -= ONE_Y_ROW, pos.Y--)
                {
                    if (voxels[voxelIndex].Color == 0)
                    {
                        voxels[voxelIndex].Color = biome.VoxelDirt.ColorToUInt();
                    }
                    else if (voxels[voxelIndex].Color == 0 && pos.Y <= waterLevel)
                    {                     // hole under water level -> fill with water
                        voxels[voxelIndex].Color = WaterColor.ColorToUInt();
                    }
                }
                if (bedrockRow >= 0 && voxelIndex >= 0)
                {
                    voxels[voxelIndex].Color = BedrockColor.ColorToUInt();
                }
            }
        }