diff --git a/Assets/Fungus/Scripts/Commands/SetSprite.cs b/Assets/Fungus/Scripts/Commands/SetSprite.cs new file mode 100644 index 00000000..dc0c08a6 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/SetSprite.cs @@ -0,0 +1,87 @@ +// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). +// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) + +// Snippet added by ducksonthewater, 2019-01-03 - www.ducks-on-the-water.com + +using UnityEngine; +using System.Collections.Generic; + +namespace Fungus +{ + /// + /// Changes the sprite on a SpriteRenderer. + /// + [CommandInfo("Sprite", + "Set Sprite", + "Changes the sprite of a SpriteRenderer.")] + [AddComponentMenu("")] + public class SetSprite : Command + { + [Tooltip("List of sprites to set the sprite property on")] + [SerializeField] protected List targetSprites = new List(); + + [Tooltip("The sprite set on the target sprites")] + [SerializeField] protected Sprite spriteRendererSprite; + + #region Public members + + public override void OnEnter() + { + for (int i = 0; i < targetSprites.Count; i++) + { + var spriteRenderer = targetSprites[i]; + spriteRenderer.sprite = spriteRendererSprite; + } + + Continue(); + } + + public override string GetSummary() + { + string summary = ""; + for (int i = 0; i < targetSprites.Count; i++) + { + var spriteRenderer = targetSprites[i]; + if (spriteRenderer == null) + { + continue; + } + if (summary.Length > 0) + { + summary += ", "; + } + summary += spriteRenderer.name; + } + + if (summary.Length == 0) + { + return "Error: No cursor sprite selected"; + } + + return summary + " = " + spriteRendererSprite; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool IsReorderableArray(string propertyName) + { + if (propertyName == "targetSprites") + { + return true; + } + + return false; + } + + public override void OnCommandAdded(Block parentBlock) + { + // Add a default empty entry + targetSprites.Add(null); + } + + #endregion + } +} diff --git a/Assets/Fungus/Scripts/Commands/SetSprite.cs.meta b/Assets/Fungus/Scripts/Commands/SetSprite.cs.meta new file mode 100644 index 00000000..aa8315a2 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/SetSprite.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8bacd6d8da56644cbb2c9a43f96750c3 +timeCreated: 1439385260 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/SetUIImage.cs b/Assets/Fungus/Scripts/Commands/SetUIImage.cs new file mode 100644 index 00000000..0fbe96dd --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/SetUIImage.cs @@ -0,0 +1,86 @@ +// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). +// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) + +using UnityEngine; +using System.Collections.Generic; +using UnityEngine.UI; + +namespace Fungus +{ + /// + /// Changes the Image on a UI-element. + /// + [CommandInfo("UI", + "Set UI-Image", + "Changes the Image of a UI-Element.")] + [AddComponentMenu("")] + public class SetUIImage : Command + { + [Tooltip("List of UI-objects to set the image property on")] + [SerializeField] protected List targetImages = new List(); + + [Tooltip("The sprite set on the target Image")] + [SerializeField] protected Sprite imageSprite; + + #region Public members + + public override void OnEnter() + { + for (int i = 0; i < targetImages.Count; i++) + { + var targetImage = targetImages[i]; + targetImage.sprite = imageSprite; + } + + Continue(); + } + + public override string GetSummary() + { + string summary = ""; + for (int i = 0; i < targetImages.Count; i++) + { + var targetImage = targetImages[i]; + if (targetImage == null) + { + continue; + } + if (summary.Length > 0) + { + summary += ", "; + } + summary += targetImage.name; + } + + if (summary.Length == 0) + { + return "Error: No cursor sprite selected"; + } + + return summary + " = " + imageSprite; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool IsReorderableArray(string propertyName) + { + if (propertyName == "targetImages") + { + return true; + } + + return false; + } + + public override void OnCommandAdded(Block parentBlock) + { + // Add a default empty entry + targetImages.Add(null); + } + + #endregion + } +} diff --git a/Assets/Fungus/Scripts/Commands/SetUIImage.cs.meta b/Assets/Fungus/Scripts/Commands/SetUIImage.cs.meta new file mode 100644 index 00000000..39b80ddf --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/SetUIImage.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 82e4c082f762243f6943909a4272096d +timeCreated: 1439385260 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: