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; return;
} }
AudioSource[] audioSources = GameObject.FindObjectsOfType<AudioSource>(); var audioSources = GameObject.FindObjectsOfType<AudioSource>();
foreach (AudioSource a in audioSources) foreach (var a in audioSources)
{ {
if ((a.GetComponent<AudioSource>() != _audioSource.Value) && (a.tag == _audioSource.Value.tag)) 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) protected virtual void MoveToFront(Stage stage)
{ {
foreach (Stage s in Stage.ActiveStages) var activeStages = Stage.ActiveStages;
foreach (var s in activeStages)
{ {
if (s == stage) if (s == stage)
{ {
@ -88,7 +89,8 @@ namespace Fungus
protected virtual void UndimAllPortraits(Stage stage) protected virtual void UndimAllPortraits(Stage stage)
{ {
stage.DimPortraits = false; stage.DimPortraits = false;
foreach (Character character in stage.CharactersOnStage) var charactersOnStage = stage.CharactersOnStage;
foreach (var character in charactersOnStage)
{ {
stage.SetDimmed(character, false); stage.SetDimmed(character, false);
} }

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

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

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

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

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

@ -107,7 +107,8 @@ namespace Fungus
string displayText = storyText; 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); displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith);
if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "") if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -58,12 +58,14 @@ namespace Fungus
return; return;
} }
foreach (DragEntered handler in GetHandlers<DragEntered>()) var dragEnteredHandlers = GetHandlers<DragEntered>();
foreach (var handler in dragEnteredHandlers)
{ {
handler.OnDragEntered(this, other); handler.OnDragEntered(this, other);
} }
foreach (DragCompleted handler in GetHandlers<DragCompleted>()) var dragCompletedHandlers = GetHandlers<DragCompleted>();
foreach (var handler in dragCompletedHandlers)
{ {
handler.OnDragEntered(this, other); handler.OnDragEntered(this, other);
} }
@ -76,12 +78,14 @@ namespace Fungus
return; return;
} }
foreach (DragExited handler in GetHandlers<DragExited>()) var dragExitedHandlers = GetHandlers<DragExited>();
foreach (var handler in dragExitedHandlers)
{ {
handler.OnDragExited(this, other); handler.OnDragExited(this, other);
} }
foreach (DragCompleted handler in GetHandlers<DragCompleted>()) var dragCompletedHandlers = GetHandlers<DragCompleted>();
foreach (var handler in dragCompletedHandlers)
{ {
handler.OnDragExited(this, other); handler.OnDragExited(this, other);
} }
@ -103,7 +107,8 @@ namespace Fungus
startingPosition = transform.position; startingPosition = transform.position;
foreach (DragStarted handler in GetHandlers<DragStarted>()) var dragStartedHandlers = GetHandlers<DragStarted>();
foreach (var handler in dragStartedHandlers)
{ {
handler.OnDragStarted(this); handler.OnDragStarted(this);
} }
@ -134,8 +139,8 @@ namespace Fungus
bool dragCompleted = false; bool dragCompleted = false;
DragCompleted[] handlers = GetHandlers<DragCompleted>(); var handlers = GetHandlers<DragCompleted>();
foreach (DragCompleted handler in handlers) foreach (var handler in handlers)
{ {
if (handler.DraggableObject == this) if (handler.DraggableObject == this)
{ {
@ -154,7 +159,8 @@ namespace Fungus
if (!dragCompleted) if (!dragCompleted)
{ {
foreach (DragCancelled handler in GetHandlers<DragCancelled>()) var dragCancelledHandlers = GetHandlers<DragCancelled>();
foreach (var handler in dragCancelledHandlers)
{ {
handler.OnDragCancelled(this); 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 // 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; IUpdateable u = component as IUpdateable;
if (u != null) if (u != null)
@ -213,7 +214,8 @@ namespace Fungus
// It shouldn't happen but it seemed to occur for a user on the forum // It shouldn't happen but it seemed to occur for a user on the forum
variables.RemoveAll(item => item == null); variables.RemoveAll(item => item == null);
foreach (Variable variable in GetComponents<Variable>()) var allVariables = GetComponents<Variable>();
foreach (var variable in allVariables)
{ {
if (!variables.Contains(variable)) if (!variables.Contains(variable))
{ {
@ -222,8 +224,8 @@ namespace Fungus
} }
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
var commands = GetComponents<Command>();
foreach (var command in GetComponents<Command>()) foreach (var command in commands)
{ {
bool found = false; bool found = false;
foreach (var block in blocks) 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; bool found = false;
foreach (var block in blocks) foreach (var block in blocks)
@ -279,8 +282,8 @@ namespace Fungus
/// </summary> /// </summary>
public static void BroadcastFungusMessage(string messageName) public static void BroadcastFungusMessage(string messageName)
{ {
MessageReceived[] eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>(); var eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers) foreach (var eventHandler in eventHandlers)
{ {
eventHandler.OnSendFungusMessage(messageName); eventHandler.OnSendFungusMessage(messageName);
} }
@ -506,7 +509,7 @@ namespace Fungus
public virtual void StopAllBlocks() public virtual void StopAllBlocks()
{ {
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (Block block in blocks) foreach (var block in blocks)
{ {
if (block.IsExecuting()) if (block.IsExecuting())
{ {
@ -521,8 +524,8 @@ namespace Fungus
/// </summary> /// </summary>
public virtual void SendFungusMessage(string messageName) public virtual void SendFungusMessage(string messageName)
{ {
MessageReceived[] eventHandlers = GetComponents<MessageReceived>(); var eventHandlers = GetComponents<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers) foreach (var eventHandler in eventHandlers)
{ {
eventHandler.OnSendFungusMessage(messageName); eventHandler.OnSendFungusMessage(messageName);
} }
@ -553,7 +556,7 @@ namespace Fungus
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach(Variable variable in variables) foreach(var variable in variables)
{ {
if (variable == null || if (variable == null ||
variable == ignoreVariable || variable == ignoreVariable ||
@ -640,7 +643,8 @@ namespace Fungus
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach (var command in block.CommandList) var commandList = block.CommandList;
foreach (var command in commandList)
{ {
Label label = command as Label; Label label = command as Label;
if (label == null || if (label == null ||
@ -673,7 +677,7 @@ namespace Fungus
/// </summary> /// </summary>
public Variable GetVariable(string key) public Variable GetVariable(string key)
{ {
foreach (Variable variable in variables) foreach (var variable in variables)
{ {
if (variable != null && variable.Key == key) if (variable != null && variable.Key == key)
{ {
@ -692,7 +696,7 @@ namespace Fungus
/// </summary> /// </summary>
public T GetVariable<T>(string key) where T : Variable 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) if (variable != null && variable.Key == key)
{ {
@ -710,7 +714,7 @@ namespace Fungus
/// </summary> /// </summary>
public void SetVariable<T>(string key, T newvariable) where T : Variable 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) if (v != null && v.Key == key)
{ {
@ -732,7 +736,7 @@ namespace Fungus
public virtual List<Variable> GetPublicVariables() public virtual List<Variable> GetPublicVariables()
{ {
List<Variable> publicVariables = new List<Variable>(); List<Variable> publicVariables = new List<Variable>();
foreach (Variable v in variables) foreach (var v in variables)
{ {
if (v != null && v.Scope == VariableScope.Public) if (v != null && v.Scope == VariableScope.Public)
{ {
@ -874,8 +878,8 @@ namespace Fungus
{ {
if (hideComponents) if (hideComponents)
{ {
Block[] blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (Block block in blocks) foreach (var block in blocks)
{ {
block.hideFlags = HideFlags.HideInInspector; block.hideFlags = HideFlags.HideInInspector;
if (block.gameObject != gameObject) if (block.gameObject != gameObject)
@ -884,13 +888,13 @@ namespace Fungus
} }
} }
Command[] commands = GetComponents<Command>(); var commands = GetComponents<Command>();
foreach (var command in commands) foreach (var command in commands)
{ {
command.hideFlags = HideFlags.HideInInspector; command.hideFlags = HideFlags.HideInInspector;
} }
EventHandler[] eventHandlers = GetComponents<EventHandler>(); var eventHandlers = GetComponents<EventHandler>();
foreach (var eventHandler in eventHandlers) foreach (var eventHandler in eventHandlers)
{ {
eventHandler.hideFlags = HideFlags.HideInInspector; eventHandler.hideFlags = HideFlags.HideInInspector;
@ -898,8 +902,8 @@ namespace Fungus
} }
else else
{ {
MonoBehaviour[] monoBehaviours = GetComponents<MonoBehaviour>(); var monoBehaviours = GetComponents<MonoBehaviour>();
foreach (MonoBehaviour monoBehaviour in monoBehaviours) foreach (var monoBehaviour in monoBehaviours)
{ {
if (monoBehaviour == null) if (monoBehaviour == null)
{ {
@ -947,7 +951,7 @@ namespace Fungus
if (resetVariables) if (resetVariables)
{ {
foreach (Variable variable in variables) foreach (var variable in variables)
{ {
variable.OnReset(); variable.OnReset();
} }
@ -959,7 +963,7 @@ namespace Fungus
/// </summary> /// </summary>
public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo) public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo)
{ {
foreach (string key in hideCommands) foreach (var key in hideCommands)
{ {
// Match on category or command name (case insensitive) // Match on category or command name (case insensitive)
if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 || 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); string key = match.Value.Substring(2, match.Value.Length - 3);
// Look for any matching private variables in this Flowchart first // Look for any matching private variables in this Flowchart first
foreach (Variable variable in variables) foreach (var variable in variables)
{ {
if (variable == null) if (variable == null)
continue; continue;
@ -1089,7 +1093,7 @@ namespace Fungus
string key = match.Value.Substring(2, match.Value.Length - 3); string key = match.Value.Substring(2, match.Value.Length - 3);
// Look for any matching public variables in this Flowchart // Look for any matching public variables in this Flowchart
foreach (Variable variable in variables) foreach (var variable in variables)
{ {
if (variable == null) if (variable == null)
continue; continue;

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

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

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

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

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

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

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

@ -77,15 +77,15 @@ namespace Fungus
} }
// Fade child sprite renderers // Fade child sprite renderers
SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>(); var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer child in children) foreach (var sr in spriteRenderers)
{ {
if (child == spriteRenderer) if (sr == spriteRenderer)
{ {
continue; continue;
} }
FadeSprite(child, targetColor, duration, slideOffset); FadeSprite(sr, targetColor, duration, slideOffset);
} }
// Destroy any existing fader component // 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 // Try to find any component with a text property
if (textUI == null && inputField == null && textMesh == null) 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"); textProperty = c.GetType().GetProperty("text");
if (textProperty != null) if (textProperty != null)
@ -118,7 +119,8 @@ namespace Fungus
} }
// Cache the list of child writer listeners // 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; IWriterListener writerListener = component as IWriterListener;
if (writerListener != null) if (writerListener != null)
@ -688,7 +690,7 @@ namespace Fungus
{ {
WriterSignals.DoWriterInput(this); WriterSignals.DoWriterInput(this);
foreach (IWriterListener writerListener in writerListeners) foreach (var writerListener in writerListeners)
{ {
writerListener.OnInput(); writerListener.OnInput();
} }
@ -698,7 +700,7 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.Start); WriterSignals.DoWriterState(this, WriterState.Start);
foreach (IWriterListener writerListener in writerListeners) foreach (var writerListener in writerListeners)
{ {
writerListener.OnStart(audioClip); writerListener.OnStart(audioClip);
} }
@ -708,7 +710,7 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.Pause); WriterSignals.DoWriterState(this, WriterState.Pause);
foreach (IWriterListener writerListener in writerListeners) foreach (var writerListener in writerListeners)
{ {
writerListener.OnPause(); writerListener.OnPause();
} }
@ -718,7 +720,7 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.Resume); WriterSignals.DoWriterState(this, WriterState.Resume);
foreach (IWriterListener writerListener in writerListeners) foreach (var writerListener in writerListeners)
{ {
writerListener.OnResume(); writerListener.OnResume();
} }
@ -728,7 +730,7 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.End); WriterSignals.DoWriterState(this, WriterState.End);
foreach (IWriterListener writerListener in writerListeners) foreach (var writerListener in writerListeners)
{ {
writerListener.OnEnd(stopAudio); writerListener.OnEnd(stopAudio);
} }
@ -738,7 +740,7 @@ namespace Fungus
{ {
WriterSignals.DoWriterGlyph(this); WriterSignals.DoWriterGlyph(this);
foreach (IWriterListener writerListener in writerListeners) foreach (var writerListener in writerListeners)
{ {
writerListener.OnGlyph(); writerListener.OnGlyph();
} }

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

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

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

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

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

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

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

@ -171,7 +171,8 @@ namespace Fungus.EditorUtils
var flowchart = FlowchartWindow.GetFlowchart(); var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart != null) if (flowchart != null)
{ {
foreach (Command command in flowchart.SelectedCommands) var selectedCommands = flowchart.SelectedCommands;
foreach (var command in selectedCommands)
{ {
MoveToView moveToViewCommand = command as MoveToView; MoveToView moveToViewCommand = command as MoveToView;
if (moveToViewCommand != null && 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 // These characters are usually added for legibility when editing, but are not
// desireable when viewing the text in game. // desireable when viewing the text in game.
bool trimLeading = false; bool trimLeading = false;
foreach (TextTagToken token in tokens) foreach (var token in tokens)
{ {
if (trimLeading && if (trimLeading &&
token.type == TokenType.Words) token.type == TokenType.Words)

Loading…
Cancel
Save