Advertisement
Guest User

CharacterManager.cs

a guest
Apr 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6.  
  7. //Holder styr på at tilføje mm. characters.
  8. public class CharacterManager : MonoBehaviour {
  9.  
  10.     public static CharacterManager instance;
  11.  
  12.     //Characters skal være under characterPanel.
  13.     public RectTransform characterPanel;
  14.  
  15.  
  16.     //Liste med alle characters i scenen.
  17.     public List<Characters> characters = new List<Characters>();
  18.  
  19.     //Nem måde at søge efter vores characters.
  20.     public Dictionary<string, int> characterDictionary = new Dictionary<string, int>();
  21.  
  22.     void Awake()
  23.     {
  24.         instance = this;
  25.     }
  26.  
  27.     //Prøver at finde en character med det givne navn fra character listen.
  28.     public Characters GetCharacter(string characterName, bool createCharacterIfDoesNotExist = true, bool enableCreatedCharacterOnStart = true)
  29.     {
  30.         int index = -1;
  31.         if (characterDictionary.TryGetValue (characterName, out index))
  32.         {
  33.             return characters[index];
  34.         }
  35.         else if (createCharacterIfDoesNotExist)
  36.         {
  37.             return CreateCharacter(characterName, enableCreatedCharacterOnStart);
  38.         }
  39.  
  40.         return null;
  41.     }
  42.  
  43.     public Characters CreateCharacter(string characterName, bool enableOnStart = true)
  44.     {
  45.         Characters newCharacter = new Characters(characterName, enableOnStart);
  46.  
  47.         characterDictionary.Add(characterName, characters.Count);
  48.         characters.Add(newCharacter);
  49.  
  50.         return newCharacter;
  51.  
  52.     }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement