示例#1
0
        bool UpdateBrushPosition(bool Forced = false, bool Size = true, bool Position = true)
        {
            //Debug.Log(Vector3.Distance(MouseBeginClick, Input.mousePosition));
            if (Forced || Vector3.Distance(MouseBeginClick, Input.mousePosition) > 1)
            {
            }
            else
            {
                return(false);
            }

            float SizeXprop      = MapLuaParser.GetMapSizeX() / 512f;
            float SizeZprop      = MapLuaParser.GetMapSizeY() / 512f;
            float BrushSizeValue = BrushSize.value;

            if (BrushSizeValue < 0.2f)
            {
                BrushSizeValue = 0.2f;
            }

            if (Size)
            {
                TerrainMaterial.SetFloat("_BrushSize", BrushSizeValue / ((SizeXprop + SizeZprop) / 2f));
            }


            MouseBeginClick = Input.mousePosition;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Position && Physics.Raycast(ray, out hit, 2000, TerrainMask))
            {
                BrushPos = hit.point;
                if (SnapToGround.isOn && BrushSize.value < 1.5f)
                {
                    //BrushPos = Vector3.Lerp(ScmapEditor.SnapToSmallGridCenter(BrushPos), BrushPos, (BrushSize.value - 0.2f) / 1.5f);
                    BrushPos = ScmapEditor.SnapToSmallGrid(BrushPos + new Vector3(0.025f, 0, -0.025f));
                }

                BrushPos.y = ScmapEditor.Current.Teren.SampleHeight(BrushPos);

                Vector3 tempCoord = ScmapEditor.Current.Teren.gameObject.transform.InverseTransformPoint(BrushPos);
                Vector3 coord     = Vector3.zero;
                float   SizeX     = (int)((BrushSizeValue / SizeXprop) * 100) * 0.01f;
                float   SizeZ     = (int)((BrushSizeValue / SizeZprop) * 100) * 0.01f;
                coord.x = (tempCoord.x - SizeX * MapLuaParser.GetMapSizeX() * 0.0001f) / ScmapEditor.Current.Teren.terrainData.size.x;
                coord.z = (tempCoord.z - SizeZ * MapLuaParser.GetMapSizeY() * 0.0001f) / ScmapEditor.Current.Teren.terrainData.size.z;

                TerrainMaterial.SetFloat("_BrushUvX", coord.x);
                TerrainMaterial.SetFloat("_BrushUvY", coord.z);

                return(true);
            }
            return(false);
        }