From 1a1f8bca193dc6284a1d15f593409d74ca6c92fc Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 12 Aug 2015 14:54:49 +0100 Subject: [PATCH] Added Set Sprite Order command https://trello.com/c/5yZ88Rh0 --- .../Sprite/Scripts/Commands/SetSpriteOrder.cs | 76 +++++++++++++++++++ .../Scripts/Commands/SetSpriteOrder.cs.meta | 12 +++ 2 files changed, 88 insertions(+) create mode 100644 Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs create mode 100644 Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs.meta diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs b/Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs new file mode 100644 index 00000000..9634b5e8 --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs @@ -0,0 +1,76 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus +{ + [CommandInfo("Sprite", + "Set Sprite Order", + "Controls the render order of sprites by setting the Order In Layer property of a list of sprites.")] + [AddComponentMenu("")] + public class SetSpriteOrder : Command + { + [Tooltip("List of sprites to set the order in layer property on")] + public List targetSprites = new List(); + + [Tooltip("The order in layer value to set on the target sprites")] + public IntegerData orderInLayer; + + public override void OnEnter() + { + foreach (SpriteRenderer spriteRenderer in targetSprites) + { + spriteRenderer.sortingOrder = orderInLayer; + } + + Continue(); + } + + public override string GetSummary() + { + string summary = ""; + foreach (SpriteRenderer spriteRenderer in targetSprites) + { + if (spriteRenderer == null) + { + continue; + } + + if (summary.Length > 0) + { + summary += ", "; + } + + summary += spriteRenderer.name; + } + + if (summary.Length == 0) + { + return "Error: No cursor sprite selected"; + } + + return summary + " = " + orderInLayer.Value; + } + + 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); + } + } +} diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs.meta b/Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs.meta new file mode 100644 index 00000000..c8b1862f --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetSpriteOrder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5d1724bb98f694376b7653fa24a54541 +timeCreated: 1439385260 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: