Esempio n. 1
0
        // Add the sprites to the repo ready for retrieval
        public void RegisterCharacterSprites(DialogueSprites_SO sprites)
        {
            if (_characterSprites.ContainsKey(sprites.CharactersName))
            {
                DialogueLogger.LogWarning($"Character sprites for {sprites.CharactersName} already exist, overwritting");
            }

            if (validateSprites(sprites))
            {
                _characterSprites[sprites.CharactersName] = sprites;
            }
        }
Esempio n. 2
0
        // Check all values are valid
        private bool validateSprites(DialogueSprites_SO sprites)
        {
            var names = new List <string>();

            if (sprites.CharacterSprites.Count == 0)
            {
                DialogueLogger.LogWarning($"Trying to register character sprites for {sprites.CharactersName} but the sprite list is empty");
            }

            foreach (var spritePair in sprites.CharacterSprites)
            {
                // Check name
                if (string.IsNullOrEmpty(spritePair.Name) || string.IsNullOrWhiteSpace(spritePair.Name))
                {
                    DialogueLogger.LogError($"Error registering character sprites for {sprites.CharactersName}, one or more of the names is empty");
                    return(false);
                }

                // Check for duplicate names
                if (names.Contains(spritePair.Name))
                {
                    DialogueLogger.LogError($"Error registering character sprites for {sprites.CharactersName}, there is already a sprite with the name {spritePair.Name}. Each sprite must have a unique name");
                    return(false);
                }

                names.Add(spritePair.Name);

                // Check sprites
                if (spritePair.Sprite == null)
                {
                    DialogueLogger.LogError($"Error registering character sprites for {sprites.CharactersName} with the sprite name {spritePair.Name}, but the sprite is empty");
                    return(false);
                }
            }

            return(true);
        }