Chaotic Motion  1.0
SlideshowParticles.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 
6 [RequireComponent(typeof(ChaoticParticles))]
7 [RequireComponent(typeof(ParticleSystem))]
8 public class SlideshowParticles : MonoBehaviour {
9 
11  public int timer = 15;
12 
13  public GameObject cameraBoom;
14  public float spinRate = 0.2f;
15 
16  public Text slideLabel;
17 
18  private float nextSlideTime;
19 
20  private int currentSlide = 0;
21  private int maxSlide;
22  private List<ChaosEqn> eqns;
23  private string[] eqnNames;
24 
25  private ChaoticParticles chaoticParticles;
26  private ParticleSystem particleSys;
27 
28  private Quaternion initialRotation;
29 
30  public float speedTrim = 1.0f;
31 
32  // Use this for initialization
33  void Start () {
34  nextSlideTime = Time.time + timer;
36  maxSlide = eqns.Count;
37  eqnNames = new string[maxSlide];
38  int index = 0;
39  foreach (ChaosEqn eqn in eqns) {
40  eqnNames[index] = eqn.GetName();
41  index++;
42  }
43  chaoticParticles = GetComponent<ChaoticParticles>();
44  chaoticParticles.selectedEqn = currentSlide;
45  slideLabel.text = eqnNames[currentSlide];
46  chaoticParticles.timeZoom = eqns[currentSlide].GetSlideshowSpeed()*speedTrim;
47  chaoticParticles.Init();
48  particleSys = GetComponent<ParticleSystem>();
49 
50  initialRotation = transform.rotation;
51 
52  }
53 
54  // Update is called once per frame
55  void Update () {
56  if (Time.time > nextSlideTime) {
57  nextSlideTime = Time.time + timer;
58  NextSlide(true);
59 
60  } else {
61  if (Time.time < (nextSlideTime - timer/2f)) {
62  cameraBoom.transform.rotation *= Quaternion.AngleAxis( spinRate, Vector3.up);
63  } else {
64  cameraBoom.transform.rotation *= Quaternion.AngleAxis( spinRate, Vector3.right);
65  }
66 
67  }
68  // press "N" for next slide, "P" for previous
69  if (Input.GetKeyUp(KeyCode.N)) {
70  NextSlide(true);
71  } else if (Input.GetKeyUp(KeyCode.P)) {
72  NextSlide(false);
73  }
74 
75  }
76 
77  private void NextSlide(bool advance) {
78  if (advance) {
79  currentSlide++;
80  if (currentSlide >= maxSlide) {
81  currentSlide = 0;
82  }
83  } else {
84  currentSlide--;
85  if (currentSlide < 0) {
86  currentSlide = maxSlide-1;
87  }
88  }
89  Debug.Log(eqnNames[currentSlide]);
90  chaoticParticles.selectedEqn = currentSlide;
91  slideLabel.text = eqnNames[currentSlide];
92  // restart particle system
93  particleSys.Clear();
94  particleSys.Play();
95 
96  // re-center position/camera
97  transform.position = Vector3.zero;
98  cameraBoom.transform.rotation = initialRotation;
99  chaoticParticles.timeZoom = eqns[currentSlide].GetSlideshowSpeed()*speedTrim;
100  chaoticParticles.Init();
101 
102  }
103 }
int timer
Time interval to show each system for.
Chaotic particles.
int selectedEqn
Number of chaos system to evolve (w.r.t. ChaosFactory list)
float timeZoom
Time scale (>0)
Chaos eqn. Base class for all equations that define a 3D chaotic system.
Definition: ChaosEqn.cs:9
static List< ChaosEqn > GetEquations()
Returns a List of Equation objects. A singleton reference list is provided for the inspector script t...
string GetName()
Gets the name.
Definition: ChaosEqn.cs:33