-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ChrisAdderley/dev
Release 0.2.2
- Loading branch information
Showing
14 changed files
with
450 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
{ | ||
"MAJOR":0, | ||
"MINOR":2, | ||
"PATCH":1, | ||
"PATCH":2, | ||
"BUILD":0 | ||
}, | ||
"KSP_VERSION": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
using UnityEngine.Experimental.PlayerLoop; | ||
|
||
namespace Waterfall.Modules | ||
{ | ||
public class ModuleWaterfallSmoke : PartModule | ||
{ | ||
|
||
// This links to an EngineID from a ModuleEnginesFX | ||
[KSPField(isPersistant = false)] | ||
public string waterfallModuleID = ""; | ||
|
||
// This links to an EngineID from a ModuleEnginesFX | ||
[KSPField(isPersistant = false)] | ||
public string smokeTransformName = ""; | ||
|
||
// This links to an EngineID from a ModuleEnginesFX | ||
[KSPField(isPersistant = false)] | ||
public string smokePrefabName = "WaterfallSmokeProto"; | ||
|
||
// Map speed to emission | ||
[KSPField(isPersistant = false)] | ||
public FloatCurve SpeedEmissionScaleCurve = new FloatCurve(); | ||
|
||
[KSPField(isPersistant = false)] | ||
public FloatCurve SpeedLifetimeScaleCurve = new FloatCurve(); | ||
|
||
[KSPField(isPersistant = false)] | ||
public FloatCurve AtmoSizeScaleCurve = new FloatCurve(); | ||
|
||
[KSPField(isPersistant = false)] | ||
public FloatCurve AtmoAlphaFadeCurve = new FloatCurve(); | ||
|
||
[KSPField(isPersistant = false)] | ||
public Vector2 emissionRateRange; | ||
|
||
[KSPField(isPersistant = false)] | ||
public Vector2 emissionSpeedRange; | ||
|
||
[KSPField(isPersistant = false)] | ||
public Vector2 startSizeRange; | ||
|
||
[KSPField(isPersistant = false)] | ||
public Vector2 lifetimeRange; | ||
|
||
List<WaterfallSmokeEmitter> emitters; | ||
|
||
public void Start() | ||
{ | ||
if (HighLogic.LoadedSceneIsFlight) | ||
{ | ||
InstantiateEffect(); | ||
} | ||
|
||
} | ||
|
||
public void InstantiateEffect() | ||
{ | ||
emitters = new List<WaterfallSmokeEmitter>(); | ||
if (smokeTransformName != "") | ||
{ | ||
foreach (Transform t in part.FindModelTransforms(smokeTransformName)) | ||
{ | ||
|
||
emitters.Add(new WaterfallSmokeEmitter(smokePrefabName, t)); | ||
} | ||
} | ||
else | ||
emitters.Add(new WaterfallSmokeEmitter(smokePrefabName, part.transform)); | ||
|
||
} | ||
public void SetRanges( | ||
Vector2 emissionRangeNew, | ||
Vector2 speedRangeNew, | ||
Vector2 sizeRangeNew, | ||
Vector2 lifetimeRangeNew) | ||
{ | ||
emissionRateRange = emissionRangeNew; | ||
emissionSpeedRange = speedRangeNew; | ||
startSizeRange = sizeRangeNew; | ||
lifetimeRange = lifetimeRangeNew; | ||
} | ||
protected void SetParticles() | ||
{ | ||
float srfSpeed = (float)part.vessel.srfSpeed; | ||
float pressureAtm = (float)vessel.mainBody.GetPressureAtm(part.vessel.altitude); | ||
for (int i = 0; i < emitters.Count; i++) | ||
{ | ||
emitters[i].Set( | ||
emissionRateRange * SpeedEmissionScaleCurve.Evaluate(srfSpeed), | ||
emissionSpeedRange, | ||
startSizeRange * AtmoSizeScaleCurve.Evaluate(pressureAtm), | ||
lifetimeRange * SpeedLifetimeScaleCurve.Evaluate(srfSpeed), | ||
AtmoAlphaFadeCurve.Evaluate(pressureAtm)); | ||
} | ||
} | ||
|
||
public void FixedUpdate() | ||
{ | ||
|
||
if (HighLogic.LoadedSceneIsFlight && emitters != null) | ||
{ | ||
SetParticles(); | ||
for (int i = 0; i < emitters.Count; i++) | ||
{ | ||
emitters[i].Update(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class WaterfallSmokeEmitter | ||
{ | ||
private string prefab; | ||
private Transform parent; | ||
private ParticleSystem emitter; | ||
private ParticleSystemRenderer renderer; | ||
|
||
private static ParticleSystem.Particle[] particles; | ||
|
||
public WaterfallSmokeEmitter(string prefabName, Transform parentTransform) | ||
{ | ||
prefab = prefabName; | ||
parent = parentTransform; | ||
GameObject go = GameObject.Instantiate(WaterfallParticleLoader.GetParticles(prefabName), Vector3.zero, Quaternion.identity) as GameObject; | ||
|
||
emitter = go.GetComponent<ParticleSystem>(); | ||
renderer = go.GetComponent<ParticleSystemRenderer>(); | ||
go.transform.SetParent(parentTransform); | ||
go.transform.localPosition = Vector3.zero; | ||
go.transform.localScale = Vector3.one; | ||
go.transform.localRotation = Quaternion.identity; | ||
|
||
FloatingOrigin.RegisterParticleSystem(emitter); | ||
} | ||
|
||
public void Update() | ||
{ | ||
//if (particles == null || emitter.main.maxParticles > particles.Length) | ||
// particles = new ParticleSystem.Particle[emitter.main.maxParticles]; | ||
|
||
//int numParticlesAlive = emitter.GetParticles(particles); | ||
|
||
//for (int j = 0; j < numParticlesAlive; j++) | ||
//{ | ||
// //particles[j].v Krakensbane.GetFrameVelocity | ||
//} | ||
} | ||
|
||
public void Set( | ||
Vector2 emissionRange, | ||
Vector2 speedRange, | ||
Vector2 sizeRange, | ||
Vector2 lifetimeRange, | ||
float fade | ||
) | ||
{ | ||
var main = emitter.main; | ||
main.startSpeed = new ParticleSystem.MinMaxCurve(speedRange.x, speedRange.y); | ||
main.startSize = new ParticleSystem.MinMaxCurve(sizeRange.x, sizeRange.y); | ||
main.startLifetime = new ParticleSystem.MinMaxCurve(lifetimeRange.x, lifetimeRange.y); | ||
|
||
var emit = emitter.emission; | ||
emit.rateOverTime = new ParticleSystem.MinMaxCurve(emissionRange.x, emissionRange.y); | ||
|
||
var color = emitter.colorOverLifetime; | ||
|
||
Gradient grad = color.color.gradient; | ||
grad.SetKeys(grad.colorKeys, new GradientAlphaKey[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(fade * 1f, 0.01f), new GradientAlphaKey(fade * 0.3f, 0.5f), new GradientAlphaKey(0f, 1f) }); | ||
color.color = new ParticleSystem.MinMaxGradient(grad); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ public UIPopupWindow(bool show) | |
Utils.Log("[UI]: Start fired"); | ||
showWindow = show; | ||
|
||
|
||
} | ||
|
||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
using Waterfall.Modules; | ||
|
||
namespace Waterfall.UI | ||
{ | ||
public class UISmokeEditWindow : UIPopupWindow | ||
{ | ||
|
||
|
||
protected string windowTitle = ""; | ||
|
||
Vector2 startSizeRange; | ||
string[] startSizeRangeString; | ||
Vector2 lifetimeRange; | ||
string[] lifetimeRangeString; | ||
Vector2 emissionRateRange; | ||
string[] emissionRateRangeString; | ||
Vector2 emissionSpeedRange; | ||
string[] emissionSpeedRangeString; | ||
|
||
ModuleWaterfallSmoke smokeModule; | ||
|
||
public UISmokeEditWindow(ModuleWaterfallSmoke smoke, bool show) : base(show) | ||
{ | ||
smokeModule = smoke; | ||
Utils.Log($"[UISmokeEditWindoww]: Started editing smoke on {true.ToString()}", LogType.UI); | ||
|
||
startSizeRange = smoke.startSizeRange; | ||
emissionRateRange = smoke.emissionRateRange; | ||
emissionSpeedRange = smoke.emissionSpeedRange; | ||
lifetimeRange = smoke.lifetimeRange; | ||
|
||
startSizeRangeString = new string[] {startSizeRange.x.ToString(), startSizeRange.y.ToString() }; | ||
emissionRateRangeString = new string[] { emissionRateRange.x.ToString(), emissionRateRange.y.ToString() }; | ||
emissionSpeedRangeString = new string[] { emissionSpeedRange.x.ToString(), emissionSpeedRange.y.ToString() }; | ||
lifetimeRangeString = new string[] { lifetimeRange.x.ToString(), lifetimeRange.y.ToString() }; | ||
|
||
WindowPosition = new Rect(Screen.width / 2 - 200, Screen.height / 2f, 400, 100); | ||
} | ||
|
||
protected override void InitUI() | ||
{ | ||
windowTitle = "Smoke Editor"; | ||
base.InitUI(); | ||
|
||
|
||
} | ||
public void Update() | ||
{ | ||
|
||
if (smokeModule) | ||
{ | ||
if (smokeModule.startSizeRange != startSizeRange || | ||
smokeModule.emissionRateRange != emissionRateRange || | ||
smokeModule.emissionSpeedRange != emissionSpeedRange || | ||
smokeModule.lifetimeRange != lifetimeRange) | ||
{ | ||
// Utils.Log(string.Format("{0} {1} {2} {3}", emissionRateRange, emissionSpeedRange, startSizeRange, lifetimeRange)); | ||
smokeModule.SetRanges( | ||
emissionRateRange, emissionSpeedRange, startSizeRange, lifetimeRange); | ||
} | ||
} | ||
} | ||
|
||
protected override void DrawWindow(int windowId) | ||
{ | ||
DrawTitle(); | ||
DrawEditor(); | ||
GUI.DragWindow(); | ||
} | ||
|
||
|
||
protected void DrawTitle() | ||
{ | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Label(windowTitle, GUIResources.GetStyle("window_header"), GUILayout.MaxHeight(26f), GUILayout.MinHeight(26f)); | ||
|
||
GUILayout.FlexibleSpace(); | ||
|
||
Rect buttonRect = GUILayoutUtility.GetRect(22f, 22f); | ||
GUI.color = resources.GetColor("cancel_color"); | ||
if (GUI.Button(buttonRect, "", GUIResources.GetStyle("button_cancel"))) | ||
{ | ||
ToggleWindow(); | ||
} | ||
|
||
GUI.DrawTextureWithTexCoords(buttonRect, GUIResources.GetIcon("cancel").iconAtlas, GUIResources.GetIcon("cancel").iconRect); | ||
GUI.color = Color.white; | ||
GUILayout.EndHorizontal(); | ||
} | ||
|
||
protected void DrawEditor() | ||
{ | ||
|
||
bool delta = false; | ||
|
||
GUILayout.BeginVertical(GUILayout.MaxWidth(400f)); | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Label("Start Size"); | ||
startSizeRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), startSizeRange, startSizeRangeString, GUI.skin.label, GUI.skin.textArea, out delta); | ||
GUILayout.EndHorizontal(); | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Label("Emission Rate"); | ||
emissionRateRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), emissionRateRange, emissionRateRangeString, GUI.skin.label, GUI.skin.textArea, out delta); | ||
GUILayout.EndHorizontal(); | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Label("Emission Speed"); | ||
emissionSpeedRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), emissionSpeedRange, emissionSpeedRangeString, GUI.skin.label, GUI.skin.textArea, out delta); | ||
GUILayout.EndHorizontal(); | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Label("Lifetime Range"); | ||
lifetimeRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), lifetimeRange, lifetimeRangeString, GUI.skin.label, GUI.skin.textArea, out delta); | ||
GUILayout.EndHorizontal(); | ||
|
||
GUILayout.EndVertical(); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.