diff --git a/Assets/Fungus/Docs/CHANGELOG.txt b/Assets/Fungus/Docs/CHANGELOG.txt index 11f1f32a..1a6e55a0 100644 --- a/Assets/Fungus/Docs/CHANGELOG.txt +++ b/Assets/Fungus/Docs/CHANGELOG.txt @@ -1,3 +1,53 @@ +Fungus 3.3.0 +============ +# Known Issues +- FungusLua does not work in WebGL builds due to issues in MoonSharp 1.8.0.0 + Forum thread: http://fungusgames.com/forum/#!/general:fungus-lua-and-web-gl-uni + +# Added +- Added test for StopTweens does not stop a Tween with loop enabled #529 +- Added signals (pub-sub system) for Writer and Block events #539 +- All interfaces now have their own source files. +- Added monodevelop project for editing docs files. +- Added Flip option (<<< and >>>) to conversation system #527 + +# Changed + +- Tidied up Fungus folder structure to organize scripts more logically +- Migrated documentation to use Doxygen for help and API docs +- Lots of misc improvements to documentation +- Updated to MoonSharp 1.8.0.0 +- Documented using string facing parameter in stage.show() Lua function. +- Documented <<< and >>> tags for conversation system. +- Documented all public members for API docs. +- All serialized fields are now protected, exposed via public properties as needed. +- Moved all enums to namespace scope. +- Moved global constants to FungusConstants static class. +- Moved editor resources to the main resources folder +- Fungus editor code moved to Fungus.EditorUtils namespace +- Convert singletons to use a single FungusManager singleton #540 +- Renamed CameraController to CameraManager and MusicController to MusicManager +- Changed float constant comparisons to use Mathf.Approximately +- Added #region Public members to all non-editor classes +- StringFormatter, TextTagParser and FungusPrefs classes are now static +- Merged MenuDialog extension methods (used for Lua) with main MenuDialog class. +- Change all public methods to use virtual +- Removed all unnecessary using statements. +- All class and member comments use standard c# xml comment style + +# Fixed + +- Fixed Setting facing in lua only works if portraits are set to “FRONT” #528 +- Fixed Say command completes instantly after menu choice #533 +- Fixed broken mouse pointer in WebGL build of Drag and Drop +- Fixed ObjectField nulls reference if object is disabled #536 +- Updated Unity Test Tools to v1.5.9 +- Fixed missing Process class error in Unity5.5b3 +- Fixed Spine.Unity namespace problem in integration scripts +- Fix Regex for character names with "." & "'" #531 (thanks to Sercan Altun) + Old Regex expression did not capture Character names with "." and "'". As a result characters with names like "Mr. Jones" or "Ab'ar" were not registering correctly. +- Fixed Lua setlanguage() function + Fungus 3.2.0 ============ diff --git a/Assets/Fungus/Scripts/Commands/ControlAudio.cs b/Assets/Fungus/Scripts/Commands/ControlAudio.cs index 09677625..0ee5b000 100644 --- a/Assets/Fungus/Scripts/Commands/ControlAudio.cs +++ b/Assets/Fungus/Scripts/Commands/ControlAudio.cs @@ -65,12 +65,13 @@ namespace Fungus return; } - AudioSource[] audioSources = GameObject.FindObjectsOfType(); - foreach (AudioSource a in audioSources) + var audioSources = GameObject.FindObjectsOfType(); + for (int i = 0; i < audioSources.Length; i++) { - if ((a.GetComponent() != _audioSource.Value) && (a.tag == _audioSource.Value.tag)) + var a = audioSources[i]; + if (a != _audioSource.Value && a.tag == _audioSource.Value.tag) { - StopLoop(a.GetComponent()); + StopLoop(a); } } } diff --git a/Assets/Fungus/Scripts/Commands/ControlStage.cs b/Assets/Fungus/Scripts/Commands/ControlStage.cs index 877b79f8..0dd9dd87 100644 --- a/Assets/Fungus/Scripts/Commands/ControlStage.cs +++ b/Assets/Fungus/Scripts/Commands/ControlStage.cs @@ -72,8 +72,10 @@ namespace Fungus protected virtual void MoveToFront(Stage stage) { - foreach (Stage s in Stage.ActiveStages) + var activeStages = Stage.ActiveStages; + for (int i = 0; i < activeStages.Count; i++) { + var s = activeStages[i]; if (s == stage) { s.PortraitCanvas.sortingOrder = 1; @@ -88,8 +90,10 @@ namespace Fungus protected virtual void UndimAllPortraits(Stage stage) { stage.DimPortraits = false; - foreach (Character character in stage.CharactersOnStage) + var charactersOnStage = stage.CharactersOnStage; + for (int i = 0; i < charactersOnStage.Count; i++) { + var character = charactersOnStage[i]; stage.SetDimmed(character, false); } } diff --git a/Assets/Fungus/Scripts/Commands/FadeUI.cs b/Assets/Fungus/Scripts/Commands/FadeUI.cs index 35fb781e..d344c79d 100644 --- a/Assets/Fungus/Scripts/Commands/FadeUI.cs +++ b/Assets/Fungus/Scripts/Commands/FadeUI.cs @@ -33,92 +33,98 @@ namespace Fungus protected override void ApplyTween(GameObject go) { - foreach (Image image in go.GetComponentsInChildren()) + var images = go.GetComponentsInChildren(); + for (int i = 0; i < images.Length; i++) { + var image = images[i]; if (Mathf.Approximately(duration, 0f)) { switch (fadeMode) { - case FadeMode.Alpha: - Color tempColor = image.color; - tempColor.a = targetAlpha; - image.color = tempColor; - break; - case FadeMode.Color: - image.color = targetColor; - break; + case FadeMode.Alpha: + Color tempColor = image.color; + tempColor.a = targetAlpha; + image.color = tempColor; + break; + case FadeMode.Color: + image.color = targetColor; + break; } } else { switch (fadeMode) { - case FadeMode.Alpha: - LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType); - break; - case FadeMode.Color: - LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType); - break; + case FadeMode.Alpha: + LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType); + break; + case FadeMode.Color: + LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType); + break; } } } - foreach (Text text in go.GetComponentsInChildren()) + var texts = go.GetComponentsInChildren(); + for (int i = 0; i < texts.Length; i++) { + var text = texts[i]; if (Mathf.Approximately(duration, 0f)) { switch (fadeMode) { - case FadeMode.Alpha: - Color tempColor = text.color; - tempColor.a = targetAlpha; - text.color = tempColor; - break; - case FadeMode.Color: - text.color = targetColor; - break; + case FadeMode.Alpha: + Color tempColor = text.color; + tempColor.a = targetAlpha; + text.color = tempColor; + break; + case FadeMode.Color: + text.color = targetColor; + break; } } else { switch (fadeMode) { - case FadeMode.Alpha: - LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType); - break; - case FadeMode.Color: - LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType); - break; + case FadeMode.Alpha: + LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType); + break; + case FadeMode.Color: + LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType); + break; } } } - foreach (TextMesh textMesh in go.GetComponentsInChildren()) + var textMeshes = go.GetComponentsInChildren(); + for (int i = 0; i < textMeshes.Length; i++) { + var textMesh = textMeshes[i]; if (Mathf.Approximately(duration, 0f)) { switch (fadeMode) { - case FadeMode.Alpha: - Color tempColor = textMesh.color; - tempColor.a = targetAlpha; - textMesh.color = tempColor; - break; - case FadeMode.Color: - textMesh.color = targetColor; - break; + case FadeMode.Alpha: + Color tempColor = textMesh.color; + tempColor.a = targetAlpha; + textMesh.color = tempColor; + break; + case FadeMode.Color: + textMesh.color = targetColor; + break; } } else { switch (fadeMode) { - case FadeMode.Alpha: - LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType); - break; - case FadeMode.Color: - LeanTween.color(go, targetColor, duration).setEase(tweenType); - break; + case FadeMode.Alpha: + LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType); + break; + case FadeMode.Color: + LeanTween.color(go, targetColor, duration).setEase(tweenType); + break; } } } diff --git a/Assets/Fungus/Scripts/Commands/Jump.cs b/Assets/Fungus/Scripts/Commands/Jump.cs index 26849578..ebaa4b4d 100644 --- a/Assets/Fungus/Scripts/Commands/Jump.cs +++ b/Assets/Fungus/Scripts/Commands/Jump.cs @@ -29,11 +29,12 @@ namespace Fungus return; } - foreach (var command in ParentBlock.CommandList) + var commandList = ParentBlock.CommandList; + for (int i = 0; i < commandList.Count; i++) { + var command = commandList[i]; Label label = command as Label; - if (label != null && - label.Key == _targetLabel.Value) + if (label != null && label.Key == _targetLabel.Value) { Continue(label.CommandIndex + 1); return; diff --git a/Assets/Fungus/Scripts/Commands/Say.cs b/Assets/Fungus/Scripts/Commands/Say.cs index aae38e81..d129f78b 100644 --- a/Assets/Fungus/Scripts/Commands/Say.cs +++ b/Assets/Fungus/Scripts/Commands/Say.cs @@ -107,8 +107,10 @@ namespace Fungus string displayText = storyText; - foreach (CustomTag ct in CustomTag.activeCustomTags) + var activeCustomTags = CustomTag.activeCustomTags; + for (int i = 0; i < activeCustomTags.Count; i++) { + var ct = activeCustomTags[i]; displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith); if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "") { diff --git a/Assets/Fungus/Scripts/Commands/SendMessage.cs b/Assets/Fungus/Scripts/Commands/SendMessage.cs index a9499ed4..fd87b76d 100644 --- a/Assets/Fungus/Scripts/Commands/SendMessage.cs +++ b/Assets/Fungus/Scripts/Commands/SendMessage.cs @@ -59,8 +59,9 @@ namespace Fungus if (receivers != null) { - foreach (MessageReceived receiver in receivers) + for (int i = 0; i < receivers.Length; i++) { + var receiver = receivers[i]; receiver.OnSendFungusMessage(_message.Value); } } diff --git a/Assets/Fungus/Scripts/Commands/SetCollider.cs b/Assets/Fungus/Scripts/Commands/SetCollider.cs index 2d8ea4a1..b56a64f5 100644 --- a/Assets/Fungus/Scripts/Commands/SetCollider.cs +++ b/Assets/Fungus/Scripts/Commands/SetCollider.cs @@ -29,14 +29,18 @@ namespace Fungus if (go != null) { // 3D objects - foreach (Collider c in go.GetComponentsInChildren()) + var colliders = go.GetComponentsInChildren(); + for (int i = 0; i < colliders.Length; i++) { + var c = colliders[i]; c.enabled = activeState.Value; } // 2D objects - foreach (Collider2D c in go.GetComponentsInChildren()) + var collider2Ds = go.GetComponentsInChildren(); + for (int i = 0; i < collider2Ds.Length; i++) { + var c = collider2Ds[i]; c.enabled = activeState.Value; } } @@ -46,8 +50,9 @@ namespace Fungus public override void OnEnter() { - foreach (GameObject go in targetObjects) + for (int i = 0; i < targetObjects.Count; i++) { + var go = targetObjects[i]; SetColliderActive(go); } @@ -63,8 +68,9 @@ namespace Fungus if (taggedObjects != null) { - foreach (GameObject go in taggedObjects) + for (int i = 0; i < taggedObjects.Length; i++) { + var go = taggedObjects[i]; SetColliderActive(go); } } diff --git a/Assets/Fungus/Scripts/Commands/SetInteractable.cs b/Assets/Fungus/Scripts/Commands/SetInteractable.cs index 07f54537..66d77eb1 100644 --- a/Assets/Fungus/Scripts/Commands/SetInteractable.cs +++ b/Assets/Fungus/Scripts/Commands/SetInteractable.cs @@ -31,10 +31,13 @@ namespace Fungus return; } - foreach (GameObject targetObject in targetObjects) + for (int i = 0; i < targetObjects.Count; i++) { - foreach (Selectable selectable in targetObject.GetComponents()) + var targetObject = targetObjects[i]; + var selectables = targetObject.GetComponents(); + for (int j = 0; j < selectables.Length; j++) { + var selectable = selectables[j]; selectable.interactable = interactableState.Value; } } @@ -58,20 +61,20 @@ namespace Fungus } string objectList = ""; - foreach (GameObject gameObject in targetObjects) + for (int i = 0; i < targetObjects.Count; i++) { - if (gameObject == null) + var go = targetObjects[i]; + if (go == null) { continue; } - if (objectList == "") { - objectList += gameObject.name; + objectList += go.name; } else { - objectList += ", " + gameObject.name; + objectList += ", " + go.name; } } diff --git a/Assets/Fungus/Scripts/Commands/SetLayerOrder.cs b/Assets/Fungus/Scripts/Commands/SetLayerOrder.cs index 112d37c7..4eb82244 100644 --- a/Assets/Fungus/Scripts/Commands/SetLayerOrder.cs +++ b/Assets/Fungus/Scripts/Commands/SetLayerOrder.cs @@ -22,14 +22,15 @@ namespace Fungus protected void ApplySortingLayer(Transform target, string layerName) { - Renderer renderer = target.gameObject.GetComponent(); + var renderer = target.gameObject.GetComponent(); if (renderer) { renderer.sortingLayerName = layerName; Debug.Log(target.name); } - foreach (Transform child in target.transform) + var targetTransform = target.transform; + foreach (Transform child in targetTransform) { ApplySortingLayer(child, layerName); } diff --git a/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs b/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs index 96c8300e..e284941d 100644 --- a/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs +++ b/Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs @@ -25,8 +25,9 @@ namespace Fungus public override void OnEnter() { - foreach (SpriteRenderer spriteRenderer in targetSprites) + for (int i = 0; i < targetSprites.Count; i++) { + var spriteRenderer = targetSprites[i]; spriteRenderer.sortingOrder = orderInLayer; } @@ -36,18 +37,17 @@ namespace Fungus public override string GetSummary() { string summary = ""; - foreach (SpriteRenderer spriteRenderer in targetSprites) + for (int i = 0; i < targetSprites.Count; i++) { + var spriteRenderer = targetSprites[i]; if (spriteRenderer == null) { continue; } - if (summary.Length > 0) { summary += ", "; } - summary += spriteRenderer.name; } diff --git a/Assets/Fungus/Scripts/Commands/ShowSprite.cs b/Assets/Fungus/Scripts/Commands/ShowSprite.cs index ed5bc62e..110b6517 100644 --- a/Assets/Fungus/Scripts/Commands/ShowSprite.cs +++ b/Assets/Fungus/Scripts/Commands/ShowSprite.cs @@ -40,9 +40,10 @@ namespace Fungus { if (affectChildren) { - SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren(); - foreach (SpriteRenderer sr in children) + var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren(); + for (int i = 0; i < spriteRenderers.Length; i++) { + var sr = spriteRenderers[i]; SetSpriteAlpha(sr, _visible.Value); } } diff --git a/Assets/Fungus/Scripts/Commands/StopFlowchart.cs b/Assets/Fungus/Scripts/Commands/StopFlowchart.cs index b295b2dc..c11cedbb 100644 --- a/Assets/Fungus/Scripts/Commands/StopFlowchart.cs +++ b/Assets/Fungus/Scripts/Commands/StopFlowchart.cs @@ -32,14 +32,14 @@ namespace Fungus flowchart.StopAllBlocks(); } - foreach (var f in targetFlowcharts) + for (int i = 0; i < targetFlowcharts.Count; i++) { + var f = targetFlowcharts[i]; if (f == flowchart) { // Flowchart has already been stopped continue; } - f.StopAllBlocks(); } } diff --git a/Assets/Fungus/Scripts/Commands/TweenUI.cs b/Assets/Fungus/Scripts/Commands/TweenUI.cs index 8803d455..2563c796 100644 --- a/Assets/Fungus/Scripts/Commands/TweenUI.cs +++ b/Assets/Fungus/Scripts/Commands/TweenUI.cs @@ -26,13 +26,13 @@ namespace Fungus protected virtual void ApplyTween() { - foreach (GameObject targetObject in targetObjects) + for (int i = 0; i < targetObjects.Count; i++) { + var targetObject = targetObjects[i]; if (targetObject == null) { continue; } - ApplyTween(targetObject); } @@ -97,20 +97,20 @@ namespace Fungus } string objectList = ""; - foreach (GameObject gameObject in targetObjects) + for (int i = 0; i < targetObjects.Count; i++) { - if (gameObject == null) + var go = targetObjects[i]; + if (go == null) { continue; } - if (objectList == "") { - objectList += gameObject.name; + objectList += go.name; } else { - objectList += ", " + gameObject.name; + objectList += ", " + go.name; } } diff --git a/Assets/Fungus/Scripts/Commands/iTweenCommand.cs b/Assets/Fungus/Scripts/Commands/iTweenCommand.cs index f5b12832..2bc8b0ac 100644 --- a/Assets/Fungus/Scripts/Commands/iTweenCommand.cs +++ b/Assets/Fungus/Scripts/Commands/iTweenCommand.cs @@ -73,8 +73,10 @@ namespace Fungus if (stopPreviousTweens) { // Force any existing iTweens on this target object to complete immediately - iTween[] tweens = _targetObject.Value.GetComponents(); - foreach (iTween tween in tweens) { + var tweens = _targetObject.Value.GetComponents(); + for (int i = 0; i < tweens.Length; i++) + { + var tween = tweens[i]; tween.time = 0; tween.SendMessage("Update"); } diff --git a/Assets/Fungus/Scripts/Components/Block.cs b/Assets/Fungus/Scripts/Components/Block.cs index 65296820..b181a3f0 100644 --- a/Assets/Fungus/Scripts/Components/Block.cs +++ b/Assets/Fungus/Scripts/Components/Block.cs @@ -72,13 +72,13 @@ namespace Fungus // Give each child command a reference back to its parent block // and tell each command its index in the list. int index = 0; - foreach (var command in commandList) + for (int i = 0; i < commandList.Count; i++) { + var command = commandList[i]; if (command == null) { continue; } - command.ParentBlock = this; command.CommandIndex = index++; } @@ -98,13 +98,14 @@ namespace Fungus protected virtual void Update() { 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; } - command.CommandIndex = index++; } } @@ -328,8 +329,9 @@ namespace Fungus public virtual List GetConnectedBlocks() { var connectedBlocks = new List(); - foreach (var command in commandList) + for (int i = 0; i < commandList.Count; i++) { + var command = commandList[i]; if (command != null) { command.GetConnectedBlocks(ref connectedBlocks); @@ -359,23 +361,20 @@ namespace Fungus public virtual void UpdateIndentLevels() { int indentLevel = 0; - foreach (var command in commandList) + for (int i = 0; i < commandList.Count; i++) { + var command = commandList[i]; if (command == null) { continue; } - if (command.CloseBlock()) { indentLevel--; } - // Negative indent level is not permitted indentLevel = Math.Max(indentLevel, 0); - command.IndentLevel = indentLevel; - if (command.OpenBlock()) { indentLevel++; diff --git a/Assets/Fungus/Scripts/Components/CameraManager.cs b/Assets/Fungus/Scripts/Components/CameraManager.cs index 93527250..d6c04acc 100644 --- a/Assets/Fungus/Scripts/Components/CameraManager.cs +++ b/Assets/Fungus/Scripts/Components/CameraManager.cs @@ -155,10 +155,10 @@ namespace Fungus 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.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0f, 1f, t)); + + SetCameraZ(camera); } - SetCameraZ(camera); - if (arrived && arriveAction != null) { diff --git a/Assets/Fungus/Scripts/Components/Clickable2D.cs b/Assets/Fungus/Scripts/Components/Clickable2D.cs index 854836e2..93c56112 100644 --- a/Assets/Fungus/Scripts/Components/Clickable2D.cs +++ b/Assets/Fungus/Scripts/Components/Clickable2D.cs @@ -40,9 +40,10 @@ namespace Fungus } // TODO: Cache these objects for faster lookup - ObjectClicked[] handlers = GameObject.FindObjectsOfType(); - foreach (ObjectClicked handler in handlers) + var handlers = GameObject.FindObjectsOfType(); + for (int i = 0; i < handlers.Length; i++) { + var handler = handlers[i]; handler.OnObjectClicked(this); } } diff --git a/Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs b/Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs index 7019a874..720c446d 100644 --- a/Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs +++ b/Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs @@ -62,8 +62,10 @@ namespace Fungus public virtual void Clear() { - foreach (Command command in GetCommands()) + var commands = GetCommands(); + for (int i = 0; i < commands.Length; i++) { + var command = commands[i]; DestroyImmediate(command); } } diff --git a/Assets/Fungus/Scripts/Components/DialogInput.cs b/Assets/Fungus/Scripts/Components/DialogInput.cs index 063aebb8..3605bcec 100644 --- a/Assets/Fungus/Scripts/Components/DialogInput.cs +++ b/Assets/Fungus/Scripts/Components/DialogInput.cs @@ -46,6 +46,13 @@ namespace Fungus protected StandaloneInputModule currentStandaloneInputModule; + protected Writer writer; + + protected virtual void Awake() + { + writer = GetComponent(); + } + protected virtual void Update() { if (EventSystem.current == null) @@ -69,10 +76,13 @@ namespace Fungus currentStandaloneInputModule = EventSystem.current.GetComponent(); } - if (Input.GetButtonDown(currentStandaloneInputModule.submitButton) || - (cancelEnabled && Input.GetButton(currentStandaloneInputModule.cancelButton))) + if (writer != null && writer.IsWriting) { - SetNextLineFlag(); + if (Input.GetButtonDown(currentStandaloneInputModule.submitButton) || + (cancelEnabled && Input.GetButton(currentStandaloneInputModule.cancelButton))) + { + SetNextLineFlag(); + } } switch (clickMode) @@ -114,9 +124,10 @@ namespace Fungus // Tell any listeners to move to the next line if (nextLineInputFlag) { - IDialogInputListener[] inputListeners = gameObject.GetComponentsInChildren(); - foreach (IDialogInputListener inputListener in inputListeners) + var inputListeners = gameObject.GetComponentsInChildren(); + for (int i = 0; i < inputListeners.Length; i++) { + var inputListener = inputListeners[i]; inputListener.OnNextLineEvent(); } nextLineInputFlag = false; diff --git a/Assets/Fungus/Scripts/Components/Draggable2D.cs b/Assets/Fungus/Scripts/Components/Draggable2D.cs index aff5bf3b..68c661ec 100644 --- a/Assets/Fungus/Scripts/Components/Draggable2D.cs +++ b/Assets/Fungus/Scripts/Components/Draggable2D.cs @@ -58,13 +58,17 @@ namespace Fungus return; } - foreach (DragEntered handler in GetHandlers()) + var dragEnteredHandlers = GetHandlers(); + for (int i = 0; i < dragEnteredHandlers.Length; i++) { + var handler = dragEnteredHandlers[i]; handler.OnDragEntered(this, other); } - foreach (DragCompleted handler in GetHandlers()) + var dragCompletedHandlers = GetHandlers(); + for (int i = 0; i < dragCompletedHandlers.Length; i++) { + var handler = dragCompletedHandlers[i]; handler.OnDragEntered(this, other); } } @@ -76,13 +80,17 @@ namespace Fungus return; } - foreach (DragExited handler in GetHandlers()) + var dragExitedHandlers = GetHandlers(); + for (int i = 0; i < dragExitedHandlers.Length; i++) { + var handler = dragExitedHandlers[i]; handler.OnDragExited(this, other); } - foreach (DragCompleted handler in GetHandlers()) + var dragCompletedHandlers = GetHandlers(); + for (int i = 0; i < dragCompletedHandlers.Length; i++) { + var handler = dragCompletedHandlers[i]; handler.OnDragExited(this, other); } } @@ -103,8 +111,10 @@ namespace Fungus startingPosition = transform.position; - foreach (DragStarted handler in GetHandlers()) + var dragStartedHandlers = GetHandlers(); + for (int i = 0; i < dragStartedHandlers.Length; i++) { + var handler = dragStartedHandlers[i]; handler.OnDragStarted(this); } } @@ -134,16 +144,16 @@ namespace Fungus bool dragCompleted = false; - DragCompleted[] handlers = GetHandlers(); - foreach (DragCompleted handler in handlers) + var handlers = GetHandlers(); + for (int i = 0; i < handlers.Length; i++) { + var handler = handlers[i]; if (handler.DraggableObject == this) { if (handler.IsOverTarget()) { handler.OnDragCompleted(this); dragCompleted = true; - if (returnOnCompleted) { LeanTween.move(gameObject, startingPosition, returnDuration).setEase(LeanTweenType.easeOutExpo); @@ -154,8 +164,10 @@ namespace Fungus if (!dragCompleted) { - foreach (DragCancelled handler in GetHandlers()) + var dragCancelledHandlers = GetHandlers(); + for (int i = 0; i < dragCancelledHandlers.Length; i++) { + var handler = dragCancelledHandlers[i]; handler.OnDragCancelled(this); } diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index 8c51eb4b..e8a57452 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -158,8 +158,10 @@ namespace Fungus } // Tell all components that implement IUpdateable to update to the new version - foreach (Component component in GetComponents()) + var components = GetComponents(); + for (int i = 0; i < components.Length; i++) { + var component = components[i]; IUpdateable u = component as IUpdateable; if (u != null) { @@ -181,10 +183,10 @@ namespace Fungus // This should always be the case, but some legacy Flowcharts may have issues. List usedIds = new List(); var blocks = GetComponents(); - foreach (var block in blocks) + for (int i = 0; i < blocks.Length; i++) { - if (block.ItemId == -1 || - usedIds.Contains(block.ItemId)) + var block = blocks[i]; + if (block.ItemId == -1 || usedIds.Contains(block.ItemId)) { block.ItemId = NextItemId(); } @@ -192,10 +194,10 @@ namespace Fungus } var commands = GetComponents(); - foreach (var command in commands) + for (int i = 0; i < commands.Length; i++) { - if (command.ItemId == -1 || - usedIds.Contains(command.ItemId)) + var command = commands[i]; + if (command.ItemId == -1 || usedIds.Contains(command.ItemId)) { command.ItemId = NextItemId(); } @@ -213,8 +215,10 @@ namespace Fungus // It shouldn't happen but it seemed to occur for a user on the forum variables.RemoveAll(item => item == null); - foreach (Variable variable in GetComponents()) + var allVariables = GetComponents(); + for (int i = 0; i < allVariables.Length; i++) { + var variable = allVariables[i]; if (!variables.Contains(variable)) { DestroyImmediate(variable); @@ -222,37 +226,40 @@ namespace Fungus } var blocks = GetComponents(); - - foreach (var command in GetComponents()) + var commands = GetComponents(); + for (int i = 0; i < commands.Length; i++) { + var command = commands[i]; 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)) { found = true; break; } } - if (!found) { DestroyImmediate(command); } } - foreach (EventHandler eventHandler in GetComponents()) + var eventHandlers = GetComponents(); + for (int i = 0; i < eventHandlers.Length; i++) { + var eventHandler = eventHandlers[i]; bool found = false; - foreach (var block in blocks) + for (int j = 0; j < blocks.Length; j++) { + var block = blocks[j]; if (block._EventHandler == eventHandler) { found = true; break; } } - if (!found) { DestroyImmediate(eventHandler); @@ -279,9 +286,10 @@ namespace Fungus /// public static void BroadcastFungusMessage(string messageName) { - MessageReceived[] eventHandlers = UnityEngine.Object.FindObjectsOfType(); - foreach (MessageReceived eventHandler in eventHandlers) + var eventHandlers = UnityEngine.Object.FindObjectsOfType(); + for (int i = 0; i < eventHandlers.Length; i++) { + var eventHandler = eventHandlers[i]; eventHandler.OnSendFungusMessage(messageName); } } @@ -406,14 +414,16 @@ namespace Fungus { int maxId = -1; var blocks = GetComponents(); - foreach (var block in blocks) + for (int i = 0; i < blocks.Length; i++) { + var block = blocks[i]; maxId = Math.Max(maxId, block.ItemId); } var commands = GetComponents(); - foreach (var command in commands) + for (int i = 0; i < commands.Length; i++) { + var command = commands[i]; maxId = Math.Max(maxId, command.ItemId); } return maxId + 1; @@ -438,8 +448,9 @@ namespace Fungus public virtual Block FindBlock(string blockName) { var blocks = GetComponents(); - foreach (var block in blocks) + for (int i = 0; i < blocks.Length; i++) { + var block = blocks[i]; if (block.BlockName == blockName) { return block; @@ -506,8 +517,9 @@ namespace Fungus public virtual void StopAllBlocks() { var blocks = GetComponents(); - foreach (Block block in blocks) + for (int i = 0; i < blocks.Length; i++) { + var block = blocks[i]; if (block.IsExecuting()) { block.Stop(); @@ -521,9 +533,10 @@ namespace Fungus /// public virtual void SendFungusMessage(string messageName) { - MessageReceived[] eventHandlers = GetComponents(); - foreach (MessageReceived eventHandler in eventHandlers) + var eventHandlers = GetComponents(); + for (int i = 0; i < eventHandlers.Length; i++) { + var eventHandler = eventHandlers[i]; eventHandler.OnSendFungusMessage(messageName); } } @@ -553,15 +566,13 @@ namespace Fungus while (true) { bool collision = false; - foreach(Variable variable in variables) + for (int i = 0; i < variables.Count; i++) { - if (variable == null || - variable == ignoreVariable || - variable.Key == null) + var variable = variables[i]; + if (variable == null || variable == ignoreVariable || variable.Key == null) { continue; } - if (variable.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) { collision = true; @@ -597,14 +608,13 @@ namespace Fungus while (true) { bool collision = false; - foreach (var block in blocks) + for (int i = 0; i < blocks.Length; i++) { - if (block == ignoreBlock || - block.BlockName == null) + var block = blocks[i]; + if (block == ignoreBlock || block.BlockName == null) { continue; } - if (block.BlockName.Equals(key, StringComparison.CurrentCultureIgnoreCase)) { collision = true; @@ -640,15 +650,15 @@ namespace Fungus while (true) { bool collision = false; - foreach (var command in block.CommandList) + var commandList = block.CommandList; + for (int i = 0; i < commandList.Count; i++) { + var command = commandList[i]; Label label = command as Label; - if (label == null || - label == ignoreLabel) + if (label == null || label == ignoreLabel) { continue; } - if (label.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) { collision = true; @@ -673,8 +683,9 @@ namespace Fungus /// public Variable GetVariable(string key) { - foreach (Variable variable in variables) + for (int i = 0; i < variables.Count; i++) { + var variable = variables[i]; if (variable != null && variable.Key == key) { return variable; @@ -692,8 +703,9 @@ namespace Fungus /// public T GetVariable(string key) where T : Variable { - foreach (Variable variable in variables) + for (int i = 0; i < variables.Count; i++) { + var variable = variables[i]; if (variable != null && variable.Key == key) { return variable as T; @@ -710,8 +722,9 @@ namespace Fungus /// public void SetVariable(string key, T newvariable) where T : Variable { - foreach (Variable v in variables) + for (int i = 0; i < variables.Count; i++) { + var v = variables[i]; if (v != null && v.Key == key) { T variable = v as T; @@ -731,9 +744,10 @@ namespace Fungus /// public virtual List GetPublicVariables() { - List publicVariables = new List(); - foreach (Variable v in variables) + var publicVariables = new List(); + for (int i = 0; i < variables.Count; i++) { + var v = variables[i]; if (v != null && v.Scope == VariableScope.Public) { publicVariables.Add(v); @@ -874,9 +888,10 @@ namespace Fungus { if (hideComponents) { - Block[] blocks = GetComponents(); - foreach (Block block in blocks) + var blocks = GetComponents(); + for (int i = 0; i < blocks.Length; i++) { + var block = blocks[i]; block.hideFlags = HideFlags.HideInInspector; if (block.gameObject != gameObject) { @@ -884,28 +899,30 @@ namespace Fungus } } - Command[] commands = GetComponents(); - foreach (var command in commands) + var commands = GetComponents(); + for (int i = 0; i < commands.Length; i++) { + var command = commands[i]; command.hideFlags = HideFlags.HideInInspector; } - EventHandler[] eventHandlers = GetComponents(); - foreach (var eventHandler in eventHandlers) + var eventHandlers = GetComponents(); + for (int i = 0; i < eventHandlers.Length; i++) { + var eventHandler = eventHandlers[i]; eventHandler.hideFlags = HideFlags.HideInInspector; } } else { - MonoBehaviour[] monoBehaviours = GetComponents(); - foreach (MonoBehaviour monoBehaviour in monoBehaviours) + var monoBehaviours = GetComponents(); + for (int i = 0; i < monoBehaviours.Length; i++) { + var monoBehaviour = monoBehaviours[i]; if (monoBehaviour == null) { continue; } - monoBehaviour.hideFlags = HideFlags.None; monoBehaviour.gameObject.hideFlags = HideFlags.None; } @@ -939,16 +956,18 @@ namespace Fungus if (resetCommands) { var commands = GetComponents(); - foreach (var command in commands) + for (int i = 0; i < commands.Length; i++) { + var command = commands[i]; command.OnReset(); } } if (resetVariables) { - foreach (Variable variable in variables) + for (int i = 0; i < variables.Count; i++) { + var variable = variables[i]; variable.OnReset(); } } @@ -959,11 +978,11 @@ namespace Fungus /// public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo) { - foreach (string key in hideCommands) + for (int i = 0; i < hideCommands.Count; i++) { // Match on category or command name (case insensitive) - if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 || - String.Compare(commandInfo.CommandName, key, StringComparison.OrdinalIgnoreCase) == 0) + var key = hideCommands[i]; + if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(commandInfo.CommandName, key, StringComparison.OrdinalIgnoreCase) == 0) { return false; } @@ -978,8 +997,9 @@ namespace Fungus public virtual bool HasExecutingBlocks() { var blocks = GetComponents(); - foreach (var block in blocks) + for (int i = 0; i < blocks.Length; i++) { + var block = blocks[i]; if (block.IsExecuting()) { return true; @@ -995,8 +1015,9 @@ namespace Fungus { var executingBlocks = new List(); var blocks = GetComponents(); - foreach (var block in blocks) + for (int i = 0; i < blocks.Length; i++) { + var block = blocks[i]; if (block.IsExecuting()) { executingBlocks.Add(block); @@ -1032,19 +1053,18 @@ namespace Fungus // Match the regular expression pattern against a text string. 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); - // Look for any matching private variables in this Flowchart first - foreach (Variable variable in variables) + for (int j = 0; j < variables.Count; j++) { + var variable = variables[j]; if (variable == null) continue; - - if (variable.Scope == VariableScope.Private && - variable.Key == key) - { + if (variable.Scope == VariableScope.Private && variable.Key == key) + { string value = variable.ToString(); sb.Replace(match.Value, value); changed = true; @@ -1084,22 +1104,22 @@ namespace Fungus // Match the regular expression pattern against a text string. 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); - // Look for any matching public variables in this Flowchart - foreach (Variable variable in variables) + for (int j = 0; j < variables.Count; j++) { + var variable = variables[j]; if (variable == null) + { continue; - - if (variable.Scope == VariableScope.Public && - variable.Key == key) - { + } + if (variable.Scope == VariableScope.Public && variable.Key == key) + { string value = variable.ToString(); input.Replace(match.Value, value); - modified = true; } } diff --git a/Assets/Fungus/Scripts/Components/Localization.cs b/Assets/Fungus/Scripts/Components/Localization.cs index b437fe20..604e107b 100644 --- a/Assets/Fungus/Scripts/Components/Localization.cs +++ b/Assets/Fungus/Scripts/Components/Localization.cs @@ -96,8 +96,9 @@ namespace Fungus protected virtual void CacheLocalizeableObjects() { UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component)); - foreach (UnityEngine.Object o in objects) + for (int i = 0; i < objects.Length; i++) { + var o = objects[i]; ILocalizable localizable = o as ILocalizable; if (localizable != null) { @@ -116,13 +117,18 @@ namespace Fungus // Add localizable commands in same order as command list to make it // easier to localise / edit standard text. var flowcharts = GameObject.FindObjectsOfType(); - foreach (var flowchart in flowcharts) + for (int i = 0; i < flowcharts.Length; i++) { + var flowchart = flowcharts[i]; var blocks = flowchart.GetComponents(); - foreach (var block in blocks) + + for (int j = 0; j < blocks.Length; j++) { - foreach (var command in block.CommandList) + var block = blocks[j]; + var commandList = block.CommandList; + for (int k = 0; k < commandList.Count; k++) { + var command = commandList[k]; ILocalizable localizable = command as ILocalizable; if (localizable != null) { @@ -137,8 +143,9 @@ namespace Fungus // Add everything else that's localizable (including inactive objects) UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component)); - foreach (UnityEngine.Object o in objects) + for (int i = 0; i < objects.Length; i++) { + var o = objects[i]; ILocalizable localizable = o as ILocalizable; if (localizable != null) { @@ -148,7 +155,6 @@ namespace Fungus // Already added continue; } - TextItem textItem = new TextItem(); textItem.standardText = localizable.GetStandardText(); textItem.description = localizable.GetDescription(); @@ -288,8 +294,9 @@ namespace Fungus // Build CSV header row and a list of the language codes currently in use string csvHeader = "Key,Description,Standard"; - List languageCodes = new List(); - foreach (TextItem textItem in textItems.Values) + var languageCodes = new List(); + var values = textItems.Values; + foreach (var textItem in values) { foreach (string languageCode in textItem.localizedStrings.Keys) { @@ -304,7 +311,8 @@ namespace Fungus // Build the CSV file using collected text items int rowCount = 0; string csvData = csvHeader + "\n"; - foreach (string stringId in textItems.Keys) + var keys = textItems.Keys; + foreach (var stringId in keys) { TextItem textItem = textItems[stringId]; @@ -312,15 +320,17 @@ namespace Fungus row += "," + CSVSupport.Escape(textItem.description); row += "," + CSVSupport.Escape(textItem.standardText); - foreach (string languageCode in languageCodes) + for (int i = 0; i < languageCodes.Count; i++) { + var languageCode = languageCodes[i]; if (textItem.localizedStrings.ContainsKey(languageCode)) { row += "," + CSVSupport.Escape(textItem.localizedStrings[languageCode]); } else { - row += ","; // Empty field + row += ","; + // Empty field } } @@ -462,7 +472,8 @@ namespace Fungus string textData = ""; int rowCount = 0; - foreach (string stringId in textItems.Keys) + var keys = textItems.Keys; + foreach (var stringId in keys) { TextItem languageItem = textItems[stringId]; @@ -481,15 +492,16 @@ namespace Fungus /// public virtual void SetStandardText(string textData) { - string[] lines = textData.Split('\n'); + var lines = textData.Split('\n'); int updatedCount = 0; string stringId = ""; string buffer = ""; - foreach (string line in lines) + for (int i = 0; i < lines.Length; i++) { // Check for string id line + var line = lines[i]; if (line.StartsWith("#")) { if (stringId.Length > 0) @@ -500,7 +512,6 @@ namespace Fungus updatedCount++; } } - // Set the string id for the follow text lines stringId = line.Substring(1, line.Length - 1); buffer = ""; @@ -540,10 +551,10 @@ namespace Fungus // Match the regular expression pattern against a text string. 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); - // Next look for matching localized string string localizedString = Localization.GetLocalizedString(key); if (localizedString != null) diff --git a/Assets/Fungus/Scripts/Components/MenuDialog.cs b/Assets/Fungus/Scripts/Components/MenuDialog.cs index 844868c7..935d242a 100644 --- a/Assets/Fungus/Scripts/Components/MenuDialog.cs +++ b/Assets/Fungus/Scripts/Components/MenuDialog.cs @@ -154,14 +154,16 @@ namespace Fungus { StopAllCoroutines(); - Button[] optionButtons = GetComponentsInChildren