-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
…. See Signal-K/sytizen#18 && https://skinetics.notion.site/fc9cae9c027f4e22b276303aa8306e36?v=6c35d6d36a0344c8b8ba24f22f0f1d76&pvs=4
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class ColourGenerator { | ||
|
||
ColourSettings settings; | ||
Texture2D texture; | ||
const int textureResolution = 50; | ||
|
||
public void UpdateSettings(ColourSettings settings) | ||
{ | ||
this.settings = settings; | ||
if (texture == null || texture.height != settings.biomeColourSettings.biomes.Length) { | ||
texture = new Texture2D(textureResolution, settings.biomeColourSettings.biomes.Length); | ||
} | ||
} | ||
|
||
public void UpdateElevation(MinMax elevationMinMax) { | ||
settings.planetMaterial.SetVector("_elevationMinMax", new Vector4(elevationMinMax.Min, elevationMinMax.Max)); | ||
} | ||
|
||
public BiomePercentFromPoint(Vector3 pointOnUnitSphere) { | ||
float heightPercent = (pointOnUnitSphere.y + 1 / 2f); | ||
float biomeIndex = 0; | ||
int numBiomes = settings.biomeColourSettings.biomes.length; | ||
|
||
for (int i = 0; i < numBiomes; i++) { | ||
if (settings.biomeColourSettings.biomes[i].startHeight < heightPercent) { | ||
biomeIndex = i; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return biomeIndex / Mathf.Max(1, numBiomes - 1); | ||
} | ||
|
||
public void UpdateColours() | ||
{ | ||
Color[] colours = new Color[texture.width * texture.height]; | ||
int colourIndex = 0; | ||
foreach (var biome in settings.biomeColourSettings.biomes) { | ||
for (int i = 0; i < textureResolution; i++) { | ||
Color gradientCol = biome.gradient.Evaluate(i / (textureResolution - 1f)); | ||
Color tintCol = biome.tint; | ||
colours[colourIndex] = gradientCol * (1 - biome.tintPercent) + tintCol * biome.tintPercent; | ||
colourIndex++; | ||
} | ||
} | ||
texture.SetPixels(colours); | ||
texture.Apply(); | ||
settings.planetMaterial.SetTexture("_texture", texture); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
[CreateAssetMenu()] | ||
public class ColourSettings : ScriptableObject { | ||
public Material planetMaterial; | ||
public BiomeColourSettings biomeColourSettings; | ||
|
||
[System.Serializable] | ||
public class BiomeColourSettings { | ||
public Biome[] biomes; | ||
|
||
[System.Serializable] | ||
public class Biome { | ||
public Gradient gradient; | ||
public Color tint; | ||
[Range(0,1)] | ||
public float startHeight; | ||
[Range(0,1)] | ||
public float tintPercent; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using UnityEngine; | ||
using System; | ||
using System.Collections; | ||
|
||
//Original version of the ConditionalHideAttribute created by Brecht Lecluyse (www.brechtos.com) | ||
//Modified by: Sebastian Lague | ||
|
||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | | ||
AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)] | ||
public class ConditionalHideAttribute : PropertyAttribute | ||
{ | ||
public string conditionalSourceField; | ||
public int enumIndex; | ||
|
||
public ConditionalHideAttribute(string boolVariableName) | ||
{ | ||
conditionalSourceField = boolVariableName; | ||
} | ||
|
||
public ConditionalHideAttribute(string enumVariableName, int enumIndex) | ||
{ | ||
conditionalSourceField = enumVariableName; | ||
this.enumIndex = enumIndex; | ||
} | ||
|
||
} | ||
|
||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections.Generic; | ||
|
||
//Original version of the ConditionalHideAttribute created by Brecht Lecluyse (www.brechtos.com) | ||
//Modified by: Sebastian Lague | ||
|
||
[CustomPropertyDrawer(typeof(ConditionalHideAttribute))] | ||
public class ConditionalHidePropertyDrawer : PropertyDrawer | ||
{ | ||
|
||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
ConditionalHideAttribute condHAtt = (ConditionalHideAttribute)attribute; | ||
bool enabled = GetConditionalHideAttributeResult(condHAtt, property); | ||
|
||
if (enabled) | ||
{ | ||
EditorGUI.PropertyField(position, property, label, true); | ||
} | ||
} | ||
|
||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | ||
{ | ||
ConditionalHideAttribute condHAtt = (ConditionalHideAttribute)attribute; | ||
bool enabled = GetConditionalHideAttributeResult(condHAtt, property); | ||
|
||
if (enabled) | ||
{ | ||
return EditorGUI.GetPropertyHeight(property, label); | ||
} | ||
//We want to undo the spacing added before and after the property | ||
return -EditorGUIUtility.standardVerticalSpacing; | ||
|
||
} | ||
|
||
bool GetConditionalHideAttributeResult(ConditionalHideAttribute condHAtt, SerializedProperty property) | ||
{ | ||
SerializedProperty sourcePropertyValue = null; | ||
|
||
//Get the full relative property path of the sourcefield so we can have nested hiding.Use old method when dealing with arrays | ||
if (!property.isArray) | ||
{ | ||
string propertyPath = property.propertyPath; //returns the property path of the property we want to apply the attribute to | ||
string conditionPath = propertyPath.Replace(property.name, condHAtt.conditionalSourceField); //changes the path to the conditionalsource property path | ||
sourcePropertyValue = property.serializedObject.FindProperty(conditionPath); | ||
|
||
//if the find failed->fall back to the old system | ||
if (sourcePropertyValue == null) | ||
{ | ||
//original implementation (doens't work with nested serializedObjects) | ||
sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.conditionalSourceField); | ||
} | ||
} | ||
else | ||
{ | ||
//original implementation (doens't work with nested serializedObjects) | ||
sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.conditionalSourceField); | ||
} | ||
|
||
|
||
if (sourcePropertyValue != null) | ||
{ | ||
return CheckPropertyType(condHAtt,sourcePropertyValue); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool CheckPropertyType(ConditionalHideAttribute condHAtt, SerializedProperty sourcePropertyValue) | ||
{ | ||
//Note: add others for custom handling if desired | ||
switch (sourcePropertyValue.propertyType) | ||
{ | ||
case SerializedPropertyType.Boolean: | ||
return sourcePropertyValue.boolValue; | ||
case SerializedPropertyType.Enum: | ||
return sourcePropertyValue.enumValueIndex == condHAtt.enumIndex; | ||
default: | ||
Debug.LogError("Data type of the property used for conditional hiding [" + sourcePropertyValue.propertyType + "] is currently not supported"); | ||
return true; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
[CustomEditor(typeof(Planet))] | ||
public class PlanetEditor : Editor { | ||
|
||
Planet planet; | ||
Editor shapeEditor; | ||
Editor colourEditor; | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
using (var check = new EditorGUI.ChangeCheckScope()) | ||
{ | ||
base.OnInspectorGUI(); | ||
if (check.changed) | ||
{ | ||
planet.GeneratePlanet(); | ||
} | ||
} | ||
|
||
if (GUILayout.Button("Generate Planet")) | ||
{ | ||
planet.GeneratePlanet(); | ||
} | ||
|
||
DrawSettingsEditor(planet.shapeSettings, planet.OnShapeSettingsUpdated, ref planet.shapeSettingsFoldout, ref shapeEditor); | ||
DrawSettingsEditor(planet.colourSettings, planet.OnColourSettingsUpdated, ref planet.colourSettingsFoldout, ref colourEditor); | ||
} | ||
|
||
void DrawSettingsEditor(Object settings, System.Action onSettingsUpdated, ref bool foldout, ref Editor editor) | ||
{ | ||
if (settings != null) | ||
{ | ||
foldout = EditorGUILayout.InspectorTitlebar(foldout, settings); | ||
using (var check = new EditorGUI.ChangeCheckScope()) | ||
{ | ||
if (foldout) | ||
{ | ||
CreateCachedEditor(settings, null, ref editor); | ||
editor.OnInspectorGUI(); | ||
|
||
if (check.changed) | ||
{ | ||
if (onSettingsUpdated != null) | ||
{ | ||
onSettingsUpdated(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void OnEnable() | ||
{ | ||
planet = (Planet)target; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3} | ||
m_Name: ForwardRenderer | ||
m_EditorClassIdentifier: | ||
m_RendererFeatures: [] | ||
m_RendererFeatureMap: | ||
postProcessData: {fileID: 0} | ||
shaders: | ||
blitPS: {fileID: 0} | ||
copyDepthPS: {fileID: 0} | ||
screenSpaceShadowPS: {fileID: 0} | ||
samplingPS: {fileID: 0} | ||
fallbackErrorPS: {fileID: 0} | ||
m_OpaqueLayerMask: | ||
serializedVersion: 2 | ||
m_Bits: 4294967295 | ||
m_TransparentLayerMask: | ||
serializedVersion: 2 | ||
m_Bits: 4294967295 | ||
m_DefaultStencilState: | ||
overrideStencilState: 0 | ||
stencilReference: 0 | ||
stencilCompareFunction: 8 | ||
passOperation: 0 | ||
failOperation: 0 | ||
zFailOperation: 0 | ||
m_ShadowTransparentReceive: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.