public void AddTrees(ref WorldData worldData, int seed) { List <TreeData> treeData = new List <TreeData>(); System.Random rng = new System.Random(seed); int size = TerrainGenerator.size * (int)treesPerVoxel; float[,] landNoise = Procedural.NoiseMap(seed, TerrainGenerator.size, TerrainGenerator.noiseScale, terrainGenerator.multiplier); float[,] treeNoise = Procedural.NoiseMap(seed + 1, size, treeNoiseScale, AnimationCurve.Linear(0f, 0f, 1f, 1f)); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { Coords voxelCoords = new Coords(Mathf.FloorToInt(x / treesPerVoxel), Mathf.FloorToInt(y / treesPerVoxel)); bool adjacentOcean = Util.AdjacentProperty(Util.CoordsToVoxels(worldData.voxelData, Util.GetAdjacent(voxelCoords, true)), "isOcean"); bool adjacentLake = Util.AdjacentProperty(Util.CoordsToVoxels(worldData.voxelData, Util.GetAdjacent(voxelCoords, true)), "isLake"); if (worldData.voxelData[voxelCoords.x, voxelCoords.y].isLand && !worldData.voxelData[voxelCoords.x, voxelCoords.y].occupied && !adjacentOcean && (treeNoise[x, y] < treeThreshold || adjacentLake) && rng.Next(0, 1000) / 1000f < treeNoise[x, y] * landNoise[voxelCoords.x, voxelCoords.y] * treeDensity) { int treeType = rng.Next(0, treeObjects.Length); Coords treeCoords = new Coords(x, y); float rotation = rng.Next(0, 360); TreeData tree = new TreeData(treeCoords, voxelCoords, treeType, rotation); treeData.Add(tree); worldData.voxelData[voxelCoords.x, voxelCoords.y].occupied = true; worldData.voxelData[voxelCoords.x, voxelCoords.y].hasTrees = true; } } } worldData.treeData = treeData; }
private void SetupSphere() { var filter = GetComponent <MeshFilter>(); filter.mesh = Procedural.GenerateCubeSphere(GridSize, Radius); mMesh = filter.mesh; }
private void SetupPlane() { var filter = GetComponent <MeshFilter>(); filter.mesh = Procedural.GeneratePlaneMesh(Rows, Columns); mMesh = filter.mesh; }
public void AddRocks(ref WorldData worldData, int seed) { List <RockData> rockData = new List <RockData>(); System.Random rng = new System.Random(seed); int size = TerrainGenerator.size; float[,] noiseMap = Procedural.NoiseMap(seed + 2, size, rockNoiseScale, AnimationCurve.Linear(0f, 0f, 1f, 1f)); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { Coords coords = new Coords(x, y); bool adjacentOcean = Util.AdjacentProperty(Util.CoordsToVoxels(worldData.voxelData, Util.GetAdjacent(coords, true)), "isOcean"); if (worldData.voxelData[x, y].isLand && !adjacentOcean && !worldData.voxelData[x, y].occupied && noiseMap[x, y] < rockThreshold) { RockData rock = new RockData(coords, rng.Next(0, rockObjects.Length), rng.Next(0, 360)); rockData.Add(rock); worldData.voxelData[coords.x, coords.y].occupied = true; worldData.voxelData[coords.x, coords.y].navigable = false; } } } worldData.rockData = rockData; }
public Process[] ListWindows(Func <Process, bool> filter) { return(Procedural.Filter((Process p) => { return p.MainWindowTitle != null && !p.MainWindowTitle.Equals("") && filter(p); }, Process.GetProcesses())); }
// call game start void Start() { player = FindObjectOfType <Player2>(); wave = FindObjectOfType <Wave>(); procedural = FindObjectOfType <Procedural>(); // GameStart(); }
// Use this for initialization void Start() { var filter = GetComponent <MeshFilter>(); //filter.mesh = Procedural.GeneratePlaneMesh(45, 45); filter.mesh = Procedural.GenerateCubeMesh(4, 4, 4); mMesh = filter.mesh; mOriginalVertices = mMesh.vertices; mModifiedVertices = (Vector3[])mOriginalVertices.Clone(); }
public void GenerateTerrain(WorldData worldData) { MeshData meshData = Procedural.MeshFromVoxelData(worldData.voxelData); meshFilter.mesh = meshData.CreateMesh(); meshRenderer.sharedMaterial.mainTexture = Procedural.TextureFromVoxelData(worldData.voxelData); foreach (VoxelData v in worldData.voxelData) { Voxel voxel = Instantiate(voxelObj, Util.CoordsToVector3(v.coords), Quaternion.identity, this.transform).GetComponent <Voxel>(); voxel.Initialize(v); } navSurface.BuildNavMesh(); }
void set() { if (SceneManager.GetActiveScene().name != "Tutorial") { proc = FindObjectOfType <Procedural>(); templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent <RoomTemplates>(); for (int i = 0; i < objects.Length; i++) { for (int j = 0; j < counts[i]; j++) { float delay = proc.getCount(); StartCoroutine(SetRoom(templates.firstDelay + delay, i)); } } } }
// Use this for initialization void Start() { if (instance == null) { instance = this; } for (int x = 0; x < mapSizeX; x++) { for (int z = 0; z < mapSizeZ; z++) { float y = 0; GameObject generated; // if the height of the object is less than 1 generated in the scene if (y <= 1) { generated = Instantiate(grass) as GameObject; generated.transform.position = new Vector3(x, y, z); generated.transform.SetParent(this.transform); } } } }
void set() { proc = FindObjectOfType <Procedural>(); templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent <RoomTemplates>(); isBig = PercentReturn(templates.BigRoomPercent); float delay = proc.getCount(); if (isBig) { Invoke("checkBig", templates.delay + delay); Invoke("SetRoom", templates.delay + delay); } else { Invoke("SetRoom", templates.delay + delay); } }
private void SetupCube() { var filter = GetComponent <MeshFilter>(); filter.mesh = Procedural.GenerateCubeMesh(XSize, YSize, ZSize); mMesh = filter.mesh; var mat = GetComponent <Renderer>().material; mat.SetInt("_XSize", XSize); mat.SetInt("_YSize", YSize); mat.SetInt("_ZSize", ZSize); mat.SetInt("_Roundness", Roundness); mVertices = mMesh.vertices; //mat.GetFloat("XSize") }
// Use this for initialization public void Awake() { if (GameObject.Find("Frameworks") == null) { GameObject fmObj = Instantiate(Resources.Load("Presets/Frameworks")) as GameObject; fmObj.name = "Frameworks"; } if (GameObject.FindGameObjectWithTag("PlayerData") == null) { GameObject _dataplayer = Instantiate(Resources.Load("Presets/PlayerData")) as GameObject; _profile = _dataplayer.GetComponent<PlayerData>(); _profile.Launch(); } else { _profile = GameObject.FindGameObjectWithTag("PlayerData").GetComponent<PlayerData>(); _profile.Launch(); } if (_profile.SETUP.GameType == GameSetup.versionType.Demo) { // Screen.SetResolution(800,600, false); // GameObject.Find("Frameworks/OT/View").GetComponent<OTView>().pixelPerfectResolution = new Vector2(800f,600f); // GameObject.Find("Frameworks/OT/View").GetComponent<OTView>().alwaysPixelPerfect = true; // GameObject.Find("Frameworks/OT/View").GetComponent<OTView>().customSize = 4; } GAMESTATE = _EditorState; _player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>(); GlobTuning = Instantiate(Resources.Load("Tuning/Global")) as LPTuning; InputMan = Instantiate(Resources.Load("Tuning/InputManager")) as InputManager; CurrentLevelInfo = Instantiate(Resources.Load("Tuning/Levels/" + NAME)) as LevelInfo; LocalTuning = Instantiate(Resources.Load("Maps/" + NAME + "/Setup")) as LevelParameters; LocalTuning.initScript(); GameObject OutSpw = new GameObject("OuterSpawn"); OuterSpawn = OutSpw; OuterSpawn.transform.parent = FETool.findWithinChildren(this.gameObject, "Enviro").transform; OuterSpawn.transform.position = new Vector3(0f, -7.5f, 0f); tools = gameObject.AddComponent<LevelTools>(); tools._levMan = this; TranslateAllInScene(); CollectiblePlaces[] collecPla = FETool.findWithinChildren(this.gameObject, "Enviro/CollectiblePlaces").GetComponentsInChildren<CollectiblePlaces>(); foreach (CollectiblePlaces cpl in collecPla) { collecPlaces.Add(cpl); } Gate = GameObject.FindGameObjectWithTag("SpaceGate").GetComponent<SpaceGate>(); Gate.Setup(this); wpDirector = GetComponentInChildren<WaypointDirector>(); wpDirector.Setup(this); bricksMan = FETool.findWithinChildren(this.gameObject, "LevelBricks/Bricks").GetComponent<BricksManager>(); bricksMan.Setup(); if (GAMETYPE != LocalTuning.levelType) { Debug.Log("Type of LevelMana & Setup scrip arent't the same"); } GAMETYPE = LocalTuning.levelType; switch (GAMETYPE) { case LevelParameters.levelTypeList.Debuggin : { linearTrigger = gameObject.AddComponent<LinearStepTrigger>(); linearTrigger.Setup(this); break; } case LevelParameters.levelTypeList.Linear : { linearTrigger = gameObject.AddComponent<LinearStepTrigger>(); linearTrigger.Setup(this); break; } case LevelParameters.levelTypeList.Maze : { break; } case LevelParameters.levelTypeList.Procedural : { GameObject gameo = FETool.createGameObject("ProceduralManager", gameObject); ProcMana = gameo.AddComponent<Procedural>(); ProcMana.Setup(this); break; } case LevelParameters.levelTypeList.Vertical : { GameObject vm = new GameObject("VerticalManager"); VerticalManager = vm.AddComponent<VerticalScroller>(); vm.transform.parent = this.transform; VerticalManager.Setup(this); break; } } wpDirector.affectRelatedBricks(bricksMan.BricksList); if (LocalTuning.levelType != LevelParameters.levelTypeList.Debuggin) { if (GameObject.Find("UI") == null) { GameObject uiman = Instantiate(Resources.Load("Presets/UI")) as GameObject; uiman.name = "UI"; menuManager = uiman.GetComponent<MainMenu>(); } else { menuManager = GameObject.Find("UI").GetComponent<MainMenu>(); } } if (menuManager != null) { menuManager.Setup(this); } managerChecker(); // proc.triggerStep(proc._listSteps[0]); _player.Setup(); Setup(); }
public VoxelData[,] GenerateVoxelData(int seed) { System.Random rng = new System.Random(seed); VoxelData[,] voxelData = new VoxelData[size, size]; float[,] landNoise = Procedural.NoiseMap(seed, size, noiseScale, multiplier); float[,] colorNoise = Procedural.NoiseMap(seed + 1, size, ObjectGenerator.treeNoiseScale, AnimationCurve.Linear(0f, 0f, 1f, 1f)); float[,] falloffMap = Procedural.FalloffMap(size); //Determine what is land for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { landNoise[x, y] = Mathf.Max(0, landNoise[x, y] - falloffMap[x, y]); } } //Set corresponding voxel values for land for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { voxelData[x, y] = new VoxelData { coords = new Coords(x, y) }; if (landNoise[x, y] > waterThreshold) { voxelData[x, y].isLand = true; voxelData[x, y].navigable = true; } else { voxelData[x, y].isOcean = true; } } } //Find and mark lakes bool[,] marked = new bool[size, size]; List <List <Coords> > bodiesOfWater = new List <List <Coords> >(); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { marked[x, y] = false; } } for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { if (!marked[x, y] && voxelData[x, y].isOcean) { Stack <Coords> stack = new Stack <Coords>(); List <Coords> list = new List <Coords>(); stack.Push(new Coords(x, y)); while (stack.Count > 0) { Coords v = stack.Pop(); if (!marked[(int)v.x, (int)v.y]) { list.Add(v); marked[(int)v.x, (int)v.y] = true; foreach (Coords adj in Util.GetAdjacent(v, true)) { if (voxelData[(int)adj.x, (int)adj.y].isOcean) { stack.Push(adj); } } } } bodiesOfWater.Add(list); } } } foreach (List <Coords> body in bodiesOfWater) { if (body.Count < 100) { foreach (Coords v in body) { voxelData[v.x, v.y].isOcean = false; voxelData[v.x, v.y].isLake = true; } } } //Set voxel colors for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { if (voxelData[x, y].isLand) { Color baseColor = Color.Lerp(Palette.LandMin, Palette.LandMax, rng.Next(0, 1000) / 1000f); voxelData[x, y].color = SerializableColor.FromColor(Color.Lerp(baseColor, Palette.Chartreuse, Mathf.Pow(colorNoise[x, y] * landNoise[x, y], 2))); } else { voxelData[x, y].color = SerializableColor.FromColor(Palette.Water); } } } //Set beaches and coasts for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { Coords coords = new Coords(x, y); if (voxelData[x, y].isLand && Util.AdjacentProperty(Util.CoordsToVoxels(voxelData, Util.GetAdjacent(coords, true)), "isOcean") && colorNoise[x, y] > .5f) { voxelData[x, y].color = SerializableColor.FromColor(Color.Lerp(voxelData[x, y].color.ToColor(), Palette.Sand, Mathf.Pow(colorNoise[x, y], 2))); } else if (voxelData[x, y].isOcean && Util.AdjacentProperty(Util.CoordsToVoxels(voxelData, Util.GetAdjacent(coords, true)), "isLand")) { voxelData[x, y].color = SerializableColor.FromColor(Color.Lerp(voxelData[x, y].color.ToColor(), Palette.Coast, .1f)); } } } return(voxelData); }
public void Start() { var filter = GetComponent <MeshFilter>(); filter.mesh = Procedural.GenerateNonInclusivePlaneMesh(Rows, Columns); mMesh = filter.mesh; mPositions = new Vector3[Rows * Columns]; mPrevPositions = new Vector3[mPositions.Length]; mAccelerations = new Vector3[mPositions.Length]; mOriginalPositions = new Vector3[mPositions.Length]; Debug.AssertFormat(mPositions.Length == mMesh.vertexCount, "Vertex count is wrong"); for (int row = 0; row < Rows; row++) { for (int col = 0; col < Columns; col++) { mPositions[row * Columns + col] = new Vector3(col / (float)Columns, 0.0f, 1 - (row - 1) / (float)Rows); mPrevPositions[row * Columns + col] = mPositions[row * Columns + col]; mAccelerations[row * Columns + col] = Vector3.zero; mOriginalPositions[row * Columns + col] = mPositions[row * Columns + col]; // Strutcural Springs // Top if (row > 0) { mSprings.Add(new Spring(RCToIdx(row - 1, col), RCToIdx(row, col), mPositions, Color.green)); } // Left if (col > 0) { mSprings.Add(new Spring(RCToIdx(row, col - 1), RCToIdx(row, col), mPositions, Color.green)); } // Shear Springs // Top Left if (row > 0 && col > 0) { mSprings.Add(new Spring(RCToIdx(row - 1, col - 1), RCToIdx(row, col), mPositions, Color.yellow)); } // Top Right if (row > 0 && col < Columns - 1) { mSprings.Add(new Spring(RCToIdx(row - 1, col + 1), RCToIdx(row, col), mPositions, Color.yellow)); } // Bending Springs // Top skip 1 if (row > 1) { mSprings.Add(new Spring(RCToIdx(row - 2, col), RCToIdx(row, col), mPositions, Color.blue)); } if (col > 1) { mSprings.Add(new Spring(RCToIdx(row, col - 2), RCToIdx(row, col), mPositions, Color.blue)); } } } }
public string[] ListWindows() { return(Procedural.Map((Process p) => { return p.MainWindowTitle; }, Process.GetProcesses())); }
void Start() { _procedural = GameObject.FindGameObjectWithTag("World").GetComponent <Procedural>(); }