コード例 #1
0
 /* Unload the currently loaded level */
 public void Unload()
 {
     metadata.SetLoadState(false);
     metadata = new LevelMetadata();
     theGrid.ClearGrid();
     LevelUnloadCompleted?.Invoke();
 }
コード例 #2
0
ファイル: Switch.cs プロジェクト: RachelZ0919/garden-game
 public void SealGrid()
 {
     affectingGrid.ClearGrid();
     affectingGrid.type = GridType.NOTSPRAYABLE;
     //affectingCube.DisableLawnAtGrid(affectingGrid);
     meshRenderer.enabled = true;
 }
コード例 #3
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";
        //}
    }
コード例 #4
0
    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";
            }
        }
    }