Advertisement
dronkowitz

DataConversion.cs

Dec 23rd, 2022 (edited)
1,315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public static class DataConversion
  6. {
  7.     public static string ItemsToString(Item[] items)
  8.     {
  9.         string output = "";
  10.         foreach (Item item in items)
  11.         {
  12.             if (item != null)
  13.             {
  14.                 output += item.itemID + "/";
  15.             }
  16.             else
  17.             {
  18.                 output += " /";
  19.             }
  20.         }
  21.         return output;
  22.     }
  23.  
  24.     public static Item[]StringToItems(string data)
  25.     {
  26.         Item[] allItems = Resources.LoadAll<Item>("");
  27.         List<Item> items = new List<Item>();
  28.         string[] dataArray = data.Split(char.Parse("/"));
  29.         foreach (string item in dataArray)
  30.         {
  31.             bool foundMatch = false;
  32.             foreach(Item i in allItems)
  33.             {
  34.                 if (i.itemID == item)
  35.                 {
  36.                     items.Add(i);
  37.                     foundMatch = true;
  38.                     break;
  39.                 }
  40.             }
  41.             if (!foundMatch)
  42.             {
  43.                 items.Add(null);
  44.             }
  45.             Debug.Log(item);
  46.         }
  47.         return items.ToArray();
  48.     }
  49.  
  50.     public static string QuestsToString(Quest[] quests)
  51.     {
  52.         string output = "";
  53.         foreach (Quest quest in quests)
  54.         {
  55.             if (quest != null)
  56.             {
  57.                 output += quest.questID + ",";
  58.                 foreach(QuestTask task in quest.tasks)
  59.                 {
  60.                     //required item
  61.                     //number to collect
  62.                     //target character
  63.                     //things to kill
  64.                     //number to kill
  65.                     //target location
  66.                     //escort target
  67.                 }
  68.             }
  69.             else
  70.             {
  71.                 output += " /";
  72.             }
  73.         }
  74.         return output;
  75.     }
  76.  
  77.     public static Quest[] StringToQuests(string data)
  78.     {
  79.         Quest[] allQuests = Resources.LoadAll<Quest>("");
  80.         List<Quest> quests = new List<Quest>();
  81.         string[] dataArray = data.Split(char.Parse("/"));
  82.         foreach (string quest in dataArray)
  83.         {
  84.             bool foundMatch = false;
  85.             foreach (Quest i in allQuests)
  86.             {
  87.                 if (i.questID == quest)
  88.                 {
  89.                     quests.Add(i);
  90.                     foundMatch = true;
  91.                     break;
  92.                 }
  93.             }
  94.             if (!foundMatch)
  95.             {
  96.                 quests.Add(null);
  97.             }
  98.            
  99.         }
  100.         return quests.ToArray();
  101.     }
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement