public void Start() { try { _terrainProperties = FindObjectOfType <TerrainProperties>(); _noColorOffset = new Vector3(0f, 0f, 0f); _defaultGrassFertilityColorOffset = Shader.GetGlobalVector("_GrassFertilityColorOffset"); _defaultGrassFieldColorOffset = Shader.GetGlobalVector("_GrassFieldColorOffset"); _defaultGrassForestColorOffset = Shader.GetGlobalVector("_GrassForestColorOffset"); _defaultGrassPollutionColorOffset = Shader.GetGlobalVector("_GrassPollutionColorOffset"); _defaultWaterColorClean = Shader.GetGlobalColor("_WaterColorClean"); _defaultWaterColorDirty = Shader.GetGlobalColor("_WaterColorDirty"); _fogProperties = FindObjectOfType <FogProperties>(); if (_fogProperties != null) { _defaultPollutionAmount = _fogProperties.m_PollutionAmount; _defaultFogDensity = _fogProperties.m_FogDensity; _defaultColorDecay = _fogProperties.m_ColorDecay; } } catch (Exception e) { Debug.Log("[Hide It!] ModManager:Start -> Exception: " + e.Message); } }
private static void SetShaderVectors() { TerrainProperties properties = TerrainManager.instance.m_properties; Shader.SetGlobalVector("_GrassFieldColorOffset", properties.m_grassFieldColorOffset); Shader.SetGlobalVector("_GrassFertilityColorOffset", properties.m_grassFertilityColorOffset); Shader.SetGlobalVector("_GrassForestColorOffset", properties.m_grassForestColorOffset); Shader.SetGlobalVector("_GrassPollutionColorOffset", new Vector4(properties.m_grassPollutionColorOffset.x, properties.m_grassPollutionColorOffset.y, properties.m_grassPollutionColorOffset.z, properties.m_cliffSandNormalTiling)); }
void CreateTiles() { scripts = new TerrainProperties[heightIncrements + 1][]; for (int z = 0; z <= heightIncrements; z++) { int mod = (int)Mathf.Abs(z%2); scripts[z] = new TerrainProperties[widthIncrements - mod + 1]; for (int x = 0; x <= widthIncrements - mod; x++) { Vector3 pos = new Vector3 ((x - widthIncrements/2)*1.5f + mod * .75f, 0, (z - heightIncrements/2) * .433f); GameObject t = Instantiate (tile, pos, Quaternion.identity) as GameObject; TerrainProperties tp = t.GetComponent<TerrainProperties>() as TerrainProperties;; scripts[z][x] = tp; count++; } } }
protected override bool SetFromProperties() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (Name) { case TextureName.WaterFoam: return(SetTexture(properties.m_waterFoam)); case TextureName.WaterNormal: return(SetTexture(properties.m_waterNormal)); default: return(false); } }
protected override bool SetFromProperties() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (Name) { case OffsetName.GrassFertilityColorOffset: return SetValue(properties.m_grassFertilityColorOffset); case OffsetName.GrassFieldColorOffset: return SetValue(properties.m_grassFieldColorOffset); case OffsetName.GrassForestColorOffset: return SetValue(properties.m_grassForestColorOffset); case OffsetName.GrassPollutionColorOffset: return SetValue(properties.m_grassPollutionColorOffset); default: return false; } }
void CreateTiles() { scripts = new TerrainProperties[heightIncrements + 1][]; for (int z = 0; z <= heightIncrements; z++) { int mod = (int)Mathf.Abs(z % 2); scripts[z] = new TerrainProperties[widthIncrements - mod + 1]; for (int x = 0; x <= widthIncrements - mod; x++) { Vector3 pos = new Vector3((x - widthIncrements / 2) * 1.5f + mod * .75f, 0, (z - heightIncrements / 2) * .433f); GameObject t = Instantiate(tile, pos, Quaternion.identity) as GameObject; TerrainProperties tp = t.GetComponent <TerrainProperties>() as TerrainProperties;; scripts[z][x] = tp; count++; } } }
protected override bool SetFromProperties() { TerrainProperties properties = TerrainManager.instance.m_properties; bool success; switch (Name) { case TextureName.GrassDiffuseTexture: success = SetTexture(properties.m_grassDiffuse); return(success && SetValue(properties.m_grassTiling)); case TextureName.RuinedDiffuseTexture: success = SetTexture(properties.m_ruinedDiffuse); return(success && SetValue(properties.m_ruinedTiling)); case TextureName.PavementDiffuseTexture: success = SetTexture(properties.m_pavementDiffuse); return(success && SetValue(properties.m_pavementTiling)); case TextureName.GravelDiffuseTexture: success = SetTexture(properties.m_gravelDiffuse); return(success && SetValue(properties.m_gravelTiling)); case TextureName.CliffDiffuseTexture: success = SetTexture(properties.m_cliffDiffuse); return(success && SetValue(properties.m_cliffTiling)); case TextureName.OilDiffuseTexture: success = SetTexture(properties.m_oilDiffuse); return(success && SetValue(properties.m_oilTiling)); case TextureName.OreDiffuseTexture: success = SetTexture(properties.m_oreDiffuse); return(success && SetValue(properties.m_oreTiling)); case TextureName.SandDiffuseTexture: success = SetTexture(properties.m_sandDiffuse); return(success && SetValue(properties.m_sandTiling)); case TextureName.CliffSandNormalTexture: success = SetTexture(properties.m_cliffSandNormal); return(success && SetValue(properties.m_cliffSandNormalTiling)); default: return(false); } }
protected override bool SetFromProperties() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (DetailName) { case Name.GrassDetailEnabled: return(SetValue(properties.m_useGrassDecorations)); case Name.FertileDetailEnabled: return(SetValue(properties.m_useFertileDecorations)); case Name.RocksDetailEnabled: return(SetValue(properties.m_useCliffDecorations)); default: return(false); } }
protected override bool SetFromProperties() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (Name) { case ColorName.WaterClean: return(SetValue(properties.m_waterColorClean)); case ColorName.WaterDirty: return(SetValue(properties.m_waterColorDirty)); case ColorName.WaterUnder: return(SetValue(properties.m_waterColorUnder)); default: return(false); } }
protected override void LoadValue() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (DetailName) { case Name.GrassDetailEnabled: properties.m_useGrassDecorations = (bool)(CustomValue ?? Value); break; case Name.FertileDetailEnabled: properties.m_useFertileDecorations = (bool)(CustomValue ?? Value); break; case Name.RocksDetailEnabled: properties.m_useCliffDecorations = (bool)(CustomValue ?? Value); break; } }
protected override void LoadValue() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (Name) { case OffsetName.GrassFertilityColorOffset: properties.m_grassFertilityColorOffset = (Vector3)(CustomValue ?? Value); break; case OffsetName.GrassFieldColorOffset: properties.m_grassFieldColorOffset = (Vector3)(CustomValue ?? Value); break; case OffsetName.GrassForestColorOffset: properties.m_grassForestColorOffset = (Vector3)(CustomValue ?? Value); break; case OffsetName.GrassPollutionColorOffset: properties.m_grassPollutionColorOffset = (Vector3)(CustomValue ?? Value); break; } SetShaderVectors(); }
protected override void LoadValue() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (Name) { case ColorName.WaterClean: properties.m_waterColorClean = (Color)(CustomValue ?? Value); Shader.SetGlobalColor("_WaterColorClean", new Color(properties.m_waterColorClean.r, properties.m_waterColorClean.g, properties.m_waterColorClean.b, properties.m_waterRainFoam)); break; case ColorName.WaterDirty: properties.m_waterColorDirty = (Color)(CustomValue ?? Value); Shader.SetGlobalColor("_WaterColorDirty", properties.m_waterColorDirty); break; case ColorName.WaterUnder: properties.m_waterColorUnder = (Color)(CustomValue ?? Value); Shader.SetGlobalColor("_WaterColorUnder", properties.m_waterColorUnder); break; } }
protected override void LoadValue() { TerrainProperties properties = TerrainManager.instance.m_properties; Texture oldTexture = null; switch (Name) { case TextureName.WaterFoam: oldTexture = properties.m_waterFoam; properties.m_waterFoam = Texture; Shader.SetGlobalTexture("_WaterFoam", properties.m_waterFoam); break; case TextureName.WaterNormal: oldTexture = properties.m_waterNormal; properties.m_waterNormal = Texture; Shader.SetGlobalTexture("_WaterNormal", properties.m_waterNormal); break; } if (oldTexture != null && !ReferenceEquals(oldTexture, Texture)) { Object.Destroy(oldTexture); } }
public void LoadTiling() { TerrainProperties properties = TerrainManager.instance.m_properties; switch (Name) { case TextureName.GrassDiffuseTexture: properties.m_grassTiling = (float)(CustomValue ?? Value); break; case TextureName.RuinedDiffuseTexture: properties.m_ruinedTiling = (float)(CustomValue ?? Value); break; case TextureName.PavementDiffuseTexture: properties.m_pavementTiling = (float)(CustomValue ?? Value); break; case TextureName.GravelDiffuseTexture: properties.m_gravelTiling = (float)(CustomValue ?? Value); break; case TextureName.CliffDiffuseTexture: properties.m_cliffTiling = (float)(CustomValue ?? Value); break; case TextureName.OilDiffuseTexture: properties.m_oilTiling = (float)(CustomValue ?? Value); break; case TextureName.OreDiffuseTexture: properties.m_oreTiling = (float)(CustomValue ?? Value); break; case TextureName.SandDiffuseTexture: properties.m_sandTiling = (float)(CustomValue ?? Value); break; case TextureName.CliffSandNormalTexture: properties.m_cliffSandNormalTiling = (float)(CustomValue ?? Value); break; } Shader.SetGlobalVector("_GrassPollutionColorOffset", // Needed here to set CliffSandNormalTiling new Vector4(properties.m_grassPollutionColorOffset.x, properties.m_grassPollutionColorOffset.y, properties.m_grassPollutionColorOffset.z, properties.m_cliffSandNormalTiling)); Shader.SetGlobalVector("_TerrainTextureTiling1", new Vector4(properties.m_pavementTiling, properties.m_ruinedTiling, properties.m_sandTiling, properties.m_cliffTiling)); Shader.SetGlobalVector("_TerrainTextureTiling2", new Vector4(properties.m_grassTiling, properties.m_gravelTiling, properties.m_oreTiling, properties.m_oilTiling)); }
protected override void LoadValue() { TerrainProperties properties = TerrainManager.instance.m_properties; Texture2D oldTexture = null; switch (Name) { case TextureName.GrassDiffuseTexture: oldTexture = properties.m_grassDiffuse; properties.m_grassDiffuse = Texture; Shader.SetGlobalTexture("_TerrainGrassDiffuse", properties.m_grassDiffuse); break; case TextureName.RuinedDiffuseTexture: oldTexture = properties.m_ruinedDiffuse; properties.m_ruinedDiffuse = Texture; Shader.SetGlobalTexture("_TerrainRuinedDiffuse", properties.m_ruinedDiffuse); break; case TextureName.PavementDiffuseTexture: oldTexture = properties.m_pavementDiffuse; properties.m_pavementDiffuse = Texture; Shader.SetGlobalTexture("_TerrainPavementDiffuse", properties.m_pavementDiffuse); break; case TextureName.GravelDiffuseTexture: oldTexture = properties.m_gravelDiffuse; properties.m_gravelDiffuse = Texture; Shader.SetGlobalTexture("_TerrainGravelDiffuse", properties.m_gravelDiffuse); break; case TextureName.CliffDiffuseTexture: oldTexture = properties.m_cliffDiffuse; properties.m_cliffDiffuse = Texture; Shader.SetGlobalTexture("_TerrainCliffDiffuse", properties.m_cliffDiffuse); break; case TextureName.OreDiffuseTexture: oldTexture = properties.m_oreDiffuse; properties.m_oreDiffuse = Texture; Shader.SetGlobalTexture("_TerrainOreDiffuse", properties.m_oreDiffuse); break; case TextureName.OilDiffuseTexture: oldTexture = properties.m_oilDiffuse; properties.m_oilDiffuse = Texture; Shader.SetGlobalTexture("_TerrainOilDiffuse", properties.m_oilDiffuse); break; case TextureName.SandDiffuseTexture: oldTexture = properties.m_sandDiffuse; properties.m_sandDiffuse = Texture; Shader.SetGlobalTexture("_TerrainSandDiffuse", properties.m_sandDiffuse); break; case TextureName.CliffSandNormalTexture: oldTexture = properties.m_cliffSandNormal; properties.m_cliffSandNormal = Texture; Shader.SetGlobalTexture("_TerrainCliffSandNormal", properties.m_cliffSandNormal); break; } if (oldTexture != null && !ReferenceEquals(oldTexture, Texture)) { Object.Destroy(oldTexture); } ThemeManager.MaybeUpdateThemeDecal(this); }
public override void Handle(TerrainModificationCommand command) { ushort[] m_tempBuffer = (ushort[])typeof(TerrainTool).GetField("m_tempBuffer", AccessTools.all).GetValue(ToolsModifierControl.GetTool <TerrainTool>()); TerrainManager instance = Singleton <TerrainManager> .instance; GameAreaManager manager2 = Singleton <GameAreaManager> .instance; SimulationManager manager3 = Singleton <SimulationManager> .instance; float[] brushData = command.BrushData; float num = command.BrushSize * 0.5f; float num2 = 16f; int b = 0x438; ushort[] rawHeights = instance.RawHeights; ushort[] finalHeights = instance.FinalHeights; ushort[] backupHeights = instance.BackupHeights; float strength = command.Strength; int num5 = 3; float num6 = 0.015625f; float num7 = 64f; Vector3 mousePosition = command.mousePosition; Vector3 vector2 = command.EndPosition - command.StartPosition; vector2.y = 0f; float sqrMagnitude = vector2.sqrMagnitude; if (sqrMagnitude != 0f) { sqrMagnitude = 1f / sqrMagnitude; } float num9 = 20f; bool flag = true; //(base.m_toolController.m_mode & ItemClass.Availability.Game) != ItemClass.Availability.None; int a = 0; int num11 = 0; //int currentCost = this.m_currentCost; int dirtBuffer = instance.DirtBuffer; int num14 = 0x80000; int dirtPrice = 0; if (flag) { if (manager2.PointOutOfArea(mousePosition)) { //this.m_toolErrors = ToolBase.ToolErrors.None | ToolBase.ToolErrors.OutOfArea; return; } TerrainProperties properties = instance.m_properties; if (properties != null) { dirtPrice = properties.m_dirtPrice; } } int num16 = Mathf.Max((int)(((mousePosition.x - num) / num2) + (b * 0.5f)), 0); int num17 = Mathf.Max((int)(((mousePosition.z - num) / num2) + (b * 0.5f)), 0); int num18 = Mathf.Min(((int)(((mousePosition.x + num) / num2) + (b * 0.5f))) + 1, b); int num19 = Mathf.Min(((int)(((mousePosition.z + num) / num2) + (b * 0.5f))) + 1, b); if (command.mode == Mode.Shift) { if (command.MouseRightDown) { num9 = -num9; } } else if ((command.mode == Mode.Soften) && command.MouseRightDown) { num5 = 10; } if ((m_tempBuffer == null) || (m_tempBuffer.Length < (((num19 - num17) + 1) * ((num18 - num16) + 1)))) { m_tempBuffer = new ushort[((num19 - num17) + 1) * ((num18 - num16) + 1)]; } for (int i = num17; i <= num19; i++) { float z = (i - (b * 0.5f)) * num2; float f = ((((z - mousePosition.z) + num) / command.BrushSize) * 64f) - 0.5f; int num23 = Mathf.Clamp(Mathf.FloorToInt(f), 0, 0x3f); int num24 = Mathf.Clamp(Mathf.CeilToInt(f), 0, 0x3f); for (int k = num16; k <= num18; k++) { float x = (k - (b * 0.5f)) * num2; float num27 = ((((x - mousePosition.x) + num) / command.BrushSize) * 64f) - 0.5f; int num28 = Mathf.Clamp(Mathf.FloorToInt(num27), 0, 0x3f); int num29 = Mathf.Clamp(Mathf.CeilToInt(num27), 0, 0x3f); int num30 = rawHeights[(i * (b + 1)) + k]; float num31 = num30 * num6; float y = 0f; if (flag && manager2.PointOutOfArea(new Vector3(x, mousePosition.y, z), num2 * 0.5f)) { m_tempBuffer[(((i - num17) * ((num18 - num16) + 1)) + k) - num16] = (ushort)num30; } else { float num33 = brushData[(num23 * 0x40) + num28]; float num34 = brushData[(num23 * 0x40) + num29]; float num35 = brushData[(num24 * 0x40) + num28]; float num36 = brushData[(num24 * 0x40) + num29]; float num37 = num33 + ((num34 - num33) * (num27 - num28)); float num38 = num35 + ((num36 - num35) * (num27 - num28)); float t = num37 + ((num38 - num37) * (f - num23)); t *= strength; if (t <= 0f) { m_tempBuffer[(((i - num17) * ((num18 - num16) + 1)) + k) - num16] = (ushort)num30; } else { if (command.mode == Mode.Shift) { y = (finalHeights[(i * (b + 1)) + k] * num6) + num9; } else if (command.mode == Mode.Level) { y = command.StartPosition.y; } else if (command.mode == Mode.Soften) { int num40 = Mathf.Max(k - num5, 0); int num41 = Mathf.Max(i - num5, 0); int num42 = Mathf.Min(k + num5, b); int num43 = Mathf.Min(i + num5, b); float num44 = 0f; for (int m = num41; m <= num43; m++) { for (int n = num40; n <= num42; n++) { float num47 = 1f - (((float)(((n - k) * (n - k)) + ((m - i) * (m - i)))) / ((float)(num5 * num5))); if (num47 > 0f) { y += finalHeights[(m * (b + 1)) + n] * (num6 * num47); num44 += num47; } } } if (num44 > 0.001f) { y /= num44; } else { y = finalHeights[(i * (b + 1)) + k]; } } else if (command.mode == Mode.Slope) { float num48 = (k - (b * 0.5f)) * num2; float num49 = (i - (b * 0.5f)) * num2; float num50 = (((num48 - command.StartPosition.x) * vector2.x) + ((num49 - command.StartPosition.z) * vector2.z)) * sqrMagnitude; y = Mathf.Lerp(command.StartPosition.y, command.EndPosition.y, num50); } float num51 = y; y = Mathf.Lerp(num31, y, t); int num52 = Mathf.Clamp(Mathf.RoundToInt(y * num7), 0, 0xffff); if (num52 == num30) { int num53 = Mathf.Clamp(Mathf.RoundToInt(num51 * num7), 0, 0xffff); if (num53 > num30) { if (((y - num31) * num7) > (manager3.m_randomizer.Int32(0, 0x2710) * 0.0001f)) { num52++; } } else if ((num53 < num30) && (((num31 - y) * num7) > (manager3.m_randomizer.Int32(0, 0x2710) * 0.0001f))) { num52--; } } m_tempBuffer[(((i - num17) * ((num18 - num16) + 1)) + k) - num16] = (ushort)num52; if (flag) { if (num52 > num30) { a += num52 - num30; } else if (num52 < num30) { num11 += num30 - num52; } int num54 = backupHeights[(i * (b + 1)) + k]; int num55 = Mathf.Abs((int)(num52 - num54)) - Mathf.Abs((int)(num30 - num54)); //currentCost += num55 * dirtPrice; } } } } } int num56 = a; int num57 = num11; ToolBase.ToolErrors none = ToolBase.ToolErrors.None; if (flag) { if (a > num11) { num56 = Mathf.Min(a, dirtBuffer + num11); if (num56 < a) { none |= ToolBase.ToolErrors.None | ToolBase.ToolErrors.NotEnoughDirt; GuideController properties = Singleton <GuideManager> .instance.m_properties; if (properties != null) { Singleton <TerrainManager> .instance.m_notEnoughDirt.Activate(properties.m_notEnoughDirt); } } GenericGuide tooMuchDirt = Singleton <TerrainManager> .instance.m_tooMuchDirt; if (tooMuchDirt != null) { tooMuchDirt.Deactivate(); } } else if (num11 > a) { num57 = Mathf.Min(num11, (num14 - dirtBuffer) + a); if (num57 < num11) { none |= ToolBase.ToolErrors.None | ToolBase.ToolErrors.TooMuchDirt; GuideController properties = Singleton <GuideManager> .instance.m_properties; if (properties != null) { Singleton <TerrainManager> .instance.m_tooMuchDirt.Activate(properties.m_tooMuchDirt); } } GenericGuide notEnoughDirt = Singleton <TerrainManager> .instance.m_notEnoughDirt; if (notEnoughDirt != null) { notEnoughDirt.Deactivate(); } } /*if (currentCost != Singleton<EconomyManager>.instance.PeekResource(EconomyManager.Resource.Landscaping, currentCost)) * { * this.m_toolErrors = none | (ToolBase.ToolErrors.None | ToolBase.ToolErrors.NotEnoughMoney); * return; * } * currentCost = this.m_currentCost; */ } //Singleton<TerrainTool>.instance.m_toolErrors = none; if ((num56 != 0) || (num57 != 0)) { GenericGuide terrainToolNotUsed = Singleton <TerrainManager> .instance.m_terrainToolNotUsed; if ((terrainToolNotUsed != null) && !terrainToolNotUsed.m_disabled) { terrainToolNotUsed.Disable(); } } for (int j = num17; j <= num19; j++) { for (int k = num16; k <= num18; k++) { int num60 = rawHeights[(j * (b + 1)) + k]; int num61 = m_tempBuffer[(((j - num17) * ((num18 - num16) + 1)) + k) - num16]; if (flag) { int num62 = num61 - num60; if (num62 > 0) { if (a > num56) { num62 = ((a - 1) + (num62 * num56)) / a; } a -= num61 - num60; num56 -= num62; num61 = num60 + num62; dirtBuffer -= num62; } else if (num62 < 0) { if (num11 > num57) { num62 = -(((num11 - 1) - (num62 * num57)) / num11); } num11 -= num60 - num61; num57 += num62; num61 = num60 + num62; dirtBuffer -= num62; } int num63 = backupHeights[(j * (b + 1)) + k]; int num64 = Mathf.Abs((int)(num61 - num63)) - Mathf.Abs((int)(num60 - num63)); //currentCost += num64 * dirtPrice; } if (num61 != num60) { rawHeights[(j * (b + 1)) + k] = (ushort)num61; int _strokeXmin = Math.Min(command.StrokeXmin, k); int _strokeXmax = Math.Max(command.StrokeXmax, k); int _strokeZmin = Math.Min(command.StrokeZmin, j); int _strokeZmax = Math.Max(command.StrokeZmax, j); typeof(TerrainTool).GetField("m_strokeXmin", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeXmin); typeof(TerrainTool).GetField("m_strokeXmax", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeXmax); typeof(TerrainTool).GetField("m_strokeZmin", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeZmin); typeof(TerrainTool).GetField("m_strokeZmax", AccessTools.all).SetValue(ToolsModifierControl.GetTool <TerrainTool>(), _strokeZmax); } } } if (flag) { instance.DirtBuffer = dirtBuffer; //this.m_currentCost = currentCost; } TerrainModify.UpdateArea((int)(num16 - 2), (int)(num17 - 2), (int)(num18 + 2), (int)(num19 + 2), true, false, false); }