public void loadXmlFromPayload() { // Creates a XmlDocument from the XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(LevelXmlPayload.Instance.levelXml); var levelFile = xmlDocument.SelectSingleNode("LevelFile"); var hashMatching = SecurityChecker.validateXmlLevel(levelFile); if (!hashMatching) { Debug.LogError("Level hashes are not matching!"); } if (!(hashMatching || overrideHashCheck)) { return; } var versionString = ParseHelper.getAttributeValueByName(levelFile, "version"); if (!int.TryParse(versionString, out var version)) { throw new Exception("Could not parse a valid Versionnumber from: " + versionString); } var levelXml = levelFile.SelectSingleNode("Level"); CurrentLevel = ParserFactory.getLevelParserByVersion(version).parseLevelFromXmlString(levelXml); CurrentTutorial = ParserFactory.getTutorialParserByVersion(version).parseTutorialFromXmlString(levelXml); CurrentLevel.initializeLevel(); CurrentTutorial.initializeTutorial(); }
static void TranslateTutorialContainer(TutorialContainer container) { int numNewTranslations = TranslateObject(container); foreach (var section in container.Sections) { numNewTranslations += TranslateObject(section); } if (numNewTranslations > 0) { container.RaiseModified(); } }
public void OpenMenu() { InitGame(); GameStarted = false; MenuPanel.SetActive(false); GamePanel.SetActive(true); LvlPassedPanel.SetActive(false); LvlLostPanel.SetActive(false); TutorialContainer.SetActive(false); LevelPassedConfetti.SetActive(false); }
static (TutorialWelcomePage, TutorialContainer, TutorialProjectSettings) CreateReadyToUseTutorialProject() { var path = GetActiveFolderPath(); TutorialWelcomePage welcomePage = CreateTutorialWelcomePage($"{path}/Tutorial Welcome Page.asset"); TutorialContainer container = CreateTutorialContainer($"{path}/Tutorials.asset"); container.Title = "Title"; container.Subtitle = "Subtitle"; CreateTutorialFlow(null, container); TutorialProjectSettings tutorialProjectSettings = CreateTutorialProjectSettings($"{path}/Tutorial Project Settings.asset"); var style = tutorialProjectSettings.TutorialStyle; //this triggers the loading of the default style tutorialProjectSettings.WelcomePage = welcomePage; EnsureAssetChangesAreSaved(container); return(welcomePage, container, tutorialProjectSettings); }
/// <summary> /// Generates a full tutorial with the least amount of tutorial pages possible, and adds it to the list of existing tutorials /// </summary> /// <param name="windowLayout">The layout the tutorial will use</param> /// <param name="container">The container to which this tutorial will be added</param> /// <returns>The created Tutorial</returns> static Tutorial CreateTutorialFlow(UnityEngine.Object windowLayout, TutorialContainer container) { var path = GetActiveFolderPath(); TutorialPage startPage = CreateTutorialPageWithNarrative($"{path}/5-StartPage"); TutorialPage instructivePage = CreateTutorialPageWithInstructions($"{path}/10-TutorialPage"); TutorialPage tutorialSwitchPage = CreateTutorialPageWithSwitch($"{path}/15-LastPage", null); Tutorial tutorial = CreateEmptyTutorial($"{path}/New Tutorial.asset"); // TODO: this would be the ideal solution to provide a more complete setup experience, // but a bug with Scriptable object prevents Scriptable Objects created "after" to // be referenced from Scriptable Objects created before them... //TutorialPage tutorialSwitchPage = CreateTutorialPageWithSwitch("15-LastPage", tutorial); Debug.LogWarning( Tr($"The created tutorial switch page doesn't have a Tutorial assiged. Please assign the '{tutorial.name}' object to the field 'Next Tutorial', in the Inspector of the object '{tutorialSwitchPage.name}'."), tutorialSwitchPage ); tutorial.AddPage(startPage); tutorial.AddPage(instructivePage); tutorial.AddPage(tutorialSwitchPage); tutorial.TutorialTitle = "New Tutorial"; tutorial.ProgressTrackingEnabled = true; tutorial.LessonId = Guid.NewGuid().ToString(); if (container) { TutorialContainer.Section lastTutorial = null; if (container.Sections.Length > 0) { lastTutorial = container.Sections.Where(s => !string.IsNullOrEmpty(s.TutorialId)).Last(); } TutorialContainer.Section section = new TutorialContainer.Section(); section.OrderInView = 0; section.Heading = "Tutorial title"; section.Text = "Tutorial description"; section.Tutorial = tutorial; TutorialContainer.Section[] updatedTutorials = new TutorialContainer.Section[container.Sections.Length + 1]; Array.Copy(container.Sections, updatedTutorials, container.Sections.Length); updatedTutorials[updatedTutorials.Length - 1] = section; container.Sections = updatedTutorials; } if (windowLayout) { tutorial.WindowLayout = windowLayout; } else { Debug.LogWarning(Tr($"The tutorial '{tutorial.name}' does not have a Window Layout assigned. Please assign one to its 'Window Layout' field in the Inspector if you want to load a new Window Layout when this tutorial starts."), tutorial); } tutorial.Version = "1"; EnsureAssetChangesAreSaved(tutorial); Debug.LogWarning( Tr($"The tutorial '{tutorial.name}' does not have a Scene assigned. Please assign one to its 'Scene' field in the Inspector if you want to load a specific Scene when this tutorial starts"), tutorial ); return(tutorial); }
public TutorialContainer parseTutorialFromXmlString(XmlNode xmlDocument) { var parts = xmlDocument.SelectSingleNode("TutorialSequence"); var tutorialContainer = new TutorialContainer(); if (parts != null) { // Then goes through each element foreach (XmlNode part in parts.ChildNodes) { var partIdString = ParseHelper.getAttributeValueByName(part, "id"); if (!int.TryParse(partIdString, out var partId)) { throw new Exception($"Could not parse part ID: {partIdString}"); } var partContainer = new PartContainer(partId); tutorialContainer.addPart(partContainer); var checkEvents = part.SelectNodes("CheckEvent"); var helpDisplays = part.SelectNodes("HelpDisplay"); var uiMasks = part.SelectNodes("TutorialUiMask"); if (checkEvents != null) { foreach (XmlNode checkEvent in checkEvents) { var typeString = ParseHelper.getAttributeValueByName(checkEvent, "type"); if (!Enum.TryParse(typeString, out CheckEventType checkEventType)) { throw new Exception($"Could not parse EventType: {typeString}"); } var idString = ParseHelper.getAttributeValueByName(checkEvent, "id"); if (!int.TryParse(idString, out var id)) { throw new Exception($"Could not parse id: {idString}"); } if (checkEventType == CheckEventType.ElementEvent || checkEventType == CheckEventType.PartElementEvent) { var elementIdString = ParseHelper.getAttributeValueByName(checkEvent, "elementId"); if (!int.TryParse(elementIdString, out var elementId)) { throw new Exception($"Could not parse elementId: {elementIdString}"); } if (checkEventType == CheckEventType.ElementEvent) { partContainer.addElement(new ElementCheckEvent(checkEvent.InnerText, elementId), id); } else { partIdString = ParseHelper.getAttributeValueByName(checkEvent, "partId"); if (!int.TryParse(partIdString, out partId)) { throw new Exception($"Could not parse partId: {partIdString}"); } partContainer.addElement(new PartElementCheckEvent(checkEvent.InnerText, partId, elementId), id); } } else if (checkEventType == CheckEventType.GameObjectEvent) { var gameObjectName = ParseHelper.getAttributeValueByName(checkEvent, "name"); partContainer.addElement(new GameObjectCheckEvent(checkEvent.InnerText, gameObjectName), id); } } } if (helpDisplays != null) { foreach (XmlNode helpDisplay in helpDisplays) { var typeString = ParseHelper.getAttributeValueByName(helpDisplay, "type"); if (!Enum.TryParse(typeString, out HelpDisplayType helpDisplayType)) { throw new Exception($"Could not parse EventType: {typeString}"); } var idString = ParseHelper.getAttributeValueByName(helpDisplay, "id"); if (!int.TryParse(idString, out var id)) { throw new Exception($"Could not parse id: {idString}"); } var parameters = new Dictionary <string, string>(); var parameterNodes = helpDisplay.SelectNodes("Parameter"); foreach (XmlNode parameterNode in parameterNodes) { var attributeName = parameterNode.Attributes[0].Value; parameters.Add(attributeName, parameterNode.InnerText); } partContainer.addElement(new HelpDisplayInitializer(helpDisplayType, parameters), id); } } if (uiMasks != null) { foreach (XmlNode uiMask in uiMasks) { var idString = ParseHelper.getAttributeValueByName(uiMask, "id"); if (!int.TryParse(idString, out var id)) { throw new Exception($"Could not parse id: {idString}"); } var parameters = new Dictionary <string, string>(); var parameterNodes = uiMask.SelectNodes("Parameter"); foreach (XmlNode parameterNode in parameterNodes) { var attributeName = parameterNode.Attributes[0].Value; parameters.Add(attributeName, parameterNode.InnerText); } partContainer.addElement(new TutorialUiMaskInitializer(parameters), id); } } } } return(tutorialContainer); }