Node CreateNode(AnimationPattern ap) { Node foundNode = nodes.Find((other) => { return(other.ap == ap); }); if (foundNode != null) { sc.SelectController(containingAtom.mainController); return(foundNode); } Node node = new Node(ui, ap); //ap.containingAtom.SetOn(false); ap.SetBoolParamValue("on", false); ap.Pause(); ap.ResetAnimation(); lineMaterial = ap.rootLineDrawerMaterial; if (nodes.Contains(node) == false) { nodes.Add(node); } node.connectButton.button.onClick.AddListener(() => { sc.SelectModeAtom((atom) => { if (atom == ap.containingAtom) { SuperController.LogError("Can't make a connection to itself."); return; } AnimationPattern childAP = atom.GetStorableByID("AnimationPattern") as AnimationPattern; if (childAP == null) { SuperController.LogError("Only Animation Patterns can be selected."); return; } Node childNode = CreateNode(childAP); Transition transition = CreateTransition(node.atom, childNode.atom); if (transition != null) { node.transitions.Add(transition); PerformSave(); } }); }); node.disconnectButton.button.onClick.AddListener(() => { node.transitions.ForEach((t) => { t.OnDestroy(); transitions.Remove(t); }); node.transitions.Clear(); }); sc.SelectController(containingAtom.mainController); return(node); }
public override void Init() { try { sc = SuperController.singleton; ui = new UI(this, 0.001f); ui.canvas.transform.SetParent(containingAtom.mainController.transform, false); UIDynamicButton entrySelector = ui.CreateButton("Select Entry"); entrySelector.transform.Translate(0, 0.1f, 0); entrySelector.button.onClick.AddListener(() => { sc.SelectModeAtom((atom) => { AnimationPattern ap = atom.GetStorableByID("AnimationPattern") as AnimationPattern; if (ap == null) { SuperController.LogError("Only Animation Patterns can be selected."); return; } root = CreateNode(ap); CreateTransition(containingAtom, root.atom); active = root; entrySelector.gameObject.SetActive(false); PerformSave(); }); }); UIDynamicButton playButton = ui.CreateButton("Test Start", 80, 60); playButton.transform.Translate(0, -0.2f, 0); playButton.button.onClick.AddListener(() => { if (root == null) { return; } active = root; active.Start(); }); UIDynamicButton nextButton = ui.CreateButton("Test Next", 80, 60); nextButton.transform.Translate(0, -0.3f, 0); nextButton.button.onClick.AddListener(() => { if (active == null) { return; } Transition transition = active.GetRandomTransition(); if (transition != null) { Node nextNode = GetEndNodeFromTransition(transition); if (nextNode != null) { active.Stop(); nextNode.Start(); active = nextNode; } } }); UIDynamicButton doneEditingButton = ui.CreateButton("Done Editing", 80, 60); doneEditingButton.transform.Translate(0, -0.6f, 0); doneEditingButton.button.onClick.AddListener(() => { ui.canvas.enabled = false; if (sc.GetSelectedAtom() == containingAtom) { sc.ClearSelection(); } }); saveString = new JSONStorableString("graph", ""); RegisterString(saveString); playNextWhenReady = new JSONStorableAction("play next if ready", () => { if (active == null) { return; } if (started == false) { active.Start(); started = true; return; } if (active.ap.loop == false) { if (active.ap.GetCurrentTimeCounter() < active.ap.GetTotalTime()) { return; } } Transition transition = active.GetRandomTransition(); if (transition != null) { Node nextNode = GetEndNodeFromTransition(transition); if (nextNode != null) { active.Stop(); nextNode.Start(); active = nextNode; } } }); RegisterAction(playNextWhenReady); } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } }