コード例 #1
0
ファイル: SkinLoader.cs プロジェクト: jngo102/HKMP
        /**
         * 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.
         */
        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(null, null);

            if (!Directory.Exists(path))
            {
                return(false);
            }

            var knightPath = Path.Combine(path, KnightTextureFileName);

            if (!LoadTexture(knightPath, out var knightTexture))
            {
                return(false);
            }

            var sprintPath = Path.Combine(path, SprintTextureFileName);

            if (!LoadTexture(sprintPath, out var sprintTexture))
            {
                return(false);
            }

            playerSkin = new PlayerSkin(knightTexture, sprintTexture);
            return(true);
        }
コード例 #2
0
        /// <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);
        }