public void FireRandomLightning() { if (lightning.Length == 0) { return; } Lightning l = lightning[Random.Range(0, lightning.Length)]; if (l == null) { Debug.LogWarning("Lightning is unassigned", this); return; } l.DoLightning(); }
private bool ParseAction(string value) { value = value.Trim('.', '\n', ' '); string[] colonSplit = value.Split(':'); if (string.Equals(colonSplit[0], "audio", StringComparison.OrdinalIgnoreCase)) { string[] commandSplit = colonSplit[1].Trim(' ').Split(' '); if (commandSplit.Length > 1) { List <InkAudioLink> audioLinkList = new List <InkAudioLink>(); InkAudioLink[] audioLinks = FindObjectsOfType <InkAudioLink>(); foreach (InkAudioLink inkAudioLink in audioLinks) { if (string.Equals(commandSplit[1], inkAudioLink.Key, StringComparison.OrdinalIgnoreCase)) { audioLinkList.Add(inkAudioLink); } } foreach (InkAudioLink inkAudioLink in audioLinkList) { if (string.Equals(commandSplit[0], "play", StringComparison.OrdinalIgnoreCase)) { float delayTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out delayTime); } Debug.LogFormat("Playing audio: {0} with delay of {1}", commandSplit[0], delayTime); if (delayTime > 0) { inkAudioLink.AudioSource.PlayDelayed(delayTime); } else { inkAudioLink.AudioSource.Play(); } } else if (string.Equals(commandSplit[0], "fadeup", StringComparison.OrdinalIgnoreCase)) { float fadeTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out fadeTime); } LeanTween.value(inkAudioLink.gameObject, v => inkAudioLink.AudioSource.volume = v, 0.0f, 1.0f, fadeTime).tweenType = LeanTweenType.easeInOutCubic; } else if (string.Equals(commandSplit[0], "fadedown", StringComparison.OrdinalIgnoreCase)) { float fadeTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out fadeTime); } LeanTween.value(inkAudioLink.gameObject, v => inkAudioLink.AudioSource.volume = v, inkAudioLink.AudioSource.volume, 0.0f, fadeTime).tweenType = LeanTweenType.easeInOutCubic; } } } return(true); } if (string.Equals(colonSplit[0], "visual", StringComparison.OrdinalIgnoreCase)) { string[] commandSplit = colonSplit[1].Trim(' ').Split(' '); if (commandSplit.Length > 0) { if (string.Equals(commandSplit[0], "fadein", StringComparison.OrdinalIgnoreCase)) { float fadeTime = 0.0f; if (commandSplit.Length > 1) { float.TryParse(commandSplit[1], out fadeTime); } StorySceneManager.Instance.FadeIn(fadeTime); } else if (string.Equals(commandSplit[0], "fadeout", StringComparison.OrdinalIgnoreCase)) { float fadeTime = 0.0f; if (commandSplit.Length > 1) { float.TryParse(commandSplit[1], out fadeTime); } Color fadeColor = Color.black; if (commandSplit.Length > 2) { if (string.Equals(commandSplit[2], "white", StringComparison.OrdinalIgnoreCase)) { fadeColor = Color.white; } } StorySceneManager.Instance.FadeOut(fadeTime, fadeColor); } else if (string.Equals(commandSplit[0], "trigger")) { if (string.Equals(commandSplit[1], "lightning", StringComparison.OrdinalIgnoreCase)) { Lightning[] lightnings = FindObjectsOfType <Lightning>(); if (lightnings.Length > 0) { Lightning lightning = lightnings[UnityEngine.Random.Range(0, lightnings.Length)]; float delayTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out delayTime); } if (delayTime > 0) { lightning.Invoke("DoLightning", delayTime); } else { lightning.DoLightning(); } } } else if (string.Equals(commandSplit[1], "explosion", StringComparison.OrdinalIgnoreCase)) { float delayTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out delayTime); } Explosion[] explosions = FindObjectsOfType <Explosion>(); foreach (Explosion explosion in explosions) { if (delayTime > 0) { explosion.Invoke("DoExplosion", delayTime); } else { explosion.DoExplosion(); } } } } else if (string.Equals(commandSplit[0], "animate", StringComparison.OrdinalIgnoreCase)) { List <InkVisualLink> visualLinkList = GetVisualLinks(commandSplit[1]); foreach (InkVisualLink inkVisualLink in visualLinkList) { if (commandSplit.Length > 2) { float delayTime = 0.0f; if (commandSplit.Length > 3) { float.TryParse(commandSplit[3], out delayTime); } inkVisualLink.Animate(commandSplit[2], delayTime); } } } else if (string.Equals(commandSplit[0], "show", StringComparison.OrdinalIgnoreCase)) { List <InkVisualLink> visualLinkList = GetVisualLinks(commandSplit[1]); foreach (InkVisualLink inkVisualLink in visualLinkList) { float fadeTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out fadeTime); } inkVisualLink.Show(fadeTime); } } else if (string.Equals(commandSplit[0], "hide", StringComparison.OrdinalIgnoreCase)) { List <InkVisualLink> visualLinkList = GetVisualLinks(commandSplit[1]); foreach (InkVisualLink inkVisualLink in visualLinkList) { float fadeTime = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out fadeTime); } inkVisualLink.Hide(fadeTime); } } } return(true); } if (string.Equals(colonSplit[0], "scene", StringComparison.OrdinalIgnoreCase)) { string[] commandSplit = colonSplit[1].Trim(' ').Split(' '); if (commandSplit.Length > 1) { if (string.Equals(commandSplit[0], "load", StringComparison.OrdinalIgnoreCase)) { float delay = 0.0f; if (commandSplit.Length > 2) { float.TryParse(commandSplit[2], out delay); } int sceneNumber; if (int.TryParse(commandSplit[1], out sceneNumber)) { StorySceneManager.Instance.LoadScene(sceneNumber, delay); } else { Debug.LogWarningFormat("Couldn't parse '{0}' - couldn't parse int for {1}", value, commandSplit[1]); } } else { Debug.LogWarningFormat("Couldn't parse '{0}' - parse command for {1}", value, commandSplit[0]); } } else { Debug.LogWarningFormat("Couldn't parse '{0}' - not enough commands", value); } return(true); } if (string.Equals(colonSplit[0], "delay", StringComparison.OrdinalIgnoreCase)) { float delayTime = 0.0f; if (colonSplit.Length > 1) { float.TryParse(colonSplit[1], out delayTime); } _delayBeforeNextLine = delayTime; return(true); } return(false); }