Initial commit
This commit is contained in:
63
Assets/scripts/cell.cs
Normal file
63
Assets/scripts/cell.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class cell : MonoBehaviour
|
||||
{
|
||||
public Vector2Int pos = new Vector2Int(0, 0);
|
||||
public float noiseValue;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
/*
|
||||
GetComponent<SpriteRenderer>().color = new Color(noiseValue, noiseValue, noiseValue, 1);
|
||||
noiseValue = Random.Range(0f, 1f);
|
||||
*/
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
//Debug.Log(noiseValue);
|
||||
noiseValue = Mathf.Pow(noiseValue, 1.7f);
|
||||
|
||||
float pow = 1.2f;
|
||||
|
||||
Color color;
|
||||
if (noiseValue <= 0.35)
|
||||
{
|
||||
noiseValue = Mathf.Pow(noiseValue, pow);
|
||||
color = new Color(noiseValue*0.2f, noiseValue * 0.2f, noiseValue + 0.1f);//âîäà
|
||||
}
|
||||
else if (noiseValue <= 0.5)
|
||||
{
|
||||
noiseValue = Mathf.Pow(noiseValue, pow);
|
||||
color = new Color(noiseValue*0.4f, noiseValue+0.3f, noiseValue*0.4f);//íèçèíà
|
||||
}
|
||||
else if (noiseValue <= 0.8)
|
||||
{
|
||||
noiseValue = Mathf.Pow(noiseValue, pow);
|
||||
color = new Color(noiseValue * 0.2f, noiseValue + 0.3f, noiseValue * 0.2f);//ïîëå
|
||||
}
|
||||
else if (noiseValue <= 0.95)
|
||||
{
|
||||
noiseValue = Mathf.Pow(noiseValue, pow);
|
||||
color = new Color(noiseValue*0.8f + 0.1f, noiseValue * 0.4f, noiseValue * 0.2f);//ãîðû
|
||||
}
|
||||
else
|
||||
{
|
||||
noiseValue = Mathf.Pow(noiseValue, pow);
|
||||
color = new Color(noiseValue*0.6f + 0.0f, noiseValue * 0.1f, noiseValue * 0.0f);//íåïðîõîäèìûé ïèê
|
||||
}
|
||||
GetComponent<SpriteRenderer>().color = color;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/scripts/cell.cs.meta
Normal file
11
Assets/scripts/cell.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62970f09f26042b4c8cf4ca27a04b8f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
Assets/scripts/gridGen.cs
Normal file
69
Assets/scripts/gridGen.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class gridGen : MonoBehaviour
|
||||
{
|
||||
public perlinNoise noise;
|
||||
public GameObject hexPrefab;
|
||||
public Transform mapStart;
|
||||
private float translationVert;
|
||||
|
||||
public int x = 32;
|
||||
public int y = 32;
|
||||
|
||||
private float scaleY = Mathf.Sqrt(3) / 2;
|
||||
private float scaleX = 1;
|
||||
|
||||
private int nowX;
|
||||
private int nowY;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
/*
|
||||
GameObject hex2 = Instantiate(hexPrefab);
|
||||
hex2.transform.Translate(new Vector3(0, scaleY, 0));
|
||||
|
||||
GameObject hex3 = Instantiate(hexPrefab);
|
||||
hex3.transform.Translate(new Vector3(0.75f*scaleX, 0.5f*scaleY, 0));
|
||||
*/
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (nowX < x)
|
||||
{
|
||||
|
||||
while (nowY < y)
|
||||
{
|
||||
float modX = 0.25f;
|
||||
float modY = 0;
|
||||
|
||||
if (nowX % 2 == 1)
|
||||
{
|
||||
modY = 0.5f;
|
||||
}
|
||||
|
||||
|
||||
initHex(mapStart.position.x + (scaleX * nowX) - (modX*scaleX*nowX), mapStart.position.y + (scaleY * nowY) + (modY*scaleY));
|
||||
nowY++;
|
||||
}
|
||||
|
||||
{
|
||||
nowX++;
|
||||
nowY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initHex(float x, float y)
|
||||
{
|
||||
GameObject hex = Instantiate(hexPrefab);
|
||||
hex.transform.Translate(new Vector3(x, y, 0));
|
||||
hex.GetComponent<cell>().noiseValue = noise.getNoise((float) nowX/this.x, (float) nowY /this.x, Mathf.Max(this.x, this.y));
|
||||
hex.GetComponent<cell>().Init();
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/scripts/gridGen.cs.meta
Normal file
11
Assets/scripts/gridGen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f33a479594a257f4ead9b08bcea0dd88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/scripts/hexCulling.cs
Normal file
21
Assets/scripts/hexCulling.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class hexCulling : MonoBehaviour
|
||||
{
|
||||
public Camera camera;
|
||||
public float baseX;
|
||||
public float baseY;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.localScale = new Vector3(-1 * baseX * (10+camera.transform.position.z), -1 * baseX * (10+camera.transform.position.z), 3);
|
||||
}
|
||||
}
|
||||
11
Assets/scripts/hexCulling.cs.meta
Normal file
11
Assets/scripts/hexCulling.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f818c27fab882aa4ea5ad1e4f175462f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/scripts/perlinNoise.cs
Normal file
55
Assets/scripts/perlinNoise.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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 * 1000000000); }
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/scripts/perlinNoise.cs.meta
Normal file
11
Assets/scripts/perlinNoise.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af97c7208f5e6ff4bb5aeeb01e63506c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/scripts/randInitColor.cs
Normal file
30
Assets/scripts/randInitColor.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class randInitColor : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public float minR = 0;
|
||||
public float minG = 0;
|
||||
public float minB = 0;
|
||||
|
||||
public float maxR = 1;
|
||||
public float maxG = 1;
|
||||
public float maxB = 1;
|
||||
void Start()
|
||||
{
|
||||
float r = Random.RandomRange(minR, maxR);
|
||||
float g = Random.RandomRange(minG, maxG);
|
||||
float b = Random.RandomRange(minB, maxB);
|
||||
gameObject.GetComponent<SpriteRenderer>().color = new Color(r, g, b, 1);
|
||||
gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||||
gameObject.GetComponent<SpriteRenderer>().enabled = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/scripts/randInitColor.cs.meta
Normal file
11
Assets/scripts/randInitColor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19c2bb1a243af884cb05abb2b4e03490
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user