You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.4 KiB
82 lines
2.4 KiB
8 years ago
|
// 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)
|
||
9 years ago
|
|
||
9 years ago
|
using UnityEngine;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Controls the render order of sprites by setting the Order In Layer property of a list of sprites.
|
||
|
/// </summary>
|
||
8 years ago
|
[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")]
|
||
8 years ago
|
[SerializeField] protected List<SpriteRenderer> targetSprites = new List<SpriteRenderer>();
|
||
9 years ago
|
|
||
8 years ago
|
[Tooltip("The order in layer value to set on the target sprites")]
|
||
8 years ago
|
[SerializeField] protected IntegerData orderInLayer;
|
||
9 years ago
|
|
||
8 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
foreach (SpriteRenderer spriteRenderer in targetSprites)
|
||
|
{
|
||
|
spriteRenderer.sortingOrder = orderInLayer;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
Continue();
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
string summary = "";
|
||
|
foreach (SpriteRenderer spriteRenderer in targetSprites)
|
||
|
{
|
||
|
if (spriteRenderer == null)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if (summary.Length > 0)
|
||
|
{
|
||
|
summary += ", ";
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
summary += spriteRenderer.name;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if (summary.Length == 0)
|
||
|
{
|
||
|
return "Error: No cursor sprite selected";
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
return summary + " = " + orderInLayer.Value;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public override bool IsReorderableArray(string propertyName)
|
||
|
{
|
||
|
if (propertyName == "targetSprites")
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
return false;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public override void OnCommandAdded(Block parentBlock)
|
||
|
{
|
||
|
// Add a default empty entry
|
||
|
targetSprites.Add(null);
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|