Skip to content

Commit

Permalink
refactoring mapgenerator.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanstudioroot committed May 26, 2020
1 parent 30a70bb commit 2ccfa61
Show file tree
Hide file tree
Showing 40 changed files with 1,766 additions and 1,432 deletions.
23 changes: 23 additions & 0 deletions Assets/rootgen-unitycsharp/Editor/BiomeDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if(UNITY_EDITOR)
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;

[CustomPropertyDrawer(typeof(CubeVector))]
public class BiomeDrawer : PropertyDrawer {
public override void OnGUI(
Rect position,
SerializedProperty property,
GUIContent label
) {
Biome biome = new Biome(
(Terrains)property.FindPropertyRelative("Terrain").intValue,
property.FindPropertyRelative("plant").intValue
);

position = EditorGUI.PrefixLabel(position, label);
GUI.Label(position, biome.ToString());
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Assets/rootgen-unitycsharp/Editor/ClimateDataDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if (UNITY_EDITOR)
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;

[CustomPropertyDrawer(typeof(ClimateData))]
public class ClimateDataDrawer : PropertyDrawer {
public override void OnGUI(
Rect position,
SerializedProperty property,
GUIContent label
) {
ClimateData cubeVector = new ClimateData(
property.FindPropertyRelative("clouds").floatValue,
property.FindPropertyRelative("moisture").floatValue,
property.FindPropertyRelative("temperature").floatValue
);

position = EditorGUI.PrefixLabel(position, label);
GUI.Label(position, cubeVector.ToString());
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/rootgen-unitycsharp/Editor/CubeVectorDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if (UNITY_EDITOR)
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;

[CustomPropertyDrawer(typeof(CubeVector))]
public class CubeVectorDrawer : PropertyDrawer {
public override void OnGUI(
Rect position,
SerializedProperty property,
GUIContent label
) {
CubeVector cubeVector = new CubeVector(
property.FindPropertyRelative("_x").intValue,
property.FindPropertyRelative("_z").intValue
);

position = EditorGUI.PrefixLabel(position, label);
GUI.Label(position, cubeVector.ToString());
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions Assets/rootgen-unitycsharp/Editor/HexCoordinatesDrawer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ int wrapSize
if (hasRightWall) {
bool hasTower = false;

if (leftHex.Elevation == rightHex.Elevation) {
if (leftHex.elevation == rightHex.elevation) {
RandomHash rootHash = HexagonPoint.SampleHashGrid (
(pivot + left + right) * 1f / 3f
);
Expand All @@ -495,7 +495,7 @@ int wrapSize
hasTower
);
}
else if (leftHex.Elevation < rightHex.Elevation) {
else if (leftHex.elevation < rightHex.elevation) {
AddWallWedge(
pivot,
left,
Expand All @@ -514,7 +514,7 @@ int wrapSize
}
}
else if (hasRightWall) {
if (rightHex.Elevation < leftHex.Elevation) {
if (rightHex.elevation < leftHex.elevation) {
AddWallWedge(
right,
pivot,
Expand Down
83 changes: 63 additions & 20 deletions Assets/rootgen-unitycsharp/Runtime/Core/Hex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@
using System.Collections.Generic;

public class Hex : MonoBehaviour, IHexPoint {

[SerializeField]
public Terrains terrainType;
private ClimateData _climateData;
public ClimateData ClimateData {
get {
return _climateData;
}

set {
_climateData = value;
}
}

[SerializeField]
private Biome _biome;
public Biome Biome {
get {
return _biome;
}

set {
_biome = value;
}
}

public Terrains TerrainType {
get {
return _biome.terrain;
}
}

[SerializeField]
private CubeVector _cubeCoordinates;

private static int MaxFeatureLevel {
get {
Expand All @@ -26,15 +55,15 @@ public Vector3 Position {
public float StreamBedY {
get {
return
(Elevation + HexagonPoint.streamBedElevationOffset) *
(elevation + HexagonPoint.streamBedElevationOffset) *
HexagonPoint.elevationStep;
}
}

public float RiverSurfaceY {
get {
return
(Elevation + HexagonPoint.waterElevationOffset) *
(elevation + HexagonPoint.waterElevationOffset) *
HexagonPoint.elevationStep;
}
}
Expand All @@ -49,7 +78,7 @@ public float WaterSurfaceY {

public bool IsUnderwater {
get {
return WaterLevel > Elevation;
return WaterLevel > elevation;
}
}

Expand All @@ -61,8 +90,8 @@ public bool IsSpecial {

public int ViewElevation {
get {
return Elevation >= WaterLevel ?
Elevation : WaterLevel;
return elevation >= WaterLevel ?
elevation : WaterLevel;
}
}

Expand All @@ -72,7 +101,15 @@ public bool IsVisible {
}
}

public CubeVector Coordinates { get; private set; }
public CubeVector CubeCoordinates {
get {
return _cubeCoordinates;
}

private set {
_cubeCoordinates = value;
}
}

private Mesh GetInteractionMesh(float radius) {
Mesh result = new Mesh();
Expand Down Expand Up @@ -119,20 +156,20 @@ public void InteractionMeshEnabled(bool enabled, float outerRadius) {
}
}

public int Elevation { get; private set; }
public int elevation;

public void SetElevation(
int elevation,
float hexOuterRadius,
int wrapSize
) {
if (Elevation == elevation) {
if (this.elevation == elevation) {
return;
}

int originalViewElevation = ViewElevation;

Elevation = elevation;
this.elevation = elevation;

if (ViewElevation != originalViewElevation) {
ShaderData.ViewElevationChanged();
Expand All @@ -148,7 +185,13 @@ int wrapSize
public int WaterLevel { get; set; }
public int UrbanLevel { get; set; }
public int FarmLevel { get; set; }
public int PlantLevel { get; set; }

public int PlantLevel {
get {
return _biome.plant;
}
}

public int SpecialIndex { get; set; }
public bool IsExplored { get; set; }
public int SearchPhase { get; set; }
Expand Down Expand Up @@ -187,7 +230,7 @@ int wrapSize
GameObject resultObj = new GameObject("Hex");
Hex resultMono = resultObj.AddComponent<Hex>();

resultMono.Coordinates = CubeVector.FromOffsetCoordinates(
resultMono.CubeCoordinates = CubeVector.FromOffsetCoordinates(
offsetX,
offsetZ,
wrapSize
Expand All @@ -210,7 +253,7 @@ public void ResetVisibility() {
}

public ElevationEdgeTypes GetEdgeType(Hex otherHex) {
return HexagonPoint.GetEdgeType(Elevation, otherHex.Elevation);
return HexagonPoint.GetEdgeType(elevation, otherHex.elevation);
}

public void DisableHighlight() {
Expand Down Expand Up @@ -272,21 +315,21 @@ public void SetLabel(string text) {
public override string ToString() {
return
"[X: " +
Coordinates.X.ToString() + ", Y:" +
Coordinates.Y.ToString() + ", Z:" +
Coordinates.Z.ToString() +
CubeCoordinates.X.ToString() + ", Y:" +
CubeCoordinates.Y.ToString() + ", Z:" +
CubeCoordinates.Z.ToString() +
"]";
}

private void Awake() {
//SetEnabledInteractionMesh(true);
Elevation = int.MinValue;
elevation = int.MinValue;
}

private bool IsValidRiverDestination(Hex neighbor) {
return neighbor &&
(
Elevation >= neighbor.Elevation || WaterLevel == neighbor.Elevation
elevation >= neighbor.elevation || WaterLevel == neighbor.elevation
);
}

Expand All @@ -304,7 +347,7 @@ private void RefreshPosition(
int wrapSize
) {
Vector3 position = transform.localPosition;
position.y = Elevation * HexagonPoint.elevationStep;
position.y = elevation * HexagonPoint.elevationStep;

position.y +=
(
Expand Down
Loading

0 comments on commit 2ccfa61

Please sign in to comment.