Пример #1
0
        void Update()
        {
            Invert = Input.GetKey(KeyCode.LeftAlt);
            Smooth = Input.GetKey(KeyCode.LeftShift);

            if (CurrentPage != 0)
            {
                return;
            }

            if (PaintStarted && Input.GetMouseButtonUp(0))
            {
                ScmapEditor.Current.Teren.ApplyDelayedHeightmapModification();
                ScmapEditor.Current.Teren.Flush();
            }

            if (Edit.MauseOnGameplay || ChangingStrength || ChangingSize)
            {
                if (!ChangingSize && (Input.GetKey(KeyCode.M) || ChangingStrength))
                {
                    // Change Strength
                    if (Input.GetMouseButtonDown(0))
                    {
                        ChangingStrength   = true;
                        BeginMousePos      = Input.mousePosition;
                        StrengthBeginValue = BrushStrength.value;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        ChangingStrength = false;
                    }
                    if (ChangingStrength)
                    {
                        BrushStrength.SetValue((int)Mathf.Clamp(StrengthBeginValue - (BeginMousePos.x - Input.mousePosition.x), 0, 100));
                        //BrushStrengthSlider.value = Mathf.Clamp(StrengthBeginValue - (BeginMousePos.x - Input.mousePosition.x), 0, 100);
                        UpdateMenu(true);
                        //UpdateBrushPosition(true);
                    }
                }
                else if (Input.GetKey(KeyCode.B) || ChangingSize)
                {
                    // Change Size
                    if (Input.GetMouseButtonDown(0))
                    {
                        ChangingSize   = true;
                        BeginMousePos  = Input.mousePosition;
                        SizeBeginValue = BrushSize.value;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        ChangingSize = false;
                    }
                    if (ChangingSize)
                    {
                        BrushSize.SetValue(Mathf.Clamp(SizeBeginValue - (BeginMousePos.x - Input.mousePosition.x), 1, 256));
                        //BrushSizeSlider.value = Mathf.Clamp(SizeBeginValue - (BeginMousePos.x - Input.mousePosition.x), 1, 256);
                        UpdateMenu(true);
                        UpdateBrushPosition(true);
                    }
                }
                else
                {
                    if (!PaintStarted && Input.GetKey(KeyCode.LeftControl))
                    {
                        if (CameraControler.Current.DragStartedGameplay)
                        {
                            if (UpdateBrushPosition(false))
                            {
                            }
                        }

                        if (Input.GetMouseButton(0))
                        {
                            BrushTarget.SetValue(CameraControler.GetLastScmHeight());
                        }
                        else if (Input.GetMouseButton(1))
                        {
                            BrushMini.SetValue(CameraControler.GetLastScmHeight());
                        }
                        else if (Input.GetMouseButton(2))
                        {
                            BrushMax.SetValue(CameraControler.GetLastScmHeight());
                        }
                    }
                    else if (Edit.MauseOnGameplay && Input.GetMouseButtonDown(0))
                    {
                        if (UpdateBrushPosition(true))
                        {
                            ScmapEditor.Current.Teren.heightmapPixelError = 20;
                            GenerateControlTex.StopGenerateNormal();
                            ScmapEditor.Current.TerrainMaterial.SetFloat("_GeneratingNormal", 1);
                            PaintStarted = true;
                            SymmetryPaint();
                        }
                    }
                    else if (Input.GetMouseButton(0))
                    {
                        if (CameraControler.Current.DragStartedGameplay)
                        {
                            if (UpdateBrushPosition(false))
                            {
                            }
                            SymmetryPaint();
                        }
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        PaintStarted = false;
                        ScmapEditor.Current.Teren.heightmapPixelError = 4;
                        if (Painting)
                        {
                            Painting = false;
                            RegenerateMaps();
                        }
                    }
                    else
                    {
                        UpdateBrushPosition(true);
                    }
                }
            }

            if (TerainChanged && Input.GetMouseButtonUp(0))
            {
                MapLuaParser.Current.History.RegisterTerrainHeightmapChange(beginHeights);
                TerainChanged = false;
            }


            BrushGenerator.RegeneratePaintBrushIfNeeded();
        }
