Files
hexwar/Assets/scripts/perlinNoise.cs
fegor101 e4e834d373 refactor: Hex, cell
cell - delete
Hex - refactor, feature
State: stable

В Hex перенесен функционал из cell.
2026-01-16 22:36:32 +03:00

56 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class perlinNoise : MonoBehaviour
{
public int seed = 0;
private float offsetX = 0;
private float offsetY = 0;
private float offsetX1 = 0;
private float offsetY1 = 0;
private float offsetX2 = 0;
private float offsetY2 = 0;
// Start is called before the first frame update
void Start()
{
if(seed == -1) { seed = (int) (Random.value * int.MaxValue); }
Debug.Log(seed);
Random.InitState(seed);
offsetX = Random.value;
offsetY = Random.value;
offsetX1 = Random.value;
offsetY1 = Random.value;
offsetX2 = Random.value;
offsetY2 = Random.value;
}
public float getNoise(float x, float y, int size)
{
float density = size / 32;
//Debug.Log(size);
//Debug.Log(density);
//Debug.Log(x + " " + y);
x *= density;
y *= density;
float val1 = Mathf.PerlinNoise(x + offsetX, y + offsetY);
float val2 = Mathf.PerlinNoise(x*2 + offsetX1, y*2 + offsetY1);
float val3 = Mathf.PerlinNoise(x*8 + offsetX2, y*8 + offsetY2);
float res = val1*0.7f+val2*0.4f+val3*0.3f;
return res;
}
}