Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3.  
  4. public class ShipObject
  5. {
  6.     private static int m_ShipCounter;
  7.     private readonly int m_ShipId;
  8.  
  9.     public ShipObject()
  10.     {
  11.         m_ShipCounter++;
  12.         m_ShipId = m_ShipCounter;
  13.     }
  14.  
  15.     public override int GetHashCode ()
  16.     {
  17.         return m_ShipId;
  18.     }
  19. }
  20.  
  21. public class ShipsContainer
  22. {
  23.     private Dictionary<int, ShipObject> m_ShipDict = new Dictionary<int, ShipObject> ();
  24.  
  25.     public void AddShip(ShipObject ship)
  26.     {
  27.         m_ShipDict.Add (ship.GetHashCode (), ship);
  28.     }
  29.  
  30.     public ShipObject GetShipByHash(int hash)
  31.     {
  32.         return m_ShipDict [hash];
  33.     }
  34.  
  35.     public void RemoveShip(int hash)
  36.     {
  37.         if (m_ShipDict.ContainsKey (hash))
  38.         {
  39.             m_ShipDict.Remove (hash);
  40.             return;
  41.         }
  42.  
  43.         Debug.Log ("Ship not found!");
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement