void startPlacement(BuyObject buyObject) { if (placingObject != null) { Destroy(placingObject); OnPlacementInteract?.Invoke(true, true); } else { OnPlacementInteract?.Invoke(true); } placingObject = Instantiate(buyObject.GetBuyObjectScriptable().prefab); placingObject.transform.rotation = Quaternion.Euler(0, 130, 0); if (placingObject.GetComponent <BuyObjectBehaviour>() == null) { placingObject.AddComponent <BuyObjectBehaviour>(); } placingObject.GetComponent <BuyObjectBehaviour>().Initialize(buyObject.BuyValue, buyObject.SatisfactionGain); currentBuyObject = buyObject; meshBounds = placingObject.GetComponent <Collider>().bounds; ignoredPlanes = getIgnorableTransforms(placingObject); PointAndClickMovement.setMovementStatus(false); MainCanvas.mainCanvas.freezeOverride = true; SetPlacing(true); if (placingObject.GetComponent <WorldInteractive>() != null) { placingObject.GetComponent <WorldInteractive>().beingMoved = true; } }
// Funktion void Update() { // Verweise der Variable TotalCost auf die Komponente BuyObject der Variable ToBuyObject TotalCost = ToBuyObject.GetComponent <BuyObject> (); // WENN Objekt gekauft wurde, bzw. aktiv ist // DANN deaktiviere den Button und lasse den checkArrow anzeigen // ANSONSTEN WENN die Kosten groesser als das verfuegbare Geld sind // DANN setze den Kaufbutton auf Inaktiv und setze zusaetzlich den CheckArrow nochmal auf inaktiv // ANSONSTEN WENN die Kosten kleiner oder gleich dem verfuegbaren Geld sind // DANN setze den Kaufbutton auf Aktiv, aber lasse den checkArrow noch inaktiv if (ToBuyObject.activeSelf == true) { // BuyButton.interactable = false; checkArrow.SetActive(true); } else if (TotalCost.totalcost > availableMoney.money) { BuyButton.interactable = false; checkArrow.SetActive(false); } else if (TotalCost.totalcost <= availableMoney.money) { BuyButton.interactable = true; checkArrow.SetActive(false); } }
// Save function public void Save() { // A new Binary Format BinaryFormatter binary = new BinaryFormatter(); // To write files: Open the FileStream and wirte saveFile.tavern in the persistentDataPath (appdata) of the Application FileStream fStream = File.Create(Application.persistentDataPath + "/saveFile.tavern"); // To Read out the Data of the SaveManager class // Reference to Savemanager SaveManager saver = new SaveManager(); // Saves the money to saver saver.currentMoney = PlayerResources.Instance.money; // saves the current round to saver saver.currentRound = RoundSystem.Instance.currentRound; // ===== Inventory Save ===== string content = string.Empty; //Creates a string for containing infor about the items inside the inventory for (int i = 0; i < Inventory.Instance.AllSlots.Count; i++) //Runs through all slots in the inventory { Slot tmp = Inventory.Instance.AllSlots[i].GetComponent <Slot>(); //Creates a reference to the slot at the current index if (!tmp.IsEmpty) //We only want to save the info if the slot contains an item { //Creates a string with this format: SlotIndex-ItemType-AmountOfItems; this string can be read so that we can rebuild the inventory content += i + "-" + tmp.CurrentItem.type.ToString() + "-" + tmp.Items.Count.ToString() + ";"; } } // saves the content string to saver saver.inventoryContent = content; // Saves the rows to saver saver.currentRows = Inventory.Instance.rows; // Saves the slots to saver saver.currentSlots = Inventory.Instance.slots; // ===== Inventory Save Finish ===== // ===== BuyObject List ===== content = string.Empty; foreach (GameObject objectTmp in buyObjectsList) { BuyObject buyObjectTmp = objectTmp.GetComponent <BuyObject>(); if (objectTmp.activeSelf == true) { content += buyObjectTmp.objectName + "-true;"; } } saver.buyObjectContent = content; // all other... // Save "saver" to FileStream "fStream" binary.Serialize(fStream, saver); // Close the file stream (end file writing) fStream.Close(); }
void callForPurchase() { OnObjectPurchase?.Invoke(currentBuyObject); OnObjectSatisfaction?.Invoke(currentBuyObject.SatisfactionGain); PlayerEconomy.createPurchase(currentBuyObject.BuyName, -currentBuyObject.BuyValue); currentBuyObject = null; }
void Start() { // Variable availableMoney enthaelt die Klasse PlayerResources availableMoney = GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerResources>(); // Verweise der Variable TotalCost auf die Komponente BuyObject der Variable ToBuyObject TotalCost = ToBuyObject.GetComponent <BuyObject> (); }
static void Main(string[] args) { var results = new Dictionary <string, TimeSpan>(); Console.WriteLine("AnyClone Performance Testing"); var buyObject = new BuyObject() { AcceptedFrom = Guid.NewGuid(), ActualSnapshot = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, AdId = 100, BuyTypeId = BuyType.NoFee, Id = 999, RowVersion = 111, SkipVersionIncrement = true, ExternalOrderVersion = 2, ChildHeaderId = 123234234 }; var clonedObjects = new List <BuyObject>(); // clone using AnyClone var timer = new Stopwatch(); Console.WriteLine($"Measuring AnyClone.Clone() X {TestObjects:N0}..."); timer.Start(); for (var i = 0; i < TestObjects; i++) { clonedObjects.Add(buyObject.Clone(CloneOptions.DisableIgnoreAttributes)); } timer.Stop(); results.Add("AnyClone", timer.Elapsed); Console.WriteLine($"AnyClone took {timer.Elapsed}"); clonedObjects.Clear(); Console.WriteLine($"Measuring DeepCloner.DeepClone() X {TestObjects:N0}..."); timer.Restart(); for (var i = 0; i < TestObjects; i++) { clonedObjects.Add(buyObject.DeepClone()); } timer.Stop(); results.Add("DeepCloner", timer.Elapsed); Console.WriteLine($"DeepCloner took {timer.Elapsed}"); Console.WriteLine($"\r\nFinished performance tests!\r\n"); Console.WriteLine($"Results: \r\n"); var resultNumber = 1; foreach (var result in results.OrderBy(x => x.Value)) { Console.WriteLine($"#{resultNumber}: {result.Key} took {result.Value}, {(result.Value.TotalMilliseconds / TestObjects):N2}ms per clone operation"); resultNumber++; } }
public void Should_Clone_BuyObject() { // this test represents cloning of a very complex class var original = new BuyObject(); var cloned = original.Clone(); Func <BuyObject, int> func = i => 100; Expression <Func <BuyObject, int> > newUnits = i => func(i); cloned.Units = newUnits; Assert.IsNotNull(cloned); Assert.AreEqual(newUnits, cloned.Units); Assert.AreNotEqual(newUnits, original.Units); }
void resetInteraction() { SetPlacing(false); SetMoving(false); PointAndClickMovement.setMovementStatus(true); MainCanvas.mainCanvas.freezeOverride = false; ignoredPlanes.Clear(); if (placingObject != null) { Destroy(placingObject); currentBuyObject = null; } OnPlacementInteract?.Invoke(false); }
// Load function public void Load() { // If the savegame exists if (File.Exists(Application.persistentDataPath + "/saveFile.tavern")) { // A new binary Formatter BinaryFormatter binary = new BinaryFormatter(); // Open the filestream of the .tavern file FileStream fstream = File.Open(Application.persistentDataPath + "/saveFile.tavern", FileMode.Open); // Take Data out of File Stream, deserialize them and save them in "saver" SaveManager saver = (SaveManager)binary.Deserialize(fstream); // Close the file stream fstream.Close(); // Read the playermoney of the savegame PlayerResources.Instance.money = saver.currentMoney; // Read the currentRound of the savegame RoundSystem.Instance.currentRound = saver.currentRound; // Creates a new string to read the Inventory String of the savegame file string content = saver.inventoryContent; // If the string is NOT empty if (content != string.Empty) { // Read the rows Inventory.Instance.rows = saver.currentRows; // Read the slots Inventory.Instance.slots = saver.currentSlots; // Layout muss neu geschrieben werden: FUNKTIONIERT AUS IRGENDEINEM GRUND NICHT // EINFACH KOMMENTAR WEGMACHEN ZUM TESTEN. Der uebrige Code, der die reihen und slots speichert ist noch aktiv // Inventory.Instance.CreateLayout(); // Should recreate the Layout...does not work?! //Splits the loaded content string into segments, so that each index in the splitContent array contains information about a single slot //e.g[0]0-MANA-3 string[] splitContent = content.Split(';'); //Runs through every single slot we have information about -1 is to avoid an empty string error for (int x = 0; x < splitContent.Length - 1; x++) { //Splits the slot's information into single values, so that each index in the splitValues array contains info about a value //E.g[0]InventorIndex [1]ITEMTYPE [2]Amount of items string[] splitValues = splitContent[x].Split('-'); //int index = Int32.Parse(splitValues[0]); //InventorIndex string itemName = splitValues[1]; //ITEMTYPE int amount = Int32.Parse(splitValues[2]); //Amount of items Item tmp = null; // Resets the tmp Item for (int i = 0; i < amount; i++) //Adds the correct amount of items to the inventory { // Run through the itemList which is attached to SaveLoad (look at the top of the script) // This loop is necessary because we can not add items from nothing // We need the reference list to check which Item is to add foreach (GameObject tmpItem in itemList) { // Create a temporary reference to the Item script Item tmp1 = tmpItem.GetComponent <Item>(); // If tmp is empty if (tmp == null) { // If the itemType (saved in itemName) is the same type as the one of the list (toString to make them compareable, because itemName is a string) if (itemName == tmp1.type.ToString()) { // THEN save the current Item of the foreach-Loop in ladedItem GameObject loadedItem = tmpItem; // And add it to the Inventory Inventory.Instance.AddItem(loadedItem.GetComponent <Item>()); //Destroy(loadedItem);// Necessary? If Item is destroyed it cannot be bought anymore? } } } } } } // Resets content string string to read the buyObject String of the savegame file content = string.Empty; content = saver.buyObjectContent; if (content != string.Empty) { //Splits the loaded content string into segments, so that each index in the splitContent array contains information about a single slot //e.g[0]Table1-true; string[] splitContent = content.Split(';'); for (int x = 0; x < splitContent.Length - 1; x++) { //Splits the slot's information into single values, so that each index in the splitValues array contains info about a value //E.g[0]InventorIndex [1]ITEMTYPE [2]Amount of items string[] splitValues = splitContent[x].Split('-'); string buyObjectName = splitValues[0]; //ITEMNAME bool isBought = Boolean.Parse(splitValues[1]); //IS AKTIVE? BuyObject tmp = null; // Resets the tmp Item foreach (GameObject tmpBuyObject in buyObjectsList) { // Create a temporary reference to the Item script BuyObject tmp1 = tmpBuyObject.GetComponent <BuyObject>(); // If tmp is empty if (tmp == null) { // If the itemType (saved in itemName) is the same type as the one of the list (toString to make them compareable, because itemName is a string) if (buyObjectName == tmp1.objectName.ToString() && isBought == true) { tmpBuyObject.SetActive(true); } } } } } //all other... } }