Browse Source

Converted all foreach statement to act on simple variables.

master
Christopher 8 years ago
parent
commit
3510fc7f9a
  1. 4
      Assets/Fungus/Scripts/Commands/ControlAudio.cs
  2. 6
      Assets/Fungus/Scripts/Commands/ControlStage.cs
  3. 93
      Assets/Fungus/Scripts/Commands/FadeUI.cs
  4. 3
      Assets/Fungus/Scripts/Commands/Jump.cs
  5. 3
      Assets/Fungus/Scripts/Commands/Say.cs
  6. 2
      Assets/Fungus/Scripts/Commands/SendMessage.cs
  7. 10
      Assets/Fungus/Scripts/Commands/SetCollider.cs
  8. 7
      Assets/Fungus/Scripts/Commands/SetInteractable.cs
  9. 5
      Assets/Fungus/Scripts/Commands/SetLayerOrder.cs
  10. 4
      Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs
  11. 4
      Assets/Fungus/Scripts/Commands/ShowSprite.cs
  12. 4
      Assets/Fungus/Scripts/Commands/TweenUI.cs
  13. 5
      Assets/Fungus/Scripts/Commands/iTweenCommand.cs
  14. 4
      Assets/Fungus/Scripts/Components/Clickable2D.cs
  15. 3
      Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs
  16. 4
      Assets/Fungus/Scripts/Components/DialogInput.cs
  17. 22
      Assets/Fungus/Scripts/Components/Draggable2D.cs
  18. 56
      Assets/Fungus/Scripts/Components/Flowchart.cs
  19. 20
      Assets/Fungus/Scripts/Components/Localization.cs
  20. 10
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  21. 9
      Assets/Fungus/Scripts/Components/SayDialog.cs
  22. 8
      Assets/Fungus/Scripts/Components/SpriteFader.cs
  23. 18
      Assets/Fungus/Scripts/Components/Writer.cs
  24. 2
      Assets/Fungus/Scripts/Editor/EventHandlerEditor.cs
  25. 4
      Assets/Fungus/Scripts/Editor/FlowchartEditor.cs
  26. 25
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  27. 3
      Assets/Fungus/Scripts/Editor/LabelEditor.cs
  28. 3
      Assets/Fungus/Scripts/Editor/ViewEditor.cs
  29. 2
      Assets/Fungus/Scripts/Utils/TextTagParser.cs

4
Assets/Fungus/Scripts/Commands/ControlAudio.cs

