Advertisement
Wyv3rn

Untitled

Feb 18th, 2023
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [CreateAssetMenu]
  6. public class LocalShipDB : ScriptableObject, ISerializationCallbackReceiver
  7. {
  8.     [SerializeField]
  9.     public Dictionary<string, GameObject> SpawnableShips = new Dictionary<string, GameObject>();
  10.     [SerializeField]
  11.     public GameObject[] Ships;
  12.  
  13.     void loadShips()
  14.     {
  15.         foreach (GameObject Ship in Ships)
  16.         {
  17.             ShipData ShipInfo = Ship.GetComponent<ShipData>();
  18.             if (!SpawnableShips.ContainsKey(ShipInfo.ShipID.ToString()))
  19.             {
  20.                 SpawnableShips.Add(ShipInfo.ShipID.ToString(), Ship);
  21.             }
  22.         }
  23.     }
  24.  
  25.     public GameObject GetShip(int ItemID)
  26.     {
  27.         GameObject Ship = SpawnableShips[ItemID.ToString()];
  28.         return Ship;
  29.     }
  30.  
  31.     public void InitData()
  32.     {
  33.         loadShips();
  34.     }
  35.  
  36.     public void OnBeforeSerialize()
  37.     {
  38.  
  39.     }
  40.  
  41.     public void OnAfterDeserialize()
  42.     {
  43.  
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement