Chaotic Motion  1.0
Slideshow.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 
6 [RequireComponent(typeof(ChaoticMotion))]
7 public class Slideshow : MonoBehaviour {
8 
10  public int timer = 15;
11 
12  public GameObject cameraBoom;
13  public float spinRate = 1f;
14 
15  public Text slideLabel;
16 
17  private float nextSlideTime;
18 
19  private int currentSlide = 0;
20  private int maxSlide;
21  private List<ChaosEqn> eqns;
22  private string[] eqnNames;
23 
24  private ChaoticMotion chaoticMotion;
25  private ChaosTrail chaosTrail;
26 
27  private Quaternion initialRotation;
28 
29  // Use this for initialization
30  void Start () {
31  nextSlideTime = Time.time + timer;
33  maxSlide = eqns.Count;
34  eqnNames = new string[maxSlide];
35  int index = 0;
36  foreach (ChaosEqn eqn in eqns) {
37  eqnNames[index] = eqn.GetName();
38  index++;
39  }
40  chaoticMotion = GetComponent<ChaoticMotion>();
41  chaoticMotion.selectedEqn = currentSlide;
42  chaoticMotion.timeZoom = eqns[currentSlide].GetSlideshowSpeed();
43  slideLabel.text = eqnNames[currentSlide];
44  chaoticMotion.Init();
45  // get trail (if present)
46  chaosTrail = GetComponentInChildren<ChaosTrail>();
47 
48  initialRotation = transform.rotation;
49 
50  }
51 
52  // Update is called once per frame
53  void Update () {
54  if (Time.time > nextSlideTime) {
55  nextSlideTime = Time.time + timer;
56  NextSlide(true);
57 
58  } else {
59  if (Time.time < (nextSlideTime - timer/2f)) {
60  cameraBoom.transform.rotation *= Quaternion.AngleAxis( spinRate, Vector3.up);
61  } else {
62  cameraBoom.transform.rotation *= Quaternion.AngleAxis( spinRate, Vector3.right);
63  }
64 
65  }
66  // press "N" for next slide, "P" for previous
67  if (Input.GetKeyUp(KeyCode.N)) {
68  NextSlide(true);
69  } else if (Input.GetKeyUp(KeyCode.P)) {
70  NextSlide(false);
71  }
72 
73  }
74 
75  private void NextSlide(bool advance) {
76  if (advance) {
77  currentSlide++;
78  if (currentSlide >= maxSlide) {
79  currentSlide = 0;
80  }
81  } else {
82  currentSlide--;
83  if (currentSlide < 0) {
84  currentSlide = maxSlide-1;
85  }
86  }
87  Debug.Log(eqnNames[currentSlide]);
88  chaoticMotion.selectedEqn = currentSlide;
89  slideLabel.text = eqnNames[currentSlide];
90  // re-center position/camera
91  transform.position = Vector3.zero;
92  cameraBoom.transform.rotation = initialRotation;
93  chaoticMotion.timeZoom = eqns[currentSlide].GetSlideshowSpeed();
94  chaoticMotion.Init();
95  if (chaosTrail != null) {
96  chaosTrail.Init();
97  }
98 
99  }
100 }
int selectedEqn
Number of chaos system to evolve (w.r.t. ChaosFactory list)
Chaos trail. Update a trail using a LineRenderer. This allows the path between points to be filled in...
Definition: ChaosTrail.cs:14
float timeZoom
Time scale (>0)
int timer
Time interval to show each system for.
Definition: Slideshow.cs:10
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...
Chaotic motion. Evolve the user specified chaotic system with the parameters held by the ChaoticSyste...
override void Init()
Init the equation using the selected equation and parameter bundle.
string GetName()
Gets the name.
Definition: ChaosEqn.cs:33