-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
119 deletions.
There are no files selected for viewing
160 changes: 80 additions & 80 deletions
160
PersistantEmitterManager.cs → PersistentEmitterManager.cs
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 |
---|---|---|
@@ -1,80 +1,80 @@ | ||
/* | ||
* Author: Sébastien GAGGINI AKA Sarbian, France | ||
* License: Attribution 4.0 International (CC BY 4.0): http://creativecommons.org/licenses/by/4.0/ | ||
* | ||
* Thanks to Nothke for all the feature ideas, testing and feedback | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
|
||
[KSPAddon(KSPAddon.Startup.EveryScene, false)] | ||
class PersistentEmitterManager : MonoBehaviour | ||
{ | ||
|
||
public static PersistentEmitterManager Instance { get; private set; } | ||
|
||
private static List<PersistentKSPParticleEmitter> persistentEmitters; | ||
|
||
|
||
private void Awake() | ||
{ | ||
PersistentEmitterManager.Instance = this; | ||
|
||
persistentEmitters = new List<PersistentKSPParticleEmitter>(); | ||
|
||
GameEvents.onGameSceneLoadRequested.Add(new EventData<GameScenes>.OnEvent(this.OnSceneChange)); | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
GameEvents.onGameSceneLoadRequested.Remove(new EventData<GameScenes>.OnEvent(this.OnSceneChange)); | ||
} | ||
|
||
static public void Add(PersistentKSPParticleEmitter pkpe) | ||
{ | ||
persistentEmitters.Add(pkpe); | ||
EffectBehaviour.AddParticleEmitter(pkpe.pe); | ||
} | ||
|
||
private void OnSceneChange(GameScenes scene) | ||
{ | ||
for (int i = 0; i < persistentEmitters.Count; i++) | ||
{ | ||
EffectBehaviour.RemoveParticleEmitter(persistentEmitters[i].pe); | ||
if (persistentEmitters[i].go.transform.parent == null) | ||
Destroy(persistentEmitters[i].go); | ||
} | ||
persistentEmitters = new List<PersistentKSPParticleEmitter>(); | ||
} | ||
|
||
|
||
void FixedUpdate() | ||
{ | ||
List<PersistentKSPParticleEmitter> persistentEmittersCopy = new List<PersistentKSPParticleEmitter>(persistentEmitters); | ||
for (int i = 0; i < persistentEmittersCopy.Count; i++) | ||
{ | ||
if (persistentEmittersCopy[i].go.transform.parent == null && persistentEmittersCopy[i].pe.pe.particles.Count() == 0) | ||
{ | ||
EffectBehaviour.RemoveParticleEmitter(persistentEmittersCopy[i].pe); | ||
persistentEmitters.Remove(persistentEmittersCopy[i]); | ||
Destroy(persistentEmittersCopy[i].go); | ||
} | ||
} | ||
|
||
} | ||
|
||
private void print(String s) | ||
{ | ||
MonoBehaviour.print(this.GetType().Name + " : " + s); | ||
} | ||
|
||
|
||
} | ||
|
||
/* | ||
* Author: Sébastien GAGGINI AKA Sarbian, France | ||
* License: Attribution 4.0 International (CC BY 4.0): http://creativecommons.org/licenses/by/4.0/ | ||
* | ||
* Thanks to Nothke for all the feature ideas, testing and feedback | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
|
||
[KSPAddon(KSPAddon.Startup.EveryScene, false)] | ||
class PersistentEmitterManager : MonoBehaviour | ||
{ | ||
|
||
public static PersistentEmitterManager Instance { get; private set; } | ||
|
||
private static List<PersistentKSPParticleEmitter> persistentEmitters; | ||
|
||
|
||
private void Awake() | ||
{ | ||
PersistentEmitterManager.Instance = this; | ||
|
||
persistentEmitters = new List<PersistentKSPParticleEmitter>(); | ||
|
||
GameEvents.onGameSceneLoadRequested.Add(new EventData<GameScenes>.OnEvent(this.OnSceneChange)); | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
GameEvents.onGameSceneLoadRequested.Remove(new EventData<GameScenes>.OnEvent(this.OnSceneChange)); | ||
} | ||
|
||
static public void Add(PersistentKSPParticleEmitter pkpe) | ||
{ | ||
persistentEmitters.Add(pkpe); | ||
EffectBehaviour.AddParticleEmitter(pkpe.pe); | ||
} | ||
|
||
private void OnSceneChange(GameScenes scene) | ||
{ | ||
for (int i = 0; i < persistentEmitters.Count; i++) | ||
{ | ||
EffectBehaviour.RemoveParticleEmitter(persistentEmitters[i].pe); | ||
if (persistentEmitters[i].go.transform.parent == null) | ||
Destroy(persistentEmitters[i].go); | ||
} | ||
persistentEmitters = new List<PersistentKSPParticleEmitter>(); | ||
} | ||
|
||
|
||
void FixedUpdate() | ||
{ | ||
List<PersistentKSPParticleEmitter> persistentEmittersCopy = new List<PersistentKSPParticleEmitter>(persistentEmitters); | ||
for (int i = 0; i < persistentEmittersCopy.Count; i++) | ||
{ | ||
if (persistentEmittersCopy[i].go.transform.parent == null && persistentEmittersCopy[i].pe.pe.particles.Count() == 0) | ||
{ | ||
EffectBehaviour.RemoveParticleEmitter(persistentEmittersCopy[i].pe); | ||
persistentEmitters.Remove(persistentEmittersCopy[i]); | ||
Destroy(persistentEmittersCopy[i].go); | ||
} | ||
} | ||
|
||
} | ||
|
||
private void print(String s) | ||
{ | ||
MonoBehaviour.print(this.GetType().Name + " : " + s); | ||
} | ||
|
||
|
||
} | ||
|
||
|
78 changes: 39 additions & 39 deletions
78
PersistantKSPParticleEmitter.cs → PersistentKSPParticleEmitter.cs
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 |
---|---|---|
@@ -1,39 +1,39 @@ | ||
/* | ||
* Author: Sébastien GAGGINI AKA Sarbian, France | ||
* License: Attribution 4.0 International (CC BY 4.0): http://creativecommons.org/licenses/by/4.0/ | ||
* | ||
* Thanks to Nothke for all the feature ideas, testing and feedback | ||
* | ||
*/ | ||
|
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
|
||
// TODO : handle the relation with PersistentEmitterManager inside the class | ||
public class PersistentKSPParticleEmitter | ||
{ | ||
public GameObject go; | ||
public KSPParticleEmitter pe; | ||
public bool fixedEmit = false; | ||
public float baseMaxSize; | ||
|
||
public PersistentKSPParticleEmitter(GameObject go, KSPParticleEmitter pe, float ms) | ||
{ | ||
this.go = go; | ||
this.pe = pe; | ||
baseMaxSize = ms; | ||
} | ||
|
||
public PersistentKSPParticleEmitter(GameObject go, KSPParticleEmitter pe) | ||
{ | ||
this.go = go; | ||
this.pe = pe; | ||
this.baseMaxSize = 1; | ||
} | ||
|
||
} | ||
/* | ||
* Author: Sébastien GAGGINI AKA Sarbian, France | ||
* License: Attribution 4.0 International (CC BY 4.0): http://creativecommons.org/licenses/by/4.0/ | ||
* | ||
* Thanks to Nothke for all the feature ideas, testing and feedback | ||
* | ||
*/ | ||
|
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
|
||
// TODO : handle the relation with PersistentEmitterManager inside the class | ||
public class PersistentKSPParticleEmitter | ||
{ | ||
public GameObject go; | ||
public KSPParticleEmitter pe; | ||
public bool fixedEmit = false; | ||
public float baseMaxSize; | ||
|
||
public PersistentKSPParticleEmitter(GameObject go, KSPParticleEmitter pe, float ms) | ||
{ | ||
this.go = go; | ||
this.pe = pe; | ||
baseMaxSize = ms; | ||
} | ||
|
||
public PersistentKSPParticleEmitter(GameObject go, KSPParticleEmitter pe) | ||
{ | ||
this.go = go; | ||
this.pe = pe; | ||
this.baseMaxSize = 1; | ||
} | ||
|
||
} |