@ -65,8 +65,8 @@ namespace Fungus
return;
}
AudioSource[] audioSources = GameObject.FindObjectsOfType<AudioSource>();
foreach (AudioSource a in audioSources)
var audioSources = GameObject.FindObjectsOfType<AudioSource>();
foreach (var a in audioSources)
{
if ((a.GetComponent<AudioSource>() != _audioSource.Value) && (a.tag == _audioSource.Value.tag))
{

6
Assets/Fungus/Scripts/Commands/ControlStage.cs

@ -72,7 +72,8 @@ namespace Fungus
protected virtual void MoveToFront(Stage stage)
{
foreach (Stage s in Stage.ActiveStages)
var activeStages = Stage.ActiveStages;
foreach (var s in activeStages)
{
if (s == stage)
{
@ -88,7 +89,8 @@ namespace Fungus
protected virtual void UndimAllPortraits(Stage stage)
{
stage.DimPortraits = false;
foreach (Character character in stage.CharactersOnStage)
var charactersOnStage = stage.CharactersOnStage;
foreach (var character in charactersOnStage)
{
stage.SetDimmed(character, false);
}

93
Assets/Fungus/Scripts/Commands/FadeUI.cs

@ -33,92 +33,95 @@ namespace Fungus
protected override void ApplyTween(GameObject go)
{
foreach (Image image in go.GetComponentsInChildren<Image>())
var images = go.GetComponentsInChildren<Image>();
foreach (var image in images)
{
if (Mathf.Approximately(duration, 0f))
{
switch (fadeMode)
{
case FadeMode.Alpha:
Color tempColor = image.color;
tempColor.a = targetAlpha;
image.color = tempColor;
break;
case FadeMode.Color:
image.color = targetColor;
break;
case FadeMode.Alpha:
Color tempColor = image.color;
tempColor.a = targetAlpha;
image.color = tempColor;
break;
case FadeMode.Color:
image.color = targetColor;
break;
}
}
else
{
switch (fadeMode)
{
case FadeMode.Alpha:
LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType);
break;
case FadeMode.Alpha:
LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType);
break;
}
}
}
foreach (Text text in go.GetComponentsInChildren<Text>())
var texts = go.GetComponentsInChildren<Text>();
foreach (var text in texts)
{
if (Mathf.Approximately(duration, 0f))
{
switch (fadeMode)
{
case FadeMode.Alpha:
Color tempColor = text.color;
tempColor.a = targetAlpha;
text.color = tempColor;
break;
case FadeMode.Color:
text.color = targetColor;
break;
case FadeMode.Alpha:
Color tempColor = text.color;
tempColor.a = targetAlpha;
text.color = tempColor;
break;
case FadeMode.Color:
text.color = targetColor;
break;
}
}
else
{
switch (fadeMode)
{
case FadeMode.Alpha:
LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType);
break;
case FadeMode.Alpha:
LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType);
break;
}
}
}
foreach (TextMesh textMesh in go.GetComponentsInChildren<TextMesh>())
var textMeshes = go.GetComponentsInChildren<TextMesh>();
foreach (var textMesh in textMeshes)
{
if (Mathf.Approximately(duration, 0f))
{
switch (fadeMode)
{
case FadeMode.Alpha:
Color tempColor = textMesh.color;
tempColor.a = targetAlpha;
textMesh.color = tempColor;
break;
case FadeMode.Color:
textMesh.color = targetColor;
break;
case FadeMode.Alpha:
Color tempColor = textMesh.color;
tempColor.a = targetAlpha;
textMesh.color = tempColor;
break;
case FadeMode.Color:
textMesh.color = targetColor;
break;
}
}
else
{
switch (fadeMode)
{
case FadeMode.Alpha:
LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(go, targetColor, duration).setEase(tweenType);
break;
case FadeMode.Alpha:
LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(go, targetColor, duration).setEase(tweenType);
break;
}
}
}

3
Assets/Fungus/Scripts/Commands/Jump.cs

@ -29,7 +29,8 @@ namespace Fungus
return;
}
foreach (var command in ParentBlock.CommandList)
var commandList = ParentBlock.CommandList;
foreach (var command in commandList)
{
Label label = command as Label;
if (label != null &&

3
Assets/Fungus/Scripts/Commands/Say.cs

@ -107,7 +107,8 @@ namespace Fungus
string displayText = storyText;
foreach (CustomTag ct in CustomTag.activeCustomTags)
var activeCustomTags = CustomTag.activeCustomTags;
foreach (var ct in activeCustomTags)
{
displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith);
if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "")

2
Assets/Fungus/Scripts/Commands/SendMessage.cs

@ -59,7 +59,7 @@ namespace Fungus
if (receivers != null)
{
foreach (MessageReceived receiver in receivers)
foreach (var receiver in receivers)
{
receiver.OnSendFungusMessage(_message.Value);
}

10
Assets/Fungus/Scripts/Commands/SetCollider.cs

@ -29,13 +29,15 @@ namespace Fungus
if (go != null)
{
// 3D objects
foreach (Collider c in go.GetComponentsInChildren<Collider>())
var colliders = go.GetComponentsInChildren<Collider>();
foreach (var c in colliders)
{
c.enabled = activeState.Value;
}
// 2D objects
foreach (Collider2D c in go.GetComponentsInChildren<Collider2D>())
var collider2Ds = go.GetComponentsInChildren<Collider2D>();
foreach (var c in collider2Ds)
{
c.enabled = activeState.Value;
}
@ -46,7 +48,7 @@ namespace Fungus
public override void OnEnter()
{
foreach (GameObject go in targetObjects)
foreach (var go in targetObjects)
{
SetColliderActive(go);
}
@ -63,7 +65,7 @@ namespace Fungus
if (taggedObjects != null)
{
foreach (GameObject go in taggedObjects)
foreach (var go in taggedObjects)
{
SetColliderActive(go);
}

7
Assets/Fungus/Scripts/Commands/SetInteractable.cs

@ -31,9 +31,10 @@ namespace Fungus
return;
}
foreach (GameObject targetObject in targetObjects)
foreach (var targetObject in targetObjects)
{
foreach (Selectable selectable in targetObject.GetComponents<Selectable>())
var selectables = targetObject.GetComponents<Selectable>();
foreach (var selectable in selectables)
{
selectable.interactable = interactableState.Value;
}
@ -58,7 +59,7 @@ namespace Fungus
}
string objectList = "";
foreach (GameObject gameObject in targetObjects)
foreach (var gameObject in targetObjects)
{
if (gameObject == null)
{

5
Assets/Fungus/Scripts/Commands/SetLayerOrder.cs

@ -22,14 +22,15 @@ namespace Fungus
protected void ApplySortingLayer(Transform target, string layerName)
{
Renderer renderer = target.gameObject.GetComponent<Renderer>();
var renderer = target.gameObject.GetComponent<Renderer>();
if (renderer)
{
renderer.sortingLayerName = layerName;
Debug.Log(target.name);
}
foreach (Transform child in target.transform)
var targetTransform = target.transform;
foreach (Transform child in targetTransform)
{
ApplySortingLayer(child, layerName);
}

4
Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs

@ -25,7 +25,7 @@ namespace Fungus
public override void OnEnter()
{
foreach (SpriteRenderer spriteRenderer in targetSprites)
foreach (var spriteRenderer in targetSprites)
{
spriteRenderer.sortingOrder = orderInLayer;
}
@ -36,7 +36,7 @@ namespace Fungus
public override string GetSummary()
{
string summary = "";
foreach (SpriteRenderer spriteRenderer in targetSprites)
foreach (var spriteRenderer in targetSprites)
{
if (spriteRenderer == null)
{

4
Assets/Fungus/Scripts/Commands/ShowSprite.cs

@ -40,8 +40,8 @@ namespace Fungus
{
if (affectChildren)
{
SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer sr in children)
var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (var sr in spriteRenderers)
{
SetSpriteAlpha(sr, _visible.Value);
}

4
Assets/Fungus/Scripts/Commands/TweenUI.cs

@ -26,7 +26,7 @@ namespace Fungus
protected virtual void ApplyTween()
{
foreach (GameObject targetObject in targetObjects)
foreach (var targetObject in targetObjects)
{
if (targetObject == null)
{
@ -97,7 +97,7 @@ namespace Fungus
}
string objectList = "";
foreach (GameObject gameObject in targetObjects)
foreach (var gameObject in targetObjects)
{
if (gameObject == null)
{

5
Assets/Fungus/Scripts/Commands/iTweenCommand.cs

@ -73,8 +73,9 @@ namespace Fungus
if (stopPreviousTweens)
{
// Force any existing iTweens on this target object to complete immediately
iTween[] tweens = _targetObject.Value.GetComponents<iTween>();
foreach (iTween tween in tweens) {
var tweens = _targetObject.Value.GetComponents<iTween>();
foreach (var tween in tweens)
{
tween.time = 0;
tween.SendMessage("Update");
}

4
Assets/Fungus/Scripts/Components/Clickable2D.cs

@ -40,8 +40,8 @@ namespace Fungus
}
// TODO: Cache these objects for faster lookup
ObjectClicked[] handlers = GameObject.FindObjectsOfType<ObjectClicked>();
foreach (ObjectClicked handler in handlers)
var handlers = GameObject.FindObjectsOfType<ObjectClicked>();
foreach (var handler in handlers)
{
handler.OnObjectClicked(this);
}

3
Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs

@ -62,7 +62,8 @@ namespace Fungus
public virtual void Clear()
{
foreach (Command command in GetCommands())
var commands = GetCommands();
foreach (var command in commands)
{
DestroyImmediate(command);
}

4
Assets/Fungus/Scripts/Components/DialogInput.cs

@ -114,8 +114,8 @@ namespace Fungus
// Tell any listeners to move to the next line
if (nextLineInputFlag)
{
IDialogInputListener[] inputListeners = gameObject.GetComponentsInChildren<IDialogInputListener>();
foreach (IDialogInputListener inputListener in inputListeners)
var inputListeners = gameObject.GetComponentsInChildren<IDialogInputListener>();
foreach (var inputListener in inputListeners)
{
inputListener.OnNextLineEvent();
}

22
Assets/Fungus/Scripts/Components/Draggable2D.cs

@ -58,12 +58,14 @@ namespace Fungus
return;
}
foreach (DragEntered handler in GetHandlers<DragEntered>())
var dragEnteredHandlers = GetHandlers<DragEntered>();
foreach (var handler in dragEnteredHandlers)
{
handler.OnDragEntered(this, other);
}
foreach (DragCompleted handler in GetHandlers<DragCompleted>())
var dragCompletedHandlers = GetHandlers<DragCompleted>();
foreach (var handler in dragCompletedHandlers)
{
handler.OnDragEntered(this, other);
}
@ -76,12 +78,14 @@ namespace Fungus
return;
}
foreach (DragExited handler in GetHandlers<DragExited>())
var dragExitedHandlers = GetHandlers<DragExited>();
foreach (var handler in dragExitedHandlers)
{
handler.OnDragExited(this, other);
}
foreach (DragCompleted handler in GetHandlers<DragCompleted>())
var dragCompletedHandlers = GetHandlers<DragCompleted>();
foreach (var handler in dragCompletedHandlers)
{
handler.OnDragExited(this, other);
}
@ -103,7 +107,8 @@ namespace Fungus
startingPosition = transform.position;
foreach (DragStarted handler in GetHandlers<DragStarted>())
var dragStartedHandlers = GetHandlers<DragStarted>();
foreach (var handler in dragStartedHandlers)
{
handler.OnDragStarted(this);
}
@ -134,8 +139,8 @@ namespace Fungus
bool dragCompleted = false;
DragCompleted[] handlers = GetHandlers<DragCompleted>();
foreach (DragCompleted handler in handlers)
var handlers = GetHandlers<DragCompleted>();
foreach (var handler in handlers)
{
if (handler.DraggableObject == this)
{
@ -154,7 +159,8 @@ namespace Fungus
if (!dragCompleted)
{
foreach (DragCancelled handler in GetHandlers<DragCancelled>())
var dragCancelledHandlers = GetHandlers<DragCancelled>();
foreach (var handler in dragCancelledHandlers)
{
handler.OnDragCancelled(this);
}

56
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -158,7 +158,8 @@ namespace Fungus
}
// Tell all components that implement IUpdateable to update to the new version
foreach (Component component in GetComponents<Component>())
var components = GetComponents<Component>();
foreach (var component in components)
{
IUpdateable u = component as IUpdateable;
if (u != null)
@ -213,7 +214,8 @@ namespace Fungus
// It shouldn't happen but it seemed to occur for a user on the forum
variables.RemoveAll(item => item == null);
foreach (Variable variable in GetComponents<Variable>())
var allVariables = GetComponents<Variable>();
foreach (var variable in allVariables)
{
if (!variables.Contains(variable))
{
@ -222,8 +224,8 @@ namespace Fungus
}
var blocks = GetComponents<Block>();
foreach (var command in GetComponents<Command>())
var commands = GetComponents<Command>();
foreach (var command in commands)
{
bool found = false;
foreach (var block in blocks)
@ -241,7 +243,8 @@ namespace Fungus
}
}
foreach (EventHandler eventHandler in GetComponents<EventHandler>())
var eventHandlers = GetComponents<EventHandler>();
foreach (var eventHandler in eventHandlers)
{
bool found = false;
foreach (var block in blocks)
@ -279,8 +282,8 @@ namespace Fungus
/// </summary>
public static void BroadcastFungusMessage(string messageName)
{
MessageReceived[] eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers)
var eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>();
foreach (var eventHandler in eventHandlers)
{
eventHandler.OnSendFungusMessage(messageName);
}
@ -506,7 +509,7 @@ namespace Fungus
public virtual void StopAllBlocks()
{
var blocks = GetComponents<Block>();
foreach (Block block in blocks)
foreach (var block in blocks)
{
if (block.IsExecuting())
{
@ -521,8 +524,8 @@ namespace Fungus
/// </summary>
public virtual void SendFungusMessage(string messageName)
{
MessageReceived[] eventHandlers = GetComponents<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers)
var eventHandlers = GetComponents<MessageReceived>();
foreach (var eventHandler in eventHandlers)
{
eventHandler.OnSendFungusMessage(messageName);
}
@ -553,7 +556,7 @@ namespace Fungus
while (true)
{
bool collision = false;
foreach(Variable variable in variables)
foreach(var variable in variables)
{
if (variable == null ||
variable == ignoreVariable ||
@ -640,7 +643,8 @@ namespace Fungus
while (true)
{
bool collision = false;
foreach (var command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
Label label = command as Label;
if (label == null ||
@ -673,7 +677,7 @@ namespace Fungus
/// </summary>
public Variable GetVariable(string key)
{
foreach (Variable variable in variables)
foreach (var variable in variables)
{
if (variable != null && variable.Key == key)
{
@ -692,7 +696,7 @@ namespace Fungus
/// </summary>
public T GetVariable<T>(string key) where T : Variable
{
foreach (Variable variable in variables)
foreach (var variable in variables)
{
if (variable != null && variable.Key == key)
{
@ -710,7 +714,7 @@ namespace Fungus
/// </summary>
public void SetVariable<T>(string key, T newvariable) where T : Variable
{
foreach (Variable v in variables)
foreach (var v in variables)
{
if (v != null && v.Key == key)
{
@ -732,7 +736,7 @@ namespace Fungus
public virtual List<Variable> GetPublicVariables()
{
List<Variable> publicVariables = new List<Variable>();
foreach (Variable v in variables)
foreach (var v in variables)
{
if (v != null && v.Scope == VariableScope.Public)
{
@ -874,8 +878,8 @@ namespace Fungus
{
if (hideComponents)
{
Block[] blocks = GetComponents<Block>();
foreach (Block block in blocks)
var blocks = GetComponents<Block>();
foreach (var block in blocks)
{
block.hideFlags = HideFlags.HideInInspector;
if (block.gameObject != gameObject)
@ -884,13 +888,13 @@ namespace Fungus
}
}
Command[] commands = GetComponents<Command>();
var commands = GetComponents<Command>();
foreach (var command in commands)
{
command.hideFlags = HideFlags.HideInInspector;
}
EventHandler[] eventHandlers = GetComponents<EventHandler>();
var eventHandlers = GetComponents<EventHandler>();
foreach (var eventHandler in eventHandlers)
{
eventHandler.hideFlags = HideFlags.HideInInspector;
@ -898,8 +902,8 @@ namespace Fungus
}
else
{
MonoBehaviour[] monoBehaviours = GetComponents<MonoBehaviour>();
foreach (MonoBehaviour monoBehaviour in monoBehaviours)
var monoBehaviours = GetComponents<MonoBehaviour>();
foreach (var monoBehaviour in monoBehaviours)
{
if (monoBehaviour == null)
{
@ -947,7 +951,7 @@ namespace Fungus
if (resetVariables)
{
foreach (Variable variable in variables)
foreach (var variable in variables)
{
variable.OnReset();
}
@ -959,7 +963,7 @@ namespace Fungus
/// </summary>
public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo)
{
foreach (string key in hideCommands)
foreach (var key in hideCommands)
{
// Match on category or command name (case insensitive)
if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 ||
@ -1037,7 +1041,7 @@ namespace Fungus
string key = match.Value.Substring(2, match.Value.Length - 3);
// Look for any matching private variables in this Flowchart first
foreach (Variable variable in variables)
foreach (var variable in variables)
{
if (variable == null)
continue;
@ -1089,7 +1093,7 @@ namespace Fungus
string key = match.Value.Substring(2, match.Value.Length - 3);
// Look for any matching public variables in this Flowchart
foreach (Variable variable in variables)
foreach (var variable in variables)
{
if (variable == null)
continue;

20
Assets/Fungus/Scripts/Components/Localization.cs

@ -96,7 +96,7 @@ namespace Fungus
protected virtual void CacheLocalizeableObjects()
{
UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component));
foreach (UnityEngine.Object o in objects)
foreach (var o in objects)
{
ILocalizable localizable = o as ILocalizable;
if (localizable != null)
@ -121,7 +121,8 @@ namespace Fungus
var blocks = flowchart.GetComponents<Block>();
foreach (var block in blocks)
{
foreach (var command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
ILocalizable localizable = command as ILocalizable;
if (localizable != null)
@ -137,7 +138,7 @@ namespace Fungus
// Add everything else that's localizable (including inactive objects)
UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component));
foreach (UnityEngine.Object o in objects)
foreach (var o in objects)
{
ILocalizable localizable = o as ILocalizable;
if (localizable != null)
@ -289,7 +290,8 @@ namespace Fungus
// Build CSV header row and a list of the language codes currently in use
string csvHeader = "Key,Description,Standard";
List<string> languageCodes = new List<string>();
foreach (TextItem textItem in textItems.Values)
var values = textItems.Values;
foreach (var textItem in values)
{
foreach (string languageCode in textItem.localizedStrings.Keys)
{
@ -304,7 +306,8 @@ namespace Fungus
// Build the CSV file using collected text items
int rowCount = 0;
string csvData = csvHeader + "\n";
foreach (string stringId in textItems.Keys)
var keys = textItems.Keys;
foreach (var stringId in keys)
{
TextItem textItem = textItems[stringId];
@ -312,7 +315,7 @@ namespace Fungus
row += "," + CSVSupport.Escape(textItem.description);
row += "," + CSVSupport.Escape(textItem.standardText);
foreach (string languageCode in languageCodes)
foreach (var languageCode in languageCodes)
{
if (textItem.localizedStrings.ContainsKey(languageCode))
{
@ -462,7 +465,8 @@ namespace Fungus
string textData = "";
int rowCount = 0;
foreach (string stringId in textItems.Keys)
var keys = textItems.Keys;
foreach (var stringId in keys)
{
TextItem languageItem = textItems[stringId];
@ -487,7 +491,7 @@ namespace Fungus
string stringId = "";
string buffer = "";
foreach (string line in lines)
foreach (var line in lines)
{
// Check for string id line
if (line.StartsWith("#"))

10
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -155,12 +155,12 @@ namespace Fungus
StopAllCoroutines();
Button[] optionButtons = GetComponentsInChildren<Button>();
foreach (UnityEngine.UI.Button button in optionButtons)
foreach (var button in optionButtons)
{
button.onClick.RemoveAllListeners();
}
foreach (UnityEngine.UI.Button button in optionButtons)
foreach (var button in optionButtons)
{
if (button != null)
{
@ -198,7 +198,7 @@ namespace Fungus
public virtual bool AddOption(string text, bool interactable, Block targetBlock)
{
bool addedOption = false;
foreach (Button button in cachedButtons)
foreach (var button in cachedButtons)
{
if (!button.gameObject.activeSelf)
{
@ -266,7 +266,7 @@ namespace Fungus
}
bool addedOption = false;
foreach (Button button in CachedButtons)
foreach (var button in CachedButtons)
{
if (!button.gameObject.activeSelf)
{
@ -373,7 +373,7 @@ namespace Fungus
{
get {
int count = 0;
foreach (Button button in cachedButtons)
foreach (var button in cachedButtons)
{
if (button.gameObject.activeSelf)
{

9
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -226,7 +226,8 @@ namespace Fungus
public static void StopPortraitTweens()
{
// Stop all tweening portraits
foreach( Character c in Character.ActiveCharacters )
var activeCharacters = Character.ActiveCharacters;
foreach (var c in activeCharacters)
{
if (c.State.portraitImage != null)
{
@ -281,12 +282,14 @@ namespace Fungus
speakingCharacter = character;
// Dim portraits of non-speaking characters
foreach (Stage stage in Stage.ActiveStages)
var activeStages = Stage.ActiveStages;
foreach (var stage in activeStages)
{
if (stage.DimPortraits)
{
foreach (var c in stage.CharactersOnStage)
var charactersOnStage = stage.CharactersOnStage;
foreach (var c in charactersOnStage)
{
if (prevSpeakingCharacter != speakingCharacter)
{

8
Assets/Fungus/Scripts/Components/SpriteFader.cs

@ -77,15 +77,15 @@ namespace Fungus
}
// Fade child sprite renderers
SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer child in children)
var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (var sr in spriteRenderers)
{
if (child == spriteRenderer)
if (sr == spriteRenderer)
{
continue;
}
FadeSprite(child, targetColor, duration, slideOffset);
FadeSprite(sr, targetColor, duration, slideOffset);
}
// Destroy any existing fader component

18
Assets/Fungus/Scripts/Components/Writer.cs

@ -106,7 +106,8 @@ namespace Fungus
// Try to find any component with a text property
if (textUI == null && inputField == null && textMesh == null)
{
foreach (Component c in go.GetComponents<Component>())
var allcomponents = go.GetComponents<Component>();
foreach (var c in allcomponents)
{
textProperty = c.GetType().GetProperty("text");
if (textProperty != null)
@ -118,7 +119,8 @@ namespace Fungus
}
// Cache the list of child writer listeners
foreach (Component component in GetComponentsInChildren<Component>())
var allComponents = GetComponentsInChildren<Component>();
foreach (var component in allComponents)
{
IWriterListener writerListener = component as IWriterListener;
if (writerListener != null)
@ -688,7 +690,7 @@ namespace Fungus
{
WriterSignals.DoWriterInput(this);
foreach (IWriterListener writerListener in writerListeners)
foreach (var writerListener in writerListeners)
{
writerListener.OnInput();
}
@ -698,7 +700,7 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.Start);
foreach (IWriterListener writerListener in writerListeners)
foreach (var writerListener in writerListeners)
{
writerListener.OnStart(audioClip);
}
@ -708,7 +710,7 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.Pause);
foreach (IWriterListener writerListener in writerListeners)
foreach (var writerListener in writerListeners)
{
writerListener.OnPause();
}
@ -718,7 +720,7 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.Resume);
foreach (IWriterListener writerListener in writerListeners)
foreach (var writerListener in writerListeners)
{
writerListener.OnResume();
}
@ -728,7 +730,7 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.End);
foreach (IWriterListener writerListener in writerListeners)
foreach (var writerListener in writerListeners)
{
writerListener.OnEnd(stopAudio);
}
@ -738,7 +740,7 @@ namespace Fungus
{
WriterSignals.DoWriterGlyph(this);
foreach (IWriterListener writerListener in writerListeners)
foreach (var writerListener in writerListeners)
{
writerListener.OnGlyph();
}

2
Assets/Fungus/Scripts/Editor/EventHandlerEditor.cs

@ -15,7 +15,7 @@ namespace Fungus.EditorUtils
public static EventHandlerInfoAttribute GetEventHandlerInfo(System.Type eventHandlerType)
{
object[] attributes = eventHandlerType.GetCustomAttributes(typeof(EventHandlerInfoAttribute), false);
foreach (object obj in attributes)
foreach (var obj in attributes)
{
EventHandlerInfoAttribute eventHandlerInfoAttr = obj as EventHandlerInfoAttribute;
if (eventHandlerInfoAttr != null)

4
Assets/Fungus/Scripts/Editor/FlowchartEditor.cs

@ -188,7 +188,7 @@ namespace Fungus.EditorUtils
List<System.Type> types = FindAllDerivedTypes<Variable>();
// Add variable types without a category
foreach (System.Type type in types)
foreach (var type in types)
{
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null ||
@ -207,7 +207,7 @@ namespace Fungus.EditorUtils
}
// Add types with a category
foreach (System.Type type in types)
foreach (var type in types)
{
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null ||

25
Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

@ -121,7 +121,8 @@ namespace Fungus.EditorUtils
{
bool isSelected = (flowchart.SelectedBlock == deleteBlock);
foreach (Command command in deleteBlock.CommandList)
var commandList = deleteBlock.CommandList;
foreach (var command in commandList)
{
Undo.DestroyObjectImmediate(command);
}
@ -552,7 +553,8 @@ namespace Fungus.EditorUtils
protected virtual void DeleteBlock(Flowchart flowchart, Block block)
{
foreach (var command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
Undo.DestroyObjectImmediate(command);
}
@ -614,7 +616,7 @@ namespace Fungus.EditorUtils
// Count the number of unique connections (excluding self references)
var uniqueList = new List<Block>();
var connectedBlocks = block.GetConnectedBlocks();
foreach (Block connectedBlock in connectedBlocks)
foreach (var connectedBlock in connectedBlocks)
{
if (connectedBlock == block ||
uniqueList.Contains(connectedBlock))
@ -675,7 +677,8 @@ namespace Fungus.EditorUtils
bool blockIsSelected = (flowchart.SelectedBlock != block);
foreach (Command command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
if (command == null)
{
@ -683,7 +686,8 @@ namespace Fungus.EditorUtils
}
bool commandIsSelected = false;
foreach (Command selectedCommand in flowchart.SelectedCommands)
var selectedCommands = flowchart.SelectedCommands;
foreach (var selectedCommand in selectedCommands)
{
if (selectedCommand == command)
{
@ -703,7 +707,7 @@ namespace Fungus.EditorUtils
connectedBlocks.Clear();
command.GetConnectedBlocks(ref connectedBlocks);
foreach (Block blockB in connectedBlocks)
foreach (var blockB in connectedBlocks)
{
if (blockB == null ||
block == blockB ||
@ -745,9 +749,9 @@ namespace Fungus.EditorUtils
Vector2 pointB = Vector2.zero;
float minDist = float.MaxValue;
foreach (Vector2 a in pointsA)
foreach (var a in pointsA)
{
foreach (Vector2 b in pointsB)
foreach (var b in pointsB)
{
float d = Vector2.Distance(a, b);
if (d < minDist)
@ -796,7 +800,8 @@ namespace Fungus.EditorUtils
Undo.RecordObject(newBlock, "Duplicate Block");
foreach (Command command in oldBlock.CommandList)
var commandList = oldBlock.CommandList;
foreach (var command in commandList)
{
if (ComponentUtility.CopyComponent(command))
{
@ -807,7 +812,7 @@ namespace Fungus.EditorUtils
if (pastedCommand != null)
{
pastedCommand.ItemId = flowchart.NextItemId();
newBlock.CommandList.Add (pastedCommand);
newBlock.CommandList.Add(pastedCommand);
}
}

3
Assets/Fungus/Scripts/Editor/LabelEditor.cs

@ -26,7 +26,8 @@ namespace Fungus.EditorUtils
int index = 0;
int selectedIndex = 0;
foreach (Command command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
Label label = command as Label;
if (label == null)

3
Assets/Fungus/Scripts/Editor/ViewEditor.cs

@ -171,7 +171,8 @@ namespace Fungus.EditorUtils
var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart != null)
{
foreach (Command command in flowchart.SelectedCommands)
var selectedCommands = flowchart.SelectedCommands;
foreach (var command in selectedCommands)
{
MoveToView moveToViewCommand = command as MoveToView;
if (moveToViewCommand != null &&

2
Assets/Fungus/Scripts/Utils/TextTagParser.cs

@ -264,7 +264,7 @@ namespace Fungus
// These characters are usually added for legibility when editing, but are not
// desireable when viewing the text in game.
bool trimLeading = false;
foreach (TextTagToken token in tokens)
foreach (var token in tokens)
{
if (trimLeading &&
token.type == TokenType.Words)

Loading…
Cancel
Save