Пример #2
0
        void Update()
        {
            Invert = Input.GetKey(KeyCode.LeftAlt);
            Smooth = Input.GetKey(KeyCode.LeftShift);

            if (CurrentPage != 0)
            {
                return;
            }

            if (PaintStarted && Input.GetMouseButtonUp(0))
            {
                ScmapEditor.SyncHeightmap(true);
            }

            if (Edit.MauseOnGameplay || ChangingStrength || ChangingSize)
            {
                if (!ChangingSize && (KeyboardManager.BrushStrengthHold() || ChangingStrength))
                {
                    // Change Strength
                    if (Input.GetMouseButtonDown(0))
                    {
                        ChangingStrength   = true;
                        BeginMousePos      = Input.mousePosition;
                        StrengthBeginValue = BrushStrength.value;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        ChangingStrength = false;
                    }
                    if (ChangingStrength)
                    {
                        BrushStrength.SetValue((int)Mathf.Clamp(StrengthBeginValue - (BeginMousePos.x - Input.mousePosition.x), 0, 100));
                        //BrushStrengthSlider.value = Mathf.Clamp(StrengthBeginValue - (BeginMousePos.x - Input.mousePosition.x), 0, 100);
                        UpdateMenu(true);
                        //UpdateBrushPosition(true);
                    }
                }
                else if (KeyboardManager.BrushSizeHold() || ChangingSize)
                {
                    // Change Size
                    if (Input.GetMouseButtonDown(0))
                    {
                        ChangingSize   = true;
                        BeginMousePos  = Input.mousePosition;
                        SizeBeginValue = BrushSize.value;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        ChangingSize = false;
                    }
                    if (ChangingSize)
                    {
                        BrushSize.SetValue(Mathf.Clamp(SizeBeginValue - (BeginMousePos.x - Input.mousePosition.x), 1, 256));
                        //BrushSizeSlider.value = Mathf.Clamp(SizeBeginValue - (BeginMousePos.x - Input.mousePosition.x), 1, 256);
                        UpdateMenu(true);
                        UpdateBrushPosition(true);
                    }
                }
                else
                {
                    if (!PaintStarted && Input.GetKey(KeyCode.LeftControl))
                    {
                        if (CameraControler.Current.DragStartedGameplay)
                        {
                            if (UpdateBrushPosition(false))
                            {
                            }
                        }

                        if (Input.GetMouseButton(0))
                        {
                            BrushTarget.SetValue(CameraControler.GetLastScmHeight());
                        }
                        else if (Input.GetMouseButton(1))
                        {
                            BrushMini.SetValue(CameraControler.GetLastScmHeight());
                        }
                        else if (Input.GetMouseButton(2))
                        {
                            BrushMax.SetValue(CameraControler.GetLastScmHeight());
                        }
                    }
                    else if (Edit.MauseOnGameplay && Input.GetMouseButtonDown(0))
                    {
                        if (UpdateBrushPosition(true))
                        {
                            ScmapEditor.Current.Teren.heightmapPixelError = 20;
                            GenerateControlTex.StopGenerateNormal();
                            ScmapEditor.Current.TerrainMaterial.SetFloat("_GeneratingNormal", 1);
                            PaintStarted = true;
                            RecalcTerrainClamp();
                            SymmetryPaint();
                        }
                    }
                    else if (Input.GetMouseButton(0))
                    {
                        if (CameraControler.Current.DragStartedGameplay)
                        {
                            if (UpdateBrushPosition(false))
                            {
                            }
                            RecalcTerrainClamp();
                            SymmetryPaint();
                        }
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                    }
                    else
                    {
                        UpdateBrushPosition(true);
                    }
                }
            }

            if (!CameraControler.IsInputFieldFocused())            // Ignore all unput
            {
                if (Input.GetMouseButton(0))
                {
                }
                else if (KeyboardManager.SwitchTypeNext())
                {
                    int SelectedBrush = 0;
                    for (int i = 0; i < BrushTypes.Length; i++)
                    {
                        if (BrushTypes[i].isOn)
                        {
                            SelectedBrush = i;
                            //BrushTypes[i].isOn = false;
                        }
                    }

                    SelectedBrush++;
                    if (SelectedBrush >= BrushTypes.Length)
                    {
                        SelectedBrush = 0;
                    }

                    BrushTypes[SelectedBrush].isOn = true;
                }
                else if (KeyboardManager.SwitchType1())
                {
                    BrushTypes[0].isOn = true;
                }
                else if (KeyboardManager.SwitchType2())
                {
                    BrushTypes[1].isOn = true;
                }
                else if (KeyboardManager.SwitchType3())
                {
                    BrushTypes[2].isOn = true;
                }
                else if (KeyboardManager.SwitchType4())
                {
                    BrushTypes[3].isOn = true;
                }

                if (KeyboardManager.IncreaseTarget())
                {
                    if (BrushTarget.value < 256)
                    {
                        BrushTarget.SetValue((int)BrushTarget.value + 1);
                    }
                }
                else if (KeyboardManager.DecreaseTarget())
                {
                    if (BrushTarget.value > 0)
                    {
                        BrushTarget.SetValue((int)BrushTarget.value - 1);
                    }
                }
            }


            if (Input.GetMouseButtonUp(0))
            {
                if (TerainChanged)
                {
                    Undo.RegisterUndo(new UndoHistory.HistoryTerrainHeight(), new UndoHistory.HistoryTerrainHeight.TerrainHeightHistoryParameter(beginHeights));
                    TerainChanged = false;
                }

                if (Painting)
                {
                    Painting = false;
                    RegenerateMaps();
                }

                PaintStarted = false;
                ScmapEditor.Current.Teren.heightmapPixelError = 4;
            }



            BrushGenerator.RegeneratePaintBrushIfNeeded();
        }