Browse Source

Added

- SetSprite - changes the image on the SpriteRenderer of one or more GameObjects
- SetUIImage - changes the image on the Image of one or more GameObjects
master
Joerg Burbach 6 years ago
parent
commit
94aae11c30
  1. 87
      Assets/Fungus/Scripts/Commands/SetSprite.cs
  2. 12
      Assets/Fungus/Scripts/Commands/SetSprite.cs.meta
  3. 86
      Assets/Fungus/Scripts/Commands/SetUIImage.cs
  4. 12
      Assets/Fungus/Scripts/Commands/SetUIImage.cs.meta

87
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
{
/// <summary>
/// Changes the sprite on a SpriteRenderer.
/// </summary>
[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<SpriteRenderer> targetSprites = new List<SpriteRenderer>();
[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
}
}

12
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:

86
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
{
/// <summary>
/// Changes the Image on a UI-element.
/// </summary>
[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<Image> targetImages = new List<Image>();
[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
}
}

12
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:
Loading…
Cancel
Save