From a64ef3c67b17b489896da3301f5dd05fd5825abf Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 2 Sep 2015 12:11:27 +0100 Subject: [PATCH] Added Set Sorting Layer command Applies to all Renderers (incl. Mesh & Sprite) --- .../Sprite/Scripts/Commands/SetLayerOrder.cs | 59 +++ .../Scripts/Commands/SetLayerOrder.cs.meta | 12 + Assets/Tests/Sprite/SpriteTests.unity | 501 +++++++++++++++++- 3 files changed, 569 insertions(+), 3 deletions(-) create mode 100644 Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs create mode 100644 Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs.meta diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs b/Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs new file mode 100644 index 00000000..7afe2dc0 --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs @@ -0,0 +1,59 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus +{ + [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")] + public GameObject targetObject; + + [Tooltip("The New Layer Name to apply")] + public string sortingLayer; + + 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(); + if (renderer) + { + renderer.sortingLayerName = layerName; + Debug.Log(target.name); + } + + foreach (Transform child in target.transform) + { + ApplySortingLayer(child, layerName); + } + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs.meta b/Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs.meta new file mode 100644 index 00000000..0087a3bf --- /dev/null +++ b/Assets/Fungus/Sprite/Scripts/Commands/SetLayerOrder.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 673d76133d8494386801a5efa9dd6b7c +timeCreated: 1441190679 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Sprite/SpriteTests.unity b/Assets/Tests/Sprite/SpriteTests.unity index 6cb0741e..a5c80830 100644 --- a/Assets/Tests/Sprite/SpriteTests.unity +++ b/Assets/Tests/Sprite/SpriteTests.unity @@ -141,6 +141,131 @@ SpriteRenderer: m_SortingOrder: 20 m_Sprite: {fileID: 21300000, guid: d568b9f360a9641fba3a3c558cfbd607, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} +--- !u!1 &374044764 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 374044766} + - 212: {fileID: 374044765} + m_Layer: 0 + m_Name: TestSprite1 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &374044765 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 374044764} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0} + m_SubsetIndices: + m_StaticBatchRoot: {fileID: 0} + m_UseLightProbes: 0 + m_ReflectionProbeUsage: 0 + m_ProbeAnchor: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_ImportantGI: 0 + m_AutoUVMaxDistance: .5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 5 + m_Sprite: {fileID: 21300000, guid: d568b9f360a9641fba3a3c558cfbd607, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} +--- !u!4 &374044766 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 374044764} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: .0900000036, y: .150000006, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1440381098} + m_RootOrder: 0 +--- !u!1 &611089088 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 611089089} + - 114: {fileID: 611089090} + - 114: {fileID: 611089091} + m_Layer: 0 + m_Name: TestAssertions + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &611089089 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 611089088} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1440381098} + m_RootOrder: 3 +--- !u!114 &611089090 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 611089088} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8bafa54482a87ac4cbd7ff1bfd1ac93a, type: 3} + m_Name: + m_EditorClassIdentifier: + checkAfterTime: 1 + repeatCheckTime: 0 + repeatEveryTime: 1 + checkAfterFrames: 1 + repeatCheckFrame: 1 + repeatEveryFrame: 1 + hasFailed: 0 + checkMethods: 1 + m_ActionBase: {fileID: 1355988421} + checksPerformed: 0 +--- !u!114 &611089091 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 611089088} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8bafa54482a87ac4cbd7ff1bfd1ac93a, type: 3} + m_Name: + m_EditorClassIdentifier: + checkAfterTime: 1 + repeatCheckTime: 0 + repeatEveryTime: 1 + checkAfterFrames: 1 + repeatCheckFrame: 1 + repeatEveryFrame: 1 + hasFailed: 0 + checkMethods: 1 + m_ActionBase: {fileID: 1472816438} + checksPerformed: 0 --- !u!1 &690569142 GameObject: m_ObjectHideFlags: 0 @@ -195,6 +320,95 @@ SpriteRenderer: m_SortingOrder: 10 m_Sprite: {fileID: 21300000, guid: d568b9f360a9641fba3a3c558cfbd607, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} +--- !u!115 &823098467 +MonoScript: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: + serializedVersion: 4 + m_Script: + m_DefaultReferences: {} + m_Icon: {fileID: 0} + m_ExecutionOrder: 0 + m_ClassName: SetSortingLayer + m_Namespace: Fungus + m_AssemblyName: Assembly-CSharp.dll + m_IsEditorScript: 0 +--- !u!1 &1049233718 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1049233722} + - 114: {fileID: 1049233721} + - 114: {fileID: 1049233720} + - 114: {fileID: 1049233719} + m_Layer: 0 + m_Name: EventSystem + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1049233719 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1049233718} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1997211142, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_AllowActivationOnStandalone: 0 +--- !u!114 &1049233720 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1049233718} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1077351063, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_HorizontalAxis: Horizontal + m_VerticalAxis: Vertical + m_SubmitButton: Submit + m_CancelButton: Cancel + m_InputActionsPerSecond: 10 + m_RepeatDelay: .5 + m_AllowActivationOnMobileDevice: 0 +--- !u!114 &1049233721 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1049233718} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -619905303, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_FirstSelected: {fileID: 0} + m_sendNavigationEvents: 1 + m_DragThreshold: 5 +--- !u!4 &1049233722 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1049233718} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 --- !u!1 &1307141168 GameObject: m_ObjectHideFlags: 0 @@ -237,6 +451,26 @@ MonoBehaviour: sprite1: {fileID: 690569144} sprite2: {fileID: 166866516} sprite3: {fileID: 1364526616} +--- !u!114 &1355988421 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 58783f051e477fd4e93b42ec7a43bb64, type: 3} + m_Name: + m_EditorClassIdentifier: + go: {fileID: 374044764} + thisPropertyPath: SpriteRenderer.sortingLayerName + compareToType: 1 + other: {fileID: 0} + otherPropertyPath: + constantValueGeneric: Top + compareType: 0 + comparisonType: 4 + ignoreCase: 0 --- !u!1 &1364526615 GameObject: m_ObjectHideFlags: 0 @@ -291,6 +525,79 @@ Transform: m_Children: [] m_Father: {fileID: 1918523911} m_RootOrder: 3 +--- !u!1 &1440381097 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1440381098} + - 114: {fileID: 1440381099} + m_Layer: 0 + m_Name: SetLayerOrderTest + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1440381098 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1440381097} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 374044766} + - {fileID: 2027733279} + - {fileID: 2141262452} + - {fileID: 611089089} + m_Father: {fileID: 0} + m_RootOrder: 4 +--- !u!114 &1440381099 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1440381097} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b1dba0b27b0864740a8720e920aa88c0, type: 3} + m_Name: + m_EditorClassIdentifier: + timeout: 5 + ignored: 0 + succeedAfterAllAssertionsAreExecuted: 1 + expectException: 0 + expectedExceptionList: + succeedWhenExceptionIsThrown: 0 + includedPlatforms: -1 + platformsToIgnore: [] + dynamic: 0 + dynamicTypeName: +--- !u!114 &1472816438 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 58783f051e477fd4e93b42ec7a43bb64, type: 3} + m_Name: + m_EditorClassIdentifier: + go: {fileID: 2027733278} + thisPropertyPath: SpriteRenderer.sortingLayerName + compareToType: 1 + other: {fileID: 0} + otherPropertyPath: + constantValueGeneric: Top + compareType: 0 + comparisonType: 4 + ignoreCase: 0 --- !u!1 &1689228821 GameObject: m_ObjectHideFlags: 0 @@ -515,7 +822,6 @@ MonoBehaviour: itemId: 2 errorMessage: indentLevel: 0 - delay: 0 targetObject: {fileID: 1307141168} targetComponentAssemblyName: Fungus.SpritesTest, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null @@ -584,7 +890,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &1918523911 Transform: m_ObjectHideFlags: 0 @@ -623,6 +929,60 @@ MonoBehaviour: platformsToIgnore: [] dynamic: 0 dynamicTypeName: +--- !u!1 &2027733278 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 2027733279} + - 212: {fileID: 2027733280} + m_Layer: 0 + m_Name: TestSprite2 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2027733279 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2027733278} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 1.39999998, y: -.430000007, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1440381098} + m_RootOrder: 1 +--- !u!212 &2027733280 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2027733278} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0} + m_SubsetIndices: + m_StaticBatchRoot: {fileID: 0} + m_UseLightProbes: 0 + m_ReflectionProbeUsage: 0 + m_ProbeAnchor: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_ImportantGI: 0 + m_AutoUVMaxDistance: .5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: d568b9f360a9641fba3a3c558cfbd607, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} --- !u!1 &2126790765 GameObject: m_ObjectHideFlags: 1 @@ -650,7 +1010,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 61dddfdc5e0e44ca298d8f46f7f5a915, type: 3} m_Name: m_EditorClassIdentifier: - selectedFlowchart: {fileID: 1766220887} + selectedFlowchart: {fileID: 2141262458} --- !u!4 &2126790767 Transform: m_ObjectHideFlags: 1 @@ -663,3 +1023,138 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 +--- !u!1 &2141262451 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 142980, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 2141262452} + - 114: {fileID: 2141262458} + - 114: {fileID: 2141262457} + - 114: {fileID: 2141262455} + - 114: {fileID: 2141262454} + - 114: {fileID: 2141262453} + m_Layer: 0 + m_Name: Flowchart + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2141262452 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 467082, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2141262451} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1440381098} + m_RootOrder: 2 +--- !u!114 &2141262453 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2141262451} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 823098467} + m_Name: + m_EditorClassIdentifier: + itemId: 2 + errorMessage: + indentLevel: 0 + targetObject: {fileID: 2027733278} + sortingLayer: Top +--- !u!114 &2141262454 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2141262451} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 823098467} + m_Name: + m_EditorClassIdentifier: + itemId: 1 + errorMessage: + indentLevel: 0 + targetObject: {fileID: 374044764} + sortingLayer: Top +--- !u!114 &2141262455 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2141262451} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3} + m_Name: + m_EditorClassIdentifier: + parentBlock: {fileID: 2141262457} +--- !u!114 &2141262457 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 11433304, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2141262451} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3} + m_Name: + m_EditorClassIdentifier: + nodeRect: + serializedVersion: 2 + x: 68 + y: 68 + width: 120 + height: 40 + itemId: 0 + blockName: Start + description: + eventHandler: {fileID: 2141262455} + commandList: + - {fileID: 2141262454} + - {fileID: 2141262453} +--- !u!114 &2141262458 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 11430050, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2141262451} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 1.0 + scrollPos: {x: 0, y: 0} + variablesScrollPos: {x: 0, y: 0} + variablesExpanded: 1 + blockViewHeight: 400 + zoom: 1 + scrollViewRect: + serializedVersion: 2 + x: -343 + y: -340 + width: 1114 + height: 859 + selectedBlock: {fileID: 2141262457} + selectedCommands: + - {fileID: 2141262454} + variables: [] + description: + stepPause: 0 + colorCommands: 1 + hideComponents: 1 + saveSelection: 1 + localizationId: