Created
March 10, 2019 04:14
-
-
Save tsubaki/92df88b8a0e6939a9581d8602741b3cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.AddressableAssets; | |
public class SwapCharacter : MonoBehaviour | |
{ | |
[SerializeField] Animator parentAnimator; // 登録するAnimator | |
private GameObject cacheCharacter; // 差し替え時に元オブジェクトを削除する用 | |
public void Load(string characterName) | |
{ | |
Addressables.Instantiate(characterName, parentAnimator.transform, false).Completed +=(res)=> | |
{ | |
// 以前のキャラ情報を破棄 | |
if( cacheCharacter != null) | |
Addressables.ReleaseInstance(cacheCharacter); | |
cacheCharacter = res.Result; | |
// 再構築 | |
var childAnimator = res.Result.GetComponent<Animator>(); | |
parentAnimator.avatar = childAnimator.avatar; | |
parentAnimator.Rebind(); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment