using System; using System.Collections.Generic; using UnityEngine; public class AtomeFactory : MonoBehaviour{ public TextAsset jsonFile; private static AtomeFactory instance; private AtomesInformation atomeInJson; private Dictionary AtomeDictionary; public AtomeFactory(TextAsset jsonFile){ AtomeFactory.instance = this; AtomeDictionary = new Dictionary(); atomeInJson = JsonUtility.FromJson(jsonFile.text); foreach (var atome in atomeInJson.atomes){ AtomeDictionary.Add(atome.symbol, atome); } } public static AtomeFactory getInstrance(){ if(AtomeFactory.instance == null){ Debug.LogError("no Json file"); } return AtomeFactory.instance; } public static AtomeFactory getInstrance(TextAsset jsonFile){ if(AtomeFactory.instance == null){ AtomeFactory.instance = new AtomeFactory(jsonFile); } return AtomeFactory.instance; } public AtomeInformation createAtome(string symbol){ if(!AtomeDictionary.ContainsKey(symbol)){ Debug.LogError("Atome does not existe in json"); return null; } AtomeInformation atome = AtomeDictionary[symbol]; return atome; } public GameObject createAnimatedAtome(string atome) { if(!AtomeDictionary.ContainsKey(symbol)){ Debug.LogError("Atome does not existe in json"); return null; } AtomeInformation atome = AtomeDictionary[symbol]; //return le gameObject } }