Skip to content

Instantly share code, notes, and snippets.

@attilam
Created September 15, 2013 09:08
Show Gist options
  • Save attilam/6569069 to your computer and use it in GitHub Desktop.
Save attilam/6569069 to your computer and use it in GitHub Desktop.
Stupid little class to fit all sorts of functionality into one place as possible, to be used in an interactive environment (I'm not proud of it, but pressed on time it's proven very helpful)
using UnityEngine;
using Holoville.HOTween;
[System.Serializable]
public class DynamicEvent {
[System.Serializable]
public class AnimationSetup {
public GameObject gameObject;
public string animation;
}
public AnimationSetup[] animations;
[System.Serializable]
public class TweenObject {
public Transform transform;
public Transform targetTransform;
public float duration = 0.5f;
}
public TweenObject[] tweens;
public GameObject[] objectsToEnable;
public GameObject[] objectsToDisable;
public GameEvent[] gameEvents;
public void Trigger() {
// enable GameObjects
foreach(GameObject go in objectsToEnable) {
go.SetActiveRecursively(true);
}
// start animations
foreach(AnimationSetup ans in animations) {
ans.gameObject.animation.Play(ans.animation);
}
// trigger GameEvents
foreach(GameEvent ge in gameEvents) {
ge.Trigger(null);
}
// disable GameObjects
foreach(GameObject go in objectsToDisable) {
go.SetActiveRecursively(false);
}
// start tweens
foreach(TweenObject to in tweens) {
to.transform.parent = to.targetTransform;
HOTween.Kill(to);
HOTween.To(to.transform, to.duration, new TweenParms()
.Prop("localPosition", Vector3.zero)
.Prop("localRotation", Vector3.zero)
.Prop("localScale", Vector3.one)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment