Browse Source

Converted (most) foreach to for statements. Avoids an allocation for the loop iterator.

master
Christopher 8 years ago
parent
commit
1ba09f25e8
  1. 7
      Assets/Fungus/Scripts/Commands/ControlAudio.cs
  2. 6
      Assets/Fungus/Scripts/Commands/ControlStage.cs
  3. 9
      Assets/Fungus/Scripts/Commands/FadeUI.cs
  4. 6
      Assets/Fungus/Scripts/Commands/Jump.cs
  5. 3
      Assets/Fungus/Scripts/Commands/Say.cs
  6. 3
      Assets/Fungus/Scripts/Commands/SendMessage.cs
  7. 12
      Assets/Fungus/Scripts/Commands/SetCollider.cs
  8. 16
      Assets/Fungus/Scripts/Commands/SetInteractable.cs
  9. 8
      Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs
  10. 3
      Assets/Fungus/Scripts/Commands/ShowSprite.cs
  11. 4
      Assets/Fungus/Scripts/Commands/StopFlowchart.cs
  12. 14
      Assets/Fungus/Scripts/Commands/TweenUI.cs
  13. 3
      Assets/Fungus/Scripts/Commands/iTweenCommand.cs
  14. 21
      Assets/Fungus/Scripts/Components/Block.cs
  15. 2
      Assets/Fungus/Scripts/Components/CameraManager.cs
  16. 3
      Assets/Fungus/Scripts/Components/Clickable2D.cs
  17. 3
      Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs
  18. 3
      Assets/Fungus/Scripts/Components/DialogInput.cs
  19. 22
      Assets/Fungus/Scripts/Components/Draggable2D.cs
  20. 142
      Assets/Fungus/Scripts/Components/Flowchart.cs
  21. 35
      Assets/Fungus/Scripts/Components/Localization.cs
  22. 51
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  23. 11
      Assets/Fungus/Scripts/Components/SayDialog.cs
  24. 4
      Assets/Fungus/Scripts/Components/SpriteFader.cs
  25. 24
      Assets/Fungus/Scripts/Components/Writer.cs
  26. 13
      Assets/Fungus/Scripts/Utils/TextTagParser.cs

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

@ -66,11 +66,12 @@ namespace Fungus
} }
var audioSources = GameObject.FindObjectsOfType<AudioSource>(); var audioSources = GameObject.FindObjectsOfType<AudioSource>();
foreach (var a in audioSources) for (int i = 0; i < audioSources.Length; i++)
{ {
if ((a.GetComponent<AudioSource>() != _audioSource.Value) && (a.tag == _audioSource.Value.tag)) var a = audioSources[i];
if (a != _audioSource.Value && a.tag == _audioSource.Value.tag)
{ {
StopLoop(a.GetComponent<AudioSource>()); StopLoop(a);
} }
} }
} }

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

@ -73,8 +73,9 @@ namespace Fungus
protected virtual void MoveToFront(Stage stage) protected virtual void MoveToFront(Stage stage)
{ {
var activeStages = Stage.ActiveStages; var activeStages = Stage.ActiveStages;
foreach (var s in activeStages) for (int i = 0; i < activeStages.Count; i++)
{ {
var s = activeStages[i];
if (s == stage) if (s == stage)
{ {
s.PortraitCanvas.sortingOrder = 1; s.PortraitCanvas.sortingOrder = 1;
@ -90,8 +91,9 @@ namespace Fungus
{ {
stage.DimPortraits = false; stage.DimPortraits = false;
var charactersOnStage = stage.CharactersOnStage; var charactersOnStage = stage.CharactersOnStage;
foreach (var character in charactersOnStage) for (int i = 0; i < charactersOnStage.Count; i++)
{ {
var character = charactersOnStage[i];
stage.SetDimmed(character, false); stage.SetDimmed(character, false);
} }
} }

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

@ -34,8 +34,9 @@ namespace Fungus
protected override void ApplyTween(GameObject go) protected override void ApplyTween(GameObject go)
{ {
var images = go.GetComponentsInChildren<Image>(); var images = go.GetComponentsInChildren<Image>();
foreach (var image in images) for (int i = 0; i < images.Length; i++)
{ {
var image = images[i];
if (Mathf.Approximately(duration, 0f)) if (Mathf.Approximately(duration, 0f))
{ {
switch (fadeMode) switch (fadeMode)
@ -65,8 +66,9 @@ namespace Fungus
} }
var texts = go.GetComponentsInChildren<Text>(); var texts = go.GetComponentsInChildren<Text>();
foreach (var text in texts) for (int i = 0; i < texts.Length; i++)
{ {
var text = texts[i];
if (Mathf.Approximately(duration, 0f)) if (Mathf.Approximately(duration, 0f))
{ {
switch (fadeMode) switch (fadeMode)
@ -96,8 +98,9 @@ namespace Fungus
} }
var textMeshes = go.GetComponentsInChildren<TextMesh>(); var textMeshes = go.GetComponentsInChildren<TextMesh>();
foreach (var textMesh in textMeshes) for (int i = 0; i < textMeshes.Length; i++)
{ {
var textMesh = textMeshes[i];
if (Mathf.Approximately(duration, 0f)) if (Mathf.Approximately(duration, 0f))
{ {
switch (fadeMode) switch (fadeMode)

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

@ -30,11 +30,11 @@ namespace Fungus
} }
var commandList = ParentBlock.CommandList; var commandList = ParentBlock.CommandList;
foreach (var command in commandList) for (int i = 0; i < commandList.Count; i++)
{ {
var command = commandList[i];
Label label = command as Label; Label label = command as Label;
if (label != null && if (label != null && label.Key == _targetLabel.Value)
label.Key == _targetLabel.Value)
{ {
Continue(label.CommandIndex + 1); Continue(label.CommandIndex + 1);
return; return;

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

@ -108,8 +108,9 @@ namespace Fungus
string displayText = storyText; string displayText = storyText;
var activeCustomTags = CustomTag.activeCustomTags; var activeCustomTags = CustomTag.activeCustomTags;
foreach (var ct in activeCustomTags) for (int i = 0; i < activeCustomTags.Count; i++)
{ {
var ct = activeCustomTags[i];
displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith); displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith);
if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "") if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "")
{ {

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

@ -59,8 +59,9 @@ namespace Fungus
if (receivers != null) if (receivers != null)
{ {
foreach (var receiver in receivers) for (int i = 0; i < receivers.Length; i++)
{ {
var receiver = receivers[i];
receiver.OnSendFungusMessage(_message.Value); receiver.OnSendFungusMessage(_message.Value);
} }
} }

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

@ -30,15 +30,17 @@ namespace Fungus
{ {
// 3D objects // 3D objects
var colliders = go.GetComponentsInChildren<Collider>(); var colliders = go.GetComponentsInChildren<Collider>();
foreach (var c in colliders) for (int i = 0; i < colliders.Length; i++)
{ {
var c = colliders[i];
c.enabled = activeState.Value; c.enabled = activeState.Value;
} }
// 2D objects // 2D objects
var collider2Ds = go.GetComponentsInChildren<Collider2D>(); var collider2Ds = go.GetComponentsInChildren<Collider2D>();
foreach (var c in collider2Ds) for (int i = 0; i < collider2Ds.Length; i++)
{ {
var c = collider2Ds[i];
c.enabled = activeState.Value; c.enabled = activeState.Value;
} }
} }
@ -48,8 +50,9 @@ namespace Fungus
public override void OnEnter() public override void OnEnter()
{ {
foreach (var go in targetObjects) for (int i = 0; i < targetObjects.Count; i++)
{ {
var go = targetObjects[i];
SetColliderActive(go); SetColliderActive(go);
} }
@ -65,8 +68,9 @@ namespace Fungus
if (taggedObjects != null) if (taggedObjects != null)
{ {
foreach (var go in taggedObjects) for (int i = 0; i < taggedObjects.Length; i++)
{ {
var go = taggedObjects[i];
SetColliderActive(go); SetColliderActive(go);
} }
} }

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

@ -31,11 +31,13 @@ namespace Fungus
return; return;
} }
foreach (var targetObject in targetObjects) for (int i = 0; i < targetObjects.Count; i++)
{ {
var targetObject = targetObjects[i];
var selectables = targetObject.GetComponents<Selectable>(); var selectables = targetObject.GetComponents<Selectable>();
foreach (var selectable in selectables) for (int j = 0; j < selectables.Length; j++)
{ {
var selectable = selectables[j];
selectable.interactable = interactableState.Value; selectable.interactable = interactableState.Value;
} }
} }
@ -59,20 +61,20 @@ namespace Fungus
} }
string objectList = ""; string objectList = "";
foreach (var gameObject in targetObjects) for (int i = 0; i < targetObjects.Count; i++)
{ {
if (gameObject == null) var go = targetObjects[i];
if (go == null)
{ {
continue; continue;
} }
if (objectList == "") if (objectList == "")
{ {
objectList += gameObject.name; objectList += go.name;
} }
else else
{ {
objectList += ", " + gameObject.name; objectList += ", " + go.name;
} }
} }

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

@ -25,8 +25,9 @@ namespace Fungus
public override void OnEnter() public override void OnEnter()
{ {
foreach (var spriteRenderer in targetSprites) for (int i = 0; i < targetSprites.Count; i++)
{ {
var spriteRenderer = targetSprites[i];
spriteRenderer.sortingOrder = orderInLayer; spriteRenderer.sortingOrder = orderInLayer;
} }
@ -36,18 +37,17 @@ namespace Fungus
public override string GetSummary() public override string GetSummary()
{ {
string summary = ""; string summary = "";
foreach (var spriteRenderer in targetSprites) for (int i = 0; i < targetSprites.Count; i++)
{ {
var spriteRenderer = targetSprites[i];
if (spriteRenderer == null) if (spriteRenderer == null)
{ {
continue; continue;
} }
if (summary.Length > 0) if (summary.Length > 0)
{ {
summary += ", "; summary += ", ";
} }
summary += spriteRenderer.name; summary += spriteRenderer.name;
} }

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

@ -41,8 +41,9 @@ namespace Fungus
if (affectChildren) if (affectChildren)
{ {
var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>(); var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (var sr in spriteRenderers) for (int i = 0; i < spriteRenderers.Length; i++)
{ {
var sr = spriteRenderers[i];
SetSpriteAlpha(sr, _visible.Value); SetSpriteAlpha(sr, _visible.Value);
} }
} }

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

@ -32,14 +32,14 @@ namespace Fungus
flowchart.StopAllBlocks(); flowchart.StopAllBlocks();
} }
foreach (var f in targetFlowcharts) for (int i = 0; i < targetFlowcharts.Count; i++)
{ {
var f = targetFlowcharts[i];
if (f == flowchart) if (f == flowchart)
{ {
// Flowchart has already been stopped // Flowchart has already been stopped
continue; continue;
} }
f.StopAllBlocks(); f.StopAllBlocks();
} }
} }

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

@ -26,13 +26,13 @@ namespace Fungus
protected virtual void ApplyTween() protected virtual void ApplyTween()
{ {
foreach (var targetObject in targetObjects) for (int i = 0; i < targetObjects.Count; i++)
{ {
var targetObject = targetObjects[i];
if (targetObject == null) if (targetObject == null)
{ {
continue; continue;
} }
ApplyTween(targetObject); ApplyTween(targetObject);
} }
@ -97,20 +97,20 @@ namespace Fungus
} }
string objectList = ""; string objectList = "";
foreach (var gameObject in targetObjects) for (int i = 0; i < targetObjects.Count; i++)
{ {
if (gameObject == null) var go = targetObjects[i];
if (go == null)
{ {
continue; continue;
} }
if (objectList == "") if (objectList == "")
{ {
objectList += gameObject.name; objectList += go.name;
} }
else else
{ {
objectList += ", " + gameObject.name; objectList += ", " + go.name;
} }
} }

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

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

21
Assets/Fungus/Scripts/Components/Block.cs

@ -72,13 +72,13 @@ namespace Fungus
// Give each child command a reference back to its parent block // Give each child command a reference back to its parent block
// and tell each command its index in the list. // and tell each command its index in the list.
int index = 0; int index = 0;
foreach (var command in commandList) for (int i = 0; i < commandList.Count; i++)
{ {
var command = commandList[i];
if (command == null) if (command == null)
{ {
continue; continue;
} }
command.ParentBlock = this; command.ParentBlock = this;
command.CommandIndex = index++; command.CommandIndex = index++;
} }
@ -98,13 +98,14 @@ namespace Fungus
protected virtual void Update() protected virtual void Update()
{ {
int index = 0; int index = 0;
foreach (var command in commandList) for (int i = 0; i < commandList.Count; i++)
{ {
if (command == null) // Null entry will be deleted automatically later var command = commandList[i];
if (command == null)// Null entry will be deleted automatically later
{ {
continue; continue;
} }
command.CommandIndex = index++; command.CommandIndex = index++;
} }
} }
@ -328,8 +329,9 @@ namespace Fungus
public virtual List<Block> GetConnectedBlocks() public virtual List<Block> GetConnectedBlocks()
{ {
var connectedBlocks = new List<Block>(); var connectedBlocks = new List<Block>();
foreach (var command in commandList) for (int i = 0; i < commandList.Count; i++)
{ {
var command = commandList[i];
if (command != null) if (command != null)
{ {
command.GetConnectedBlocks(ref connectedBlocks); command.GetConnectedBlocks(ref connectedBlocks);
@ -359,23 +361,20 @@ namespace Fungus
public virtual void UpdateIndentLevels() public virtual void UpdateIndentLevels()
{ {
int indentLevel = 0; int indentLevel = 0;
foreach (var command in commandList) for (int i = 0; i < commandList.Count; i++)
{ {
var command = commandList[i];
if (command == null) if (command == null)
{ {
continue; continue;
} }
if (command.CloseBlock()) if (command.CloseBlock())
{ {
indentLevel--; indentLevel--;
} }
// Negative indent level is not permitted // Negative indent level is not permitted
indentLevel = Math.Max(indentLevel, 0); indentLevel = Math.Max(indentLevel, 0);
command.IndentLevel = indentLevel; command.IndentLevel = indentLevel;
if (command.OpenBlock()) if (command.OpenBlock())
{ {
indentLevel++; indentLevel++;

2
Assets/Fungus/Scripts/Components/CameraManager.cs

@ -155,9 +155,9 @@ namespace Fungus
camera.orthographicSize = Mathf.Lerp(startSize, endSize, Mathf.SmoothStep(0f, 1f, t)); camera.orthographicSize = Mathf.Lerp(startSize, endSize, Mathf.SmoothStep(0f, 1f, t));
camera.transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0f, 1f, t)); camera.transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0f, 1f, t));
camera.transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0f, 1f, t)); camera.transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0f, 1f, t));
}
SetCameraZ(camera); SetCameraZ(camera);
}
if (arrived && if (arrived &&
arriveAction != null) arriveAction != null)

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

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

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

@ -63,8 +63,9 @@ namespace Fungus
public virtual void Clear() public virtual void Clear()
{ {
var commands = GetCommands(); var commands = GetCommands();
foreach (var command in commands) for (int i = 0; i < commands.Length; i++)
{ {
var command = commands[i];
DestroyImmediate(command); DestroyImmediate(command);
} }
} }

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

@ -115,8 +115,9 @@ namespace Fungus
if (nextLineInputFlag) if (nextLineInputFlag)
{ {
var inputListeners = gameObject.GetComponentsInChildren<IDialogInputListener>(); var inputListeners = gameObject.GetComponentsInChildren<IDialogInputListener>();
foreach (var inputListener in inputListeners) for (int i = 0; i < inputListeners.Length; i++)
{ {
var inputListener = inputListeners[i];
inputListener.OnNextLineEvent(); inputListener.OnNextLineEvent();
} }
nextLineInputFlag = false; nextLineInputFlag = false;

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

@ -59,14 +59,16 @@ namespace Fungus
} }
var dragEnteredHandlers = GetHandlers<DragEntered>(); var dragEnteredHandlers = GetHandlers<DragEntered>();
foreach (var handler in dragEnteredHandlers) for (int i = 0; i < dragEnteredHandlers.Length; i++)
{ {
var handler = dragEnteredHandlers[i];
handler.OnDragEntered(this, other); handler.OnDragEntered(this, other);
} }
var dragCompletedHandlers = GetHandlers<DragCompleted>(); var dragCompletedHandlers = GetHandlers<DragCompleted>();
foreach (var handler in dragCompletedHandlers) for (int i = 0; i < dragCompletedHandlers.Length; i++)
{ {
var handler = dragCompletedHandlers[i];
handler.OnDragEntered(this, other); handler.OnDragEntered(this, other);
} }
} }
@ -79,14 +81,16 @@ namespace Fungus
} }
var dragExitedHandlers = GetHandlers<DragExited>(); var dragExitedHandlers = GetHandlers<DragExited>();
foreach (var handler in dragExitedHandlers) for (int i = 0; i < dragExitedHandlers.Length; i++)
{ {
var handler = dragExitedHandlers[i];
handler.OnDragExited(this, other); handler.OnDragExited(this, other);
} }
var dragCompletedHandlers = GetHandlers<DragCompleted>(); var dragCompletedHandlers = GetHandlers<DragCompleted>();
foreach (var handler in dragCompletedHandlers) for (int i = 0; i < dragCompletedHandlers.Length; i++)
{ {
var handler = dragCompletedHandlers[i];
handler.OnDragExited(this, other); handler.OnDragExited(this, other);
} }
} }
@ -108,8 +112,9 @@ namespace Fungus
startingPosition = transform.position; startingPosition = transform.position;
var dragStartedHandlers = GetHandlers<DragStarted>(); var dragStartedHandlers = GetHandlers<DragStarted>();
foreach (var handler in dragStartedHandlers) for (int i = 0; i < dragStartedHandlers.Length; i++)
{ {
var handler = dragStartedHandlers[i];
handler.OnDragStarted(this); handler.OnDragStarted(this);
} }
} }
@ -140,15 +145,15 @@ namespace Fungus
bool dragCompleted = false; bool dragCompleted = false;
var handlers = GetHandlers<DragCompleted>(); var handlers = GetHandlers<DragCompleted>();
foreach (var handler in handlers) for (int i = 0; i < handlers.Length; i++)
{ {
var handler = handlers[i];
if (handler.DraggableObject == this) if (handler.DraggableObject == this)
{ {
if (handler.IsOverTarget()) if (handler.IsOverTarget())
{ {
handler.OnDragCompleted(this); handler.OnDragCompleted(this);
dragCompleted = true; dragCompleted = true;
if (returnOnCompleted) if (returnOnCompleted)
{ {
LeanTween.move(gameObject, startingPosition, returnDuration).setEase(LeanTweenType.easeOutExpo); LeanTween.move(gameObject, startingPosition, returnDuration).setEase(LeanTweenType.easeOutExpo);
@ -160,8 +165,9 @@ namespace Fungus
if (!dragCompleted) if (!dragCompleted)
{ {
var dragCancelledHandlers = GetHandlers<DragCancelled>(); var dragCancelledHandlers = GetHandlers<DragCancelled>();
foreach (var handler in dragCancelledHandlers) for (int i = 0; i < dragCancelledHandlers.Length; i++)
{ {
var handler = dragCancelledHandlers[i];
handler.OnDragCancelled(this); handler.OnDragCancelled(this);
} }

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

@ -159,8 +159,9 @@ 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
var components = GetComponents<Component>(); var components = GetComponents<Component>();
foreach (var component in components) for (int i = 0; i < components.Length; i++)
{ {
var component = components[i];
IUpdateable u = component as IUpdateable; IUpdateable u = component as IUpdateable;
if (u != null) if (u != null)
{ {
@ -182,10 +183,10 @@ namespace Fungus
// This should always be the case, but some legacy Flowcharts may have issues. // This should always be the case, but some legacy Flowcharts may have issues.
List<int> usedIds = new List<int>(); List<int> usedIds = new List<int>();
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
if (block.ItemId == -1 || var block = blocks[i];
usedIds.Contains(block.ItemId)) if (block.ItemId == -1 || usedIds.Contains(block.ItemId))
{ {
block.ItemId = NextItemId(); block.ItemId = NextItemId();
} }
@ -193,10 +194,10 @@ namespace Fungus
} }
var commands = GetComponents<Command>(); var commands = GetComponents<Command>();
foreach (var command in commands) for (int i = 0; i < commands.Length; i++)
{ {
if (command.ItemId == -1 || var command = commands[i];
usedIds.Contains(command.ItemId)) if (command.ItemId == -1 || usedIds.Contains(command.ItemId))
{ {
command.ItemId = NextItemId(); command.ItemId = NextItemId();
} }
@ -215,8 +216,9 @@ namespace Fungus
variables.RemoveAll(item => item == null); variables.RemoveAll(item => item == null);
var allVariables = GetComponents<Variable>(); var allVariables = GetComponents<Variable>();
foreach (var variable in allVariables) for (int i = 0; i < allVariables.Length; i++)
{ {
var variable = allVariables[i];
if (!variables.Contains(variable)) if (!variables.Contains(variable))
{ {
DestroyImmediate(variable); DestroyImmediate(variable);
@ -225,18 +227,19 @@ namespace Fungus
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
var commands = GetComponents<Command>(); var commands = GetComponents<Command>();
foreach (var command in commands) for (int i = 0; i < commands.Length; i++)
{ {
var command = commands[i];
bool found = false; bool found = false;
foreach (var block in blocks) for (int j = 0; j < blocks.Length; j++)
{ {
var block = blocks[j];
if (block.CommandList.Contains(command)) if (block.CommandList.Contains(command))
{ {
found = true; found = true;
break; break;
} }
} }
if (!found) if (!found)
{ {
DestroyImmediate(command); DestroyImmediate(command);
@ -244,18 +247,19 @@ namespace Fungus
} }
var eventHandlers = GetComponents<EventHandler>(); var eventHandlers = GetComponents<EventHandler>();
foreach (var eventHandler in eventHandlers) for (int i = 0; i < eventHandlers.Length; i++)
{ {
var eventHandler = eventHandlers[i];
bool found = false; bool found = false;
foreach (var block in blocks) for (int j = 0; j < blocks.Length; j++)
{ {
var block = blocks[j];
if (block._EventHandler == eventHandler) if (block._EventHandler == eventHandler)
{ {
found = true; found = true;
break; break;
} }
} }
if (!found) if (!found)
{ {
DestroyImmediate(eventHandler); DestroyImmediate(eventHandler);
@ -283,8 +287,9 @@ namespace Fungus
public static void BroadcastFungusMessage(string messageName) public static void BroadcastFungusMessage(string messageName)
{ {
var eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>(); var eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>();
foreach (var eventHandler in eventHandlers) for (int i = 0; i < eventHandlers.Length; i++)
{ {
var eventHandler = eventHandlers[i];
eventHandler.OnSendFungusMessage(messageName); eventHandler.OnSendFungusMessage(messageName);
} }
} }
@ -409,14 +414,16 @@ namespace Fungus
{ {
int maxId = -1; int maxId = -1;
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
var block = blocks[i];
maxId = Math.Max(maxId, block.ItemId); maxId = Math.Max(maxId, block.ItemId);
} }
var commands = GetComponents<Command>(); var commands = GetComponents<Command>();
foreach (var command in commands) for (int i = 0; i < commands.Length; i++)
{ {
var command = commands[i];
maxId = Math.Max(maxId, command.ItemId); maxId = Math.Max(maxId, command.ItemId);
} }
return maxId + 1; return maxId + 1;
@ -441,8 +448,9 @@ namespace Fungus
public virtual Block FindBlock(string blockName) public virtual Block FindBlock(string blockName)
{ {
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
var block = blocks[i];
if (block.BlockName == blockName) if (block.BlockName == blockName)
{ {
return block; return block;
@ -509,8 +517,9 @@ namespace Fungus
public virtual void StopAllBlocks() public virtual void StopAllBlocks()
{ {
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
var block = blocks[i];
if (block.IsExecuting()) if (block.IsExecuting())
{ {
block.Stop(); block.Stop();
@ -525,8 +534,9 @@ namespace Fungus
public virtual void SendFungusMessage(string messageName) public virtual void SendFungusMessage(string messageName)
{ {
var eventHandlers = GetComponents<MessageReceived>(); var eventHandlers = GetComponents<MessageReceived>();
foreach (var eventHandler in eventHandlers) for (int i = 0; i < eventHandlers.Length; i++)
{ {
var eventHandler = eventHandlers[i];
eventHandler.OnSendFungusMessage(messageName); eventHandler.OnSendFungusMessage(messageName);
} }
} }
@ -556,15 +566,13 @@ namespace Fungus
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach(var variable in variables) for (int i = 0; i < variables.Count; i++)
{ {
if (variable == null || var variable = variables[i];
variable == ignoreVariable || if (variable == null || variable == ignoreVariable || variable.Key == null)
variable.Key == null)
{ {
continue; continue;
} }
if (variable.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) if (variable.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{ {
collision = true; collision = true;
@ -600,14 +608,13 @@ namespace Fungus
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
if (block == ignoreBlock || var block = blocks[i];
block.BlockName == null) if (block == ignoreBlock || block.BlockName == null)
{ {
continue; continue;
} }
if (block.BlockName.Equals(key, StringComparison.CurrentCultureIgnoreCase)) if (block.BlockName.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{ {
collision = true; collision = true;
@ -644,15 +651,14 @@ namespace Fungus
{ {
bool collision = false; bool collision = false;
var commandList = block.CommandList; var commandList = block.CommandList;
foreach (var command in commandList) for (int i = 0; i < commandList.Count; i++)
{ {
var command = commandList[i];
Label label = command as Label; Label label = command as Label;
if (label == null || if (label == null || label == ignoreLabel)
label == ignoreLabel)
{ {
continue; continue;
} }
if (label.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) if (label.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{ {
collision = true; collision = true;
@ -677,8 +683,9 @@ namespace Fungus
/// </summary> /// </summary>
public Variable GetVariable(string key) public Variable GetVariable(string key)
{ {
foreach (var variable in variables) for (int i = 0; i < variables.Count; i++)
{ {
var variable = variables[i];
if (variable != null && variable.Key == key) if (variable != null && variable.Key == key)
{ {
return variable; return variable;
@ -696,8 +703,9 @@ namespace Fungus
/// </summary> /// </summary>
public T GetVariable<T>(string key) where T : Variable public T GetVariable<T>(string key) where T : Variable
{ {
foreach (var variable in variables) for (int i = 0; i < variables.Count; i++)
{ {
var variable = variables[i];
if (variable != null && variable.Key == key) if (variable != null && variable.Key == key)
{ {
return variable as T; return variable as T;
@ -714,8 +722,9 @@ 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 (var v in variables) for (int i = 0; i < variables.Count; i++)
{ {
var v = variables[i];
if (v != null && v.Key == key) if (v != null && v.Key == key)
{ {
T variable = v as T; T variable = v as T;
@ -735,9 +744,10 @@ namespace Fungus
/// </summary> /// </summary>
public virtual List<Variable> GetPublicVariables() public virtual List<Variable> GetPublicVariables()
{ {
List<Variable> publicVariables = new List<Variable>(); var publicVariables = new List<Variable>();
foreach (var v in variables) for (int i = 0; i < variables.Count; i++)
{ {
var v = variables[i];
if (v != null && v.Scope == VariableScope.Public) if (v != null && v.Scope == VariableScope.Public)
{ {
publicVariables.Add(v); publicVariables.Add(v);
@ -879,8 +889,9 @@ namespace Fungus
if (hideComponents) if (hideComponents)
{ {
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
var block = blocks[i];
block.hideFlags = HideFlags.HideInInspector; block.hideFlags = HideFlags.HideInInspector;
if (block.gameObject != gameObject) if (block.gameObject != gameObject)
{ {
@ -889,27 +900,29 @@ namespace Fungus
} }
var commands = GetComponents<Command>(); var commands = GetComponents<Command>();
foreach (var command in commands) for (int i = 0; i < commands.Length; i++)
{ {
var command = commands[i];
command.hideFlags = HideFlags.HideInInspector; command.hideFlags = HideFlags.HideInInspector;
} }
var eventHandlers = GetComponents<EventHandler>(); var eventHandlers = GetComponents<EventHandler>();
foreach (var eventHandler in eventHandlers) for (int i = 0; i < eventHandlers.Length; i++)
{ {
var eventHandler = eventHandlers[i];
eventHandler.hideFlags = HideFlags.HideInInspector; eventHandler.hideFlags = HideFlags.HideInInspector;
} }
} }
else else
{ {
var monoBehaviours = GetComponents<MonoBehaviour>(); var monoBehaviours = GetComponents<MonoBehaviour>();
foreach (var monoBehaviour in monoBehaviours) for (int i = 0; i < monoBehaviours.Length; i++)
{ {
var monoBehaviour = monoBehaviours[i];
if (monoBehaviour == null) if (monoBehaviour == null)
{ {
continue; continue;
} }
monoBehaviour.hideFlags = HideFlags.None; monoBehaviour.hideFlags = HideFlags.None;
monoBehaviour.gameObject.hideFlags = HideFlags.None; monoBehaviour.gameObject.hideFlags = HideFlags.None;
} }
@ -943,16 +956,18 @@ namespace Fungus
if (resetCommands) if (resetCommands)
{ {
var commands = GetComponents<Command>(); var commands = GetComponents<Command>();
foreach (var command in commands) for (int i = 0; i < commands.Length; i++)
{ {
var command = commands[i];
command.OnReset(); command.OnReset();
} }
} }
if (resetVariables) if (resetVariables)
{ {
foreach (var variable in variables) for (int i = 0; i < variables.Count; i++)
{ {
var variable = variables[i];
variable.OnReset(); variable.OnReset();
} }
} }
@ -963,11 +978,11 @@ namespace Fungus
/// </summary> /// </summary>
public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo) public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo)
{ {
foreach (var key in hideCommands) for (int i = 0; i < hideCommands.Count; i++)
{ {
// 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 || var key = hideCommands[i];
String.Compare(commandInfo.CommandName, key, StringComparison.OrdinalIgnoreCase) == 0) if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(commandInfo.CommandName, key, StringComparison.OrdinalIgnoreCase) == 0)
{ {
return false; return false;
} }
@ -982,8 +997,9 @@ namespace Fungus
public virtual bool HasExecutingBlocks() public virtual bool HasExecutingBlocks()
{ {
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
var block = blocks[i];
if (block.IsExecuting()) if (block.IsExecuting())
{ {
return true; return true;
@ -999,8 +1015,9 @@ namespace Fungus
{ {
var executingBlocks = new List<Block>(); var executingBlocks = new List<Block>();
var blocks = GetComponents<Block>(); var blocks = GetComponents<Block>();
foreach (var block in blocks) for (int i = 0; i < blocks.Length; i++)
{ {
var block = blocks[i];
if (block.IsExecuting()) if (block.IsExecuting())
{ {
executingBlocks.Add(block); executingBlocks.Add(block);
@ -1036,18 +1053,17 @@ namespace Fungus
// Match the regular expression pattern against a text string. // Match the regular expression pattern against a text string.
var results = r.Matches(input); var results = r.Matches(input);
foreach (Match match in results) for (int i = 0; i < results.Count; i++)
{ {
Match match = results[i];
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 (var variable in variables) for (int j = 0; j < variables.Count; j++)
{ {
var variable = variables[j];
if (variable == null) if (variable == null)
continue; continue;
if (variable.Scope == VariableScope.Private && variable.Key == key)
if (variable.Scope == VariableScope.Private &&
variable.Key == key)
{ {
string value = variable.ToString(); string value = variable.ToString();
sb.Replace(match.Value, value); sb.Replace(match.Value, value);
@ -1088,22 +1104,22 @@ namespace Fungus
// Match the regular expression pattern against a text string. // Match the regular expression pattern against a text string.
var results = r.Matches(input.ToString()); var results = r.Matches(input.ToString());
foreach (Match match in results) for (int i = 0; i < results.Count; i++)
{ {
Match match = results[i];
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 (var variable in variables) for (int j = 0; j < variables.Count; j++)
{ {
var variable = variables[j];
if (variable == null) if (variable == null)
{
continue; continue;
}
if (variable.Scope == VariableScope.Public && if (variable.Scope == VariableScope.Public && variable.Key == key)
variable.Key == key)
{ {
string value = variable.ToString(); string value = variable.ToString();
input.Replace(match.Value, value); input.Replace(match.Value, value);
modified = true; modified = true;
} }
} }

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

@ -96,8 +96,9 @@ 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 (var o in objects) for (int i = 0; i < objects.Length; i++)
{ {
var o = objects[i];
ILocalizable localizable = o as ILocalizable; ILocalizable localizable = o as ILocalizable;
if (localizable != null) if (localizable != null)
{ {
@ -116,14 +117,18 @@ namespace Fungus
// Add localizable commands in same order as command list to make it // Add localizable commands in same order as command list to make it
// easier to localise / edit standard text. // easier to localise / edit standard text.
var flowcharts = GameObject.FindObjectsOfType<Flowchart>(); var flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (var flowchart in flowcharts) for (int i = 0; i < flowcharts.Length; i++)
{ {
var flowchart = flowcharts[i];
var blocks = flowchart.GetComponents<Block>(); var blocks = flowchart.GetComponents<Block>();
foreach (var block in blocks)
for (int j = 0; j < blocks.Length; j++)
{ {
var block = blocks[j];
var commandList = block.CommandList; var commandList = block.CommandList;
foreach (var command in commandList) for (int k = 0; k < commandList.Count; k++)
{ {
var command = commandList[k];
ILocalizable localizable = command as ILocalizable; ILocalizable localizable = command as ILocalizable;
if (localizable != null) if (localizable != null)
{ {
@ -138,8 +143,9 @@ 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 (var o in objects) for (int i = 0; i < objects.Length; i++)
{ {
var o = objects[i];
ILocalizable localizable = o as ILocalizable; ILocalizable localizable = o as ILocalizable;
if (localizable != null) if (localizable != null)
{ {
@ -149,7 +155,6 @@ namespace Fungus
// Already added // Already added
continue; continue;
} }
TextItem textItem = new TextItem(); TextItem textItem = new TextItem();
textItem.standardText = localizable.GetStandardText(); textItem.standardText = localizable.GetStandardText();
textItem.description = localizable.GetDescription(); textItem.description = localizable.GetDescription();
@ -289,7 +294,7 @@ 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>(); var languageCodes = new List<string>();
var values = textItems.Values; var values = textItems.Values;
foreach (var textItem in values) foreach (var textItem in values)
{ {
@ -315,15 +320,17 @@ namespace Fungus
row += "," + CSVSupport.Escape(textItem.description); row += "," + CSVSupport.Escape(textItem.description);
row += "," + CSVSupport.Escape(textItem.standardText); row += "," + CSVSupport.Escape(textItem.standardText);
foreach (var languageCode in languageCodes) for (int i = 0; i < languageCodes.Count; i++)
{ {
var languageCode = languageCodes[i];
if (textItem.localizedStrings.ContainsKey(languageCode)) if (textItem.localizedStrings.ContainsKey(languageCode))
{ {
row += "," + CSVSupport.Escape(textItem.localizedStrings[languageCode]); row += "," + CSVSupport.Escape(textItem.localizedStrings[languageCode]);
} }
else else
{ {
row += ","; // Empty field row += ",";
// Empty field
} }
} }
@ -485,15 +492,16 @@ namespace Fungus
/// </summary> /// </summary>
public virtual void SetStandardText(string textData) public virtual void SetStandardText(string textData)
{ {
string[] lines = textData.Split('\n'); var lines = textData.Split('\n');
int updatedCount = 0; int updatedCount = 0;
string stringId = ""; string stringId = "";
string buffer = ""; string buffer = "";
foreach (var line in lines) for (int i = 0; i < lines.Length; i++)
{ {
// Check for string id line // Check for string id line
var line = lines[i];
if (line.StartsWith("#")) if (line.StartsWith("#"))
{ {
if (stringId.Length > 0) if (stringId.Length > 0)
@ -504,7 +512,6 @@ namespace Fungus
updatedCount++; updatedCount++;
} }
} }
// Set the string id for the follow text lines // Set the string id for the follow text lines
stringId = line.Substring(1, line.Length - 1); stringId = line.Substring(1, line.Length - 1);
buffer = ""; buffer = "";
@ -544,10 +551,10 @@ namespace Fungus
// Match the regular expression pattern against a text string. // Match the regular expression pattern against a text string.
var results = r.Matches(input.ToString()); var results = r.Matches(input.ToString());
foreach (Match match in results) for (int i = 0; i < results.Count; i++)
{ {
Match match = results[i];
string key = match.Value.Substring(2, match.Value.Length - 3); string key = match.Value.Substring(2, match.Value.Length - 3);
// Next look for matching localized string // Next look for matching localized string
string localizedString = Localization.GetLocalizedString(key); string localizedString = Localization.GetLocalizedString(key);
if (localizedString != null) if (localizedString != null)

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

@ -154,14 +154,16 @@ namespace Fungus
{ {
StopAllCoroutines(); StopAllCoroutines();
Button[] optionButtons = GetComponentsInChildren<Button>(); var optionButtons = GetComponentsInChildren<Button>();
foreach (var button in optionButtons) for (int i = 0; i < optionButtons.Length; i++)
{ {
var button = optionButtons[i];
button.onClick.RemoveAllListeners(); button.onClick.RemoveAllListeners();
} }
foreach (var button in optionButtons) for (int i = 0; i < optionButtons.Length; i++)
{ {
var button = optionButtons[i];
if (button != null) if (button != null)
{ {
button.gameObject.SetActive(false); button.gameObject.SetActive(false);
@ -198,53 +200,43 @@ 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 (var button in cachedButtons) for (int i = 0; i < cachedButtons.Length; i++)
{ {
var button = cachedButtons[i];
if (!button.gameObject.activeSelf) if (!button.gameObject.activeSelf)
{ {
button.gameObject.SetActive(true); button.gameObject.SetActive(true);
button.interactable = interactable; button.interactable = interactable;
if (interactable && autoSelectFirstButton && !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
if (interactable && autoSelectFirstButton && !cachedButtons.Select((x) => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
{ {
EventSystem.current.SetSelectedGameObject(button.gameObject); EventSystem.current.SetSelectedGameObject(button.gameObject);
} }
Text textComponent = button.GetComponentInChildren<Text>(); Text textComponent = button.GetComponentInChildren<Text>();
if (textComponent != null) if (textComponent != null)
{ {
textComponent.text = text; textComponent.text = text;
} }
var block = targetBlock; var block = targetBlock;
button.onClick.AddListener(delegate
button.onClick.AddListener(delegate { {
EventSystem.current.SetSelectedGameObject(null); EventSystem.current.SetSelectedGameObject(null);
StopAllCoroutines();
StopAllCoroutines(); // Stop timeout // Stop timeout
Clear(); Clear();
HideSayDialog(); HideSayDialog();
if (block != null) if (block != null)
{ {
var flowchart = block.GetFlowchart(); var flowchart = block.GetFlowchart();
#if UNITY_EDITOR #if UNITY_EDITOR
// Select the new target block in the Flowchart window // Select the new target block in the Flowchart window
flowchart.SelectedBlock = block; flowchart.SelectedBlock = block;
#endif #endif
gameObject.SetActive(false); gameObject.SetActive(false);
// Use a coroutine to call the block on the next frame // Use a coroutine to call the block on the next frame
// Have to use the Flowchart gameobject as the MenuDialog is now inactive // Have to use the Flowchart gameobject as the MenuDialog is now inactive
flowchart.StartCoroutine(CallBlock(block)); flowchart.StartCoroutine(CallBlock(block));
} }
}); });
addedOption = true; addedOption = true;
break; break;
} }
@ -266,15 +258,14 @@ namespace Fungus
} }
bool addedOption = false; bool addedOption = false;
foreach (var button in CachedButtons) for (int i = 0; i < CachedButtons.Length; i++)
{ {
var button = CachedButtons[i];
if (!button.gameObject.activeSelf) if (!button.gameObject.activeSelf)
{ {
button.gameObject.SetActive(true); button.gameObject.SetActive(true);
button.interactable = interactable; button.interactable = interactable;
var textComponent = button.GetComponentInChildren<Text>();
Text textComponent = button.GetComponentInChildren<Text>();
if (textComponent != null) if (textComponent != null)
{ {
textComponent.text = text; textComponent.text = text;
@ -283,13 +274,12 @@ namespace Fungus
// Copy to local variables // Copy to local variables
LuaEnvironment env = luaEnv; LuaEnvironment env = luaEnv;
Closure call = callBack; Closure call = callBack;
button.onClick.AddListener(delegate
button.onClick.AddListener(delegate { {
StopAllCoroutines();
StopAllCoroutines(); // Stop timeout // Stop timeout
Clear(); Clear();
HideSayDialog(); HideSayDialog();
// Use a coroutine to call the callback on the next frame // Use a coroutine to call the callback on the next frame
StartCoroutine(CallLuaClosure(env, call)); StartCoroutine(CallLuaClosure(env, call));
}); });
@ -373,8 +363,9 @@ namespace Fungus
{ {
get { get {
int count = 0; int count = 0;
foreach (var button in cachedButtons) for (int i = 0; i < cachedButtons.Length; i++)
{ {
var button = cachedButtons[i];
if (button.gameObject.activeSelf) if (button.gameObject.activeSelf)
{ {
count++; count++;

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

@ -227,14 +227,14 @@ namespace Fungus
{ {
// Stop all tweening portraits // Stop all tweening portraits
var activeCharacters = Character.ActiveCharacters; var activeCharacters = Character.ActiveCharacters;
foreach (var c in activeCharacters) for (int i = 0; i < activeCharacters.Count; i++)
{ {
var c = activeCharacters[i];
if (c.State.portraitImage != null) if (c.State.portraitImage != null)
{ {
if (LeanTween.isTweening(c.State.portraitImage.gameObject)) if (LeanTween.isTweening(c.State.portraitImage.gameObject))
{ {
LeanTween.cancel(c.State.portraitImage.gameObject, true); LeanTween.cancel(c.State.portraitImage.gameObject, true);
PortraitController.SetRectTransform(c.State.portraitImage.rectTransform, c.State.position); PortraitController.SetRectTransform(c.State.portraitImage.rectTransform, c.State.position);
if (c.State.dimmed == true) if (c.State.dimmed == true)
{ {
@ -283,14 +283,15 @@ namespace Fungus
// Dim portraits of non-speaking characters // Dim portraits of non-speaking characters
var activeStages = Stage.ActiveStages; var activeStages = Stage.ActiveStages;
foreach (var stage in activeStages) for (int i = 0; i < activeStages.Count; i++)
{ {
var stage = activeStages[i];
if (stage.DimPortraits) if (stage.DimPortraits)
{ {
var charactersOnStage = stage.CharactersOnStage; var charactersOnStage = stage.CharactersOnStage;
foreach (var c in charactersOnStage) for (int j = 0; j < charactersOnStage.Count; j++)
{ {
var c = charactersOnStage[j];
if (prevSpeakingCharacter != speakingCharacter) if (prevSpeakingCharacter != speakingCharacter)
{ {
if (c != null && !c.Equals(speakingCharacter)) if (c != null && !c.Equals(speakingCharacter))

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

@ -78,13 +78,13 @@ namespace Fungus
// Fade child sprite renderers // Fade child sprite renderers
var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>(); var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (var sr in spriteRenderers) for (int i = 0; i < spriteRenderers.Length; i++)
{ {
var sr = spriteRenderers[i];
if (sr == spriteRenderer) if (sr == spriteRenderer)
{ {
continue; continue;
} }
FadeSprite(sr, targetColor, duration, slideOffset); FadeSprite(sr, targetColor, duration, slideOffset);
} }

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

@ -107,8 +107,9 @@ namespace Fungus
if (textUI == null && inputField == null && textMesh == null) if (textUI == null && inputField == null && textMesh == null)
{ {
var allcomponents = go.GetComponents<Component>(); var allcomponents = go.GetComponents<Component>();
foreach (var c in allcomponents) for (int i = 0; i < allcomponents.Length; i++)
{ {
var c = allcomponents[i];
textProperty = c.GetType().GetProperty("text"); textProperty = c.GetType().GetProperty("text");
if (textProperty != null) if (textProperty != null)
{ {
@ -120,8 +121,9 @@ namespace Fungus
// Cache the list of child writer listeners // Cache the list of child writer listeners
var allComponents = GetComponentsInChildren<Component>(); var allComponents = GetComponentsInChildren<Component>();
foreach (var component in allComponents) for (int i = 0; i < allComponents.Length; i++)
{ {
var component = allComponents[i];
IWriterListener writerListener = component as IWriterListener; IWriterListener writerListener = component as IWriterListener;
if (writerListener != null) if (writerListener != null)
{ {
@ -690,8 +692,9 @@ namespace Fungus
{ {
WriterSignals.DoWriterInput(this); WriterSignals.DoWriterInput(this);
foreach (var writerListener in writerListeners) for (int i = 0; i < writerListeners.Count; i++)
{ {
var writerListener = writerListeners[i];
writerListener.OnInput(); writerListener.OnInput();
} }
} }
@ -700,8 +703,9 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.Start); WriterSignals.DoWriterState(this, WriterState.Start);
foreach (var writerListener in writerListeners) for (int i = 0; i < writerListeners.Count; i++)
{ {
var writerListener = writerListeners[i];
writerListener.OnStart(audioClip); writerListener.OnStart(audioClip);
} }
} }
@ -710,8 +714,9 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.Pause); WriterSignals.DoWriterState(this, WriterState.Pause);
foreach (var writerListener in writerListeners) for (int i = 0; i < writerListeners.Count; i++)
{ {
var writerListener = writerListeners[i];
writerListener.OnPause(); writerListener.OnPause();
} }
} }
@ -720,8 +725,9 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.Resume); WriterSignals.DoWriterState(this, WriterState.Resume);
foreach (var writerListener in writerListeners) for (int i = 0; i < writerListeners.Count; i++)
{ {
var writerListener = writerListeners[i];
writerListener.OnResume(); writerListener.OnResume();
} }
} }
@ -730,8 +736,9 @@ namespace Fungus
{ {
WriterSignals.DoWriterState(this, WriterState.End); WriterSignals.DoWriterState(this, WriterState.End);
foreach (var writerListener in writerListeners) for (int i = 0; i < writerListeners.Count; i++)
{ {
var writerListener = writerListeners[i];
writerListener.OnEnd(stopAudio); writerListener.OnEnd(stopAudio);
} }
} }
@ -740,8 +747,9 @@ namespace Fungus
{ {
WriterSignals.DoWriterGlyph(this); WriterSignals.DoWriterGlyph(this);
foreach (var writerListener in writerListeners) for (int i = 0; i < writerListeners.Count; i++)
{ {
var writerListener = writerListeners[i];
writerListener.OnGlyph(); writerListener.OnGlyph();
} }
} }

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

@ -180,8 +180,9 @@ namespace Fungus
string paramsStr = input.Substring(index + 1); string paramsStr = input.Substring(index + 1);
var splits = paramsStr.Split(','); var splits = paramsStr.Split(',');
foreach (var p in splits) for (int i = 0; i < splits.Length; i++)
{ {
var p = splits[i];
paramsList.Add(p.Trim()); paramsList.Add(p.Trim());
} }
return paramsList; return paramsList;
@ -264,16 +265,14 @@ 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 (var token in tokens) for (int i = 0; i < tokens.Count; i++)
{ {
if (trimLeading && var token = tokens[i];
token.type == TokenType.Words) if (trimLeading && token.type == TokenType.Words)
{ {
token.paramList[0] = token.paramList[0].TrimStart(' ', '\t', '\r', '\n'); token.paramList[0] = token.paramList[0].TrimStart(' ', '\t', '\r', '\n');
} }
if (token.type == TokenType.Clear || token.type == TokenType.WaitForInputAndClear)
if (token.type == TokenType.Clear ||
token.type == TokenType.WaitForInputAndClear)
{ {
trimLeading = true; trimLeading = true;
} }

Loading…
Cancel
Save