/// <summary> /// Try to load the textures for a player skin from disk at the given path. This path should be /// the full path ending in the directory that contains the texture files. /// </summary> /// <param name="path">The full path of a directory containing a player skin.</param> /// <param name="playerSkin">If the method returns, will contain the loaded player skin or a fallback /// empty player skin if no skin could be loaded.</param> /// <returns>true if the skin could be loaded, false otherwise.</returns> private bool LoadTexturesForSkin(string path, out PlayerSkin playerSkin) { // Fallback out value to make sure we can always return false if loading failed playerSkin = new PlayerSkin(); if (!Directory.Exists(path)) { return(false); } var knightPath = Path.Combine(path, KnightTextureFileName); if (LoadTexture(knightPath, out var knightTexture)) { playerSkin.SetKnightTexture(knightTexture); } var sprintPath = Path.Combine(path, SprintTextureFileName); if (LoadTexture(sprintPath, out var sprintTexture)) { playerSkin.SetSprintTexture(sprintTexture); } return(true); }
/// <summary> /// Store the default player skin from the given hero controller. /// </summary> /// <param name="heroController">The HeroController instance.</param> private void StoreDefaultPlayerSkin(HeroController heroController) { var localPlayerObject = heroController.gameObject; var spriteAnimator = localPlayerObject.GetComponent <tk2dSpriteAnimator>(); if (spriteAnimator == null) { return; } // Get the knight and sprint texture from the sprite definitions of the respective animation clips // in the sprite animator of the local HeroController object var knightTexture = spriteAnimator .GetClipByName("Idle")? .frames[0]? .spriteCollection .spriteDefinitions[0]? .material .mainTexture as Texture2D; var sprintTexture = spriteAnimator .GetClipByName("Sprint")? .frames[0]? .spriteCollection .spriteDefinitions[0]? .material .mainTexture as Texture2D; if (knightTexture == null) { Logger.Get().Warn(this, "Tried to store default player skin, but knight texture was null"); return; } if (sprintTexture == null) { Logger.Get().Warn(this, "Tried to store default player skin, but sprint texture was null"); return; } _defaultPlayerSkin = new PlayerSkin(); _defaultPlayerSkin.SetKnightTexture(knightTexture); _defaultPlayerSkin.SetSprintTexture(sprintTexture); }