public void InitialisationBasicSpecifiedValues(int number, string name, string desc, string identifierBase, string identifierBasePrefs) { //// Arrange PlayerPrefs.DeleteAll(); var gameConfiguration = ScriptableObject.CreateInstance <GameConfiguration>(); var messenger = new Messenger(); var player = ScriptableObject.CreateInstance <Player>(); player.Initialise(gameConfiguration, null, messenger, 1); //// Act var gameItem = ScriptableObject.CreateInstance <GameItem>(); gameItem.Initialise(gameConfiguration, player, messenger, number, LocalisableText.CreateNonLocalised(name), LocalisableText.CreateNonLocalised(desc), identifierBase: identifierBase, identifierBasePrefs: identifierBasePrefs); //// Assert Assert.IsNotNull(gameItem, "GameItem not setup."); Assert.AreEqual(number, gameItem.Number, "Number not set correctly"); Assert.AreEqual(name, gameItem.Name, "Name not set correctly"); Assert.AreEqual(desc, gameItem.Description, "Description not set correctly"); Assert.AreEqual(identifierBase, gameItem.IdentifierBase, "IdentifierBase not set correctly"); Assert.AreEqual(identifierBasePrefs, gameItem.IdentifierBasePrefs, "IdentifierBasePrefs not set correctly"); Assert.AreEqual(0, gameItem.Score, "Score not set correctly"); Assert.AreEqual(0, gameItem.Coins, "Coins not set correctly"); Assert.AreEqual(0, gameItem.HighScore, "HighScore not set correctly"); Assert.AreEqual(false, gameItem.IsBought, "IsBought not set correctly"); Assert.AreEqual(false, gameItem.IsUnlocked, "IsUnlocked not set correctly"); Assert.AreEqual(false, gameItem.IsUnlockedAnimationShown, "IsUnlockedAnimationShown not set correctly"); }
public void BasicInitialisationSpecifiedValues(int number, string name, string desc) { //// Arrange PlayerPrefs.DeleteAll(); var gameConfiguration = ScriptableObject.CreateInstance <GameConfiguration>(); var messenger = new Messenger(); //// Act var player = ScriptableObject.CreateInstance <Player>(); player.Initialise(gameConfiguration, null, messenger, number, LocalisableText.CreateNonLocalised(name), LocalisableText.CreateNonLocalised(desc), identifierBase: "Test_Should_Not_Override", identifierBasePrefs: "T"); //// Assert Assert.IsNotNull(player, "GameItem not setup."); Assert.AreEqual(number, player.Number, "Number not set correctly"); Assert.AreEqual(name, player.Name, "Name not set correctly"); Assert.AreEqual(desc, player.Description, "Description not set correctly"); Assert.AreEqual("Player", player.IdentifierBase, "IdentifierBase not set correctly"); Assert.AreEqual("P", player.IdentifierBasePrefs, "IdentifierBasePrefs not set correctly"); Assert.AreEqual(0, player.Score, "Score not set correctly"); Assert.AreEqual(0, player.Coins, "Coins not set correctly"); Assert.AreEqual(0, player.HighScore, "HighScore not set correctly"); Assert.AreEqual(false, player.IsBought, "IsBought not set correctly"); Assert.AreEqual(false, player.IsUnlocked, "IsUnlocked not set correctly"); Assert.AreEqual(false, player.IsUnlockedAnimationShown, "IsUnlockedAnimationShown not set correctly"); Assert.AreEqual(3, player.Lives, "Lives not set correctly"); Assert.AreEqual(1, player.Health, "Health not set correctly"); Assert.AreEqual(false, player.IsGameWon, "IsGameWon not set correctly"); }
public void CustomDialog() { var dialogInstance = DialogManager.Instance.Create(); dialogInstance.Show(title: "Test Title", text: "Custom Dialog - This uses autogenerated text buttons. You can also create dialogs with custom images.", doneCallback: DoneCallback, buttonText: new [] { LocalisableText.CreateNonLocalised("Button 1"), LocalisableText.CreateNonLocalised("Button 2"), }, dialogButtons: DialogInstance.DialogButtonsType.Cancel); }
/// <summary> /// Create an instance from teh text template button /// </summary> /// <param name="localisableText"></param> /// <returns></returns> GameObject CreateTextButton(LocalisableText localisableText) { var button = Instantiate(_textTemplateButton); var textComponent = button.GetComponentInChildren <Text>(true); Assert.IsNotNull(textComponent, "If using Text buttons, ensure you the TextButton gameobject or one of it's children contains a Text component."); textComponent.text = localisableText.GetValue(); button.transform.SetParent(_textTemplateButton.transform.parent); button.transform.localScale = Vector3.one; button.SetActive(true); return(button); }
/// <summary> /// Setup default values /// </summary> protected BuyGameItemButton(string localisationBase) { _localisationBase = localisationBase; ConfirmTitleText = new LocalisableText { IsLocalised = true, Data = _localisationBase + ".Buy.Title" }; ConfirmText1 = new LocalisableText { IsLocalised = true, Data = _localisationBase + ".Buy.Text1" }; ConfirmText2 = LocalisableText.CreateNonLocalised(); ConfirmDialogSpriteType = UnlockGameItemButton.DialogSpriteType.FromGameItem; }
public void BasicInitialisationSpecifiedValues(string number, string name, string desc) { //// Arrange PlayerPrefs.DeleteAll(); var gameConfiguration = ScriptableObject.CreateInstance <GameConfiguration>(); var messenger = new Messenger(); var player = ScriptableObject.CreateInstance <Player>(); player.Initialise(gameConfiguration, null, messenger, "1"); //// Act var gameItem = ScriptableObject.CreateInstance <Level>(); gameItem.Initialise(gameConfiguration, player, messenger, number, LocalisableText.CreateNonLocalised(name), LocalisableText.CreateNonLocalised(desc), identifierBase: "Test_Should_Not_Override", identifierBasePrefs: "T"); //// Assert Assert.IsNotNull(gameItem, "GameItem not setup."); Assert.AreEqual(number, gameItem.GiId, "Number not set correctly"); Assert.AreEqual(name, gameItem.Name, "Name not set correctly"); Assert.AreEqual(desc, gameItem.Description, "Description not set correctly"); Assert.AreEqual("Level", gameItem.IdentifierBase, "IdentifierBase not set correctly"); Assert.AreEqual("L", gameItem.IdentifierBasePrefs, "IdentifierBasePrefs not set correctly"); Assert.AreEqual(0, gameItem.Score, "Score not set correctly"); Assert.AreEqual(0, gameItem.Coins, "Coins not set correctly"); Assert.AreEqual(0, gameItem.HighScore, "HighScore not set correctly"); Assert.AreEqual(false, gameItem.IsBought, "IsBought not set correctly"); Assert.AreEqual(false, gameItem.IsUnlocked, "IsUnlocked not set correctly"); Assert.AreEqual(false, gameItem.IsUnlockedAnimationShown, "IsUnlockedAnimationShown not set correctly"); Assert.AreEqual(3, gameItem.StarsTotalCount, "StarTotalCount not set correctly"); Assert.AreEqual(10, gameItem.Star1Target, "Star1Target not set correctly"); Assert.AreEqual(15, gameItem.Star2Target, "Star2Target not set correctly"); Assert.AreEqual(20, gameItem.Star3Target, "Star3Target not set correctly"); Assert.AreEqual(25, gameItem.Star4Target, "Star4Target not set correctly"); Assert.AreEqual(0, gameItem.TimeTarget, "TimeTarget not set correctly"); Assert.AreEqual(0, gameItem.ScoreTarget, "ScoreTarget not set correctly"); Assert.AreEqual(0, gameItem.CoinTarget, "CoinTarget not set correctly"); Assert.AreEqual(0, gameItem.StarsWon, "StarsWon not set correctly"); Assert.AreEqual(0, gameItem.TimeBest, "TimeBest not set correctly"); Assert.AreEqual(0, gameItem.ProgressBest, "ProgressBest not set correctly"); }
///// <summary> ///// Show the dialog instance substituting in passed values and running any transitions. ///// </summary> ///// <param name="title"></param> ///// <param name="text"></param> ///// <param name="text2"></param> ///// <param name="sprite"></param> ///// <param name="doneCallback"></param> ///// <param name="destroyOnClose"></param> ///// <param name="dialogButtons"></param> //public void Show(LocalisableText title, LocalisableText text, LocalisableText text2 = null, Sprite sprite = null, // Action<DialogInstance> doneCallback = null, bool destroyOnClose = true, // DialogButtonsType dialogButtons = DialogButtonsType.Custom) //{ // var tTitle = title == null ? null : title.GetValue(); // var tText = title == null ? null : text.GetValue(); // var tText2 = title == null ? null : text2.GetValue(); // Show(title: tTitle, text: tText, text2: tText2, sprite: sprite, doneCallback: doneCallback, destroyOnClose: destroyOnClose, dialogButtons: dialogButtons); //} /// <summary> /// Show the dialog instance substituting in passed values and running any transitions. /// </summary> /// <param name="title"></param> /// <param name="titleKey"></param> /// <param name="text"></param> /// <param name="textKey"></param> /// <param name="text2"></param> /// <param name="text2Key"></param> /// <param name="sprite"></param> /// <param name="doneCallback"></param> /// <param name="destroyOnClose"></param> /// <param name="dialogButtons"></param> /// <param name="buttonText"></param> public void Show(string title = null, string titleKey = null, string text = null, string textKey = null, string text2 = null, string text2Key = null, Sprite sprite = null, Action <DialogInstance> doneCallback = null, bool destroyOnClose = true, DialogButtonsType dialogButtons = DialogButtonsType.Custom, LocalisableText[] buttonText = null) { GameObject childGameObject; _dialogButtons = dialogButtons; DoneCallback = doneCallback; _destroyOnClose = destroyOnClose; // increase open count - not thread safe, but should be ok! Assert.IsTrue(DialogManager.IsActive, "Ensure that you have added a DialogManager component to your scene before showing a dialog!"); DialogManager.Instance.Count++; IsShown = true; // default result DialogResult = DialogResultType.Ok; if (!string.IsNullOrEmpty(titleKey)) { title = GlobalLocalisation.GetText(titleKey); } if (title != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Title", title, true); } if (sprite != null) { UIHelper.SetSpriteOnChildGameObject(gameObject, "ph_Image", sprite, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Image", true); if (childGameObject != null) { childGameObject.SetActive(false); } } if (!string.IsNullOrEmpty(textKey)) { text = GlobalLocalisation.GetText(textKey); } if (text != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Text", text, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Text", true); if (childGameObject != null) { childGameObject.SetActive(false); } } if (!string.IsNullOrEmpty(text2Key)) { text2 = GlobalLocalisation.GetText(text2Key); } if (text2 != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Text2", text2, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Text2", true); if (childGameObject != null) { childGameObject.SetActive(false); } } GameObject okButton, cancelButton; switch (_dialogButtons) { case DialogButtonsType.Ok: okButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "OkButton", true); if (okButton != null) { okButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using Ok buttons, ensure the Dialog a GameObject named OkButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Ok")); button.GetComponent <Button>().onClick.AddListener(() => DoneOk()); } break; case DialogButtonsType.OkCancel: okButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "OkButton", true); cancelButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "CancelButton", true); if (okButton != null && cancelButton != null) { okButton.SetActive(true); cancelButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using OkCancel buttons, ensure the Dialog has GameObjects named OkButton and CancelButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Ok")); button.GetComponent <Button>().onClick.AddListener(() => DoneOk()); button = CreateTextButton(LocalisableText.CreateLocalised("Button.Cancel")); button.GetComponent <Button>().onClick.AddListener(() => DoneCancel()); } break; case DialogButtonsType.Cancel: cancelButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "CancelButton", true); if (cancelButton != null) { cancelButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using a Cancel button, ensure the Dialog a GameObject named CancelButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Cancel")); button.GetComponent <Button>().onClick.AddListener(() => DoneCancel()); } break; case DialogButtonsType.YesNo: var yesButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "YesButton", true); var noButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "NoButton", true); if (yesButton != null && noButton != null) { yesButton.SetActive(true); noButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using YesNo buttons, ensure the Dialog has GameObjects named YesButton and NoButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Yes")); button.GetComponent <Button>().onClick.AddListener(() => DoneYes()); button = CreateTextButton(LocalisableText.CreateLocalised("Button.No")); button.GetComponent <Button>().onClick.AddListener(() => DoneNo()); } break; case DialogButtonsType.Text: Assert.IsNotNull(_textTemplateButton, "If using Text buttons, ensure the Dialog has a GameObject named TextButton that is a template for text buttons"); Assert.IsNotNull(buttonText, "If using Text buttons, ensure you pass a valid array of localisable texts into the show method."); var counter = 0; foreach (var localisableText in buttonText) { var button = CreateTextButton(localisableText); var counter1 = counter; button.GetComponent <Button>().onClick.AddListener(() => DoneCustom(counter1)); counter++; } break; } // show / transition in and when done call coroutine float transitionTime = 0; Target.SetActive(true); #if BEAUTIFUL_TRANSITIONS //if (TransitionHelper.ContainsTransition(gameObject)) //{ transitionTime = TransitionHelper.GetTransitionInTime(TransitionHelper.TransitionIn(gameObject)); //} #endif StartCoroutine(CoRoutines.DelayedCallback(transitionTime, ShowFinished)); }
// set defaults from constructor. public ShowGameItemCounter() { _text = LocalisableText.CreateNonLocalised("{0}"); }