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.
63 lines
2.1 KiB
63 lines
2.1 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;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Sets the Renderer sorting layer of every child of a game object. Applies to all Renderers (including mesh, skinned mesh, and sprite).
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Sprite",
|
||
|
"Set Sorting Layer",
|
||
|
"Sets the Renderer sorting layer of every child of a game object. Applies to all Renderers (including mesh, skinned mesh, and sprite).")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class SetSortingLayer : Command
|
||
|
{
|
||
|
[Tooltip("Root Object that will have the Sorting Layer set. Any children will also be affected")]
|
||
8 years ago
|
[SerializeField] protected GameObject targetObject;
|
||
8 years ago
|
|
||
|
[Tooltip("The New Layer Name to apply")]
|
||
8 years ago
|
[SerializeField] protected string sortingLayer;
|
||
8 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
if (targetObject != null)
|
||
|
{
|
||
|
ApplySortingLayer(targetObject.transform, sortingLayer);
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
if (targetObject == null)
|
||
|
{
|
||
|
return "Error: No game object selected";
|
||
|
}
|
||
|
|
||
|
return targetObject.name;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
|
|
||
|
protected void ApplySortingLayer(Transform target, string layerName)
|
||
|
{
|
||
|
Renderer renderer = target.gameObject.GetComponent<Renderer>();
|
||
|
if (renderer)
|
||
|
{
|
||
|
renderer.sortingLayerName = layerName;
|
||
|
Debug.Log(target.name);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
foreach (Transform child in target.transform)
|
||
|
{
|
||
|
ApplySortingLayer(child, layerName);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|