public IEnumerator PopulateCharacters() { //accessoriesSelector.gameObject.SetActive(false); m_UsedAccessory = -1; if (!m_IsLoadingCharacter) { m_IsLoadingCharacter = true; GameObject newChar = null; while (newChar == null) { Character c = CharacterDatabase.GetCharacter("cat"); if (c != null) { m_OwnedAccesories.Clear(); for (int i = 0; i < c.accessories.Length; ++i) { // Check which accessories we own. string compoundName = c.characterName + ":" + c.accessories[i].accessoryName; } // accessoriesSelector.gameObject.SetActive(m_OwnedAccesories.Count > 0); newChar = Instantiate(c.gameObject); Helpers.SetRendererLayerRecursive(newChar, k_UILayer); newChar.transform.SetParent(charPosition, false); newChar.transform.rotation = k_FlippedYAxisRotation; if (m_Character != null) { Destroy(m_Character); } m_Character = newChar; //charNameDisplay.text = c.characterName; m_Character.transform.localPosition = Vector3.right * 1000; //animator will take a frame to initialize, during which the character will be in a T-pose. //So we move the character off screen, wait that initialised frame, then move the character back in place. //That avoid an ugly "T-pose" flash time yield return(new WaitForEndOfFrame()); m_Character.transform.localPosition = Vector3.zero; } else { yield return(new WaitForSeconds(1.0f)); } } m_IsLoadingCharacter = false; } }
public IEnumerator PopulateCharacters() { if (!m_IsLoadingCharacter) { m_IsLoadingCharacter = true; GameObject newChar = null; while (newChar == null) { Character c = CharacterDatabase.GetCharacter(PlayerData.instance.characters[PlayerData.instance.usedCharacter]); if (c != null) { AsyncOperationHandle op = Addressables.InstantiateAsync(c.characterName); yield return(op); if (op.Result == null || !(op.Result is GameObject)) { Debug.LogWarning(string.Format("Unable to load character {0}.", c.characterName)); yield break; } newChar = op.Result as GameObject; Helpers.SetRendererLayerRecursive(newChar, k_UILayer); newChar.transform.SetParent(charPosition, false); newChar.transform.rotation = k_FlippedYAxisRotation; if (m_Character != null) { Addressables.ReleaseInstance(m_Character); } m_Character = newChar; charNameDisplay.text = c.characterName; m_Character.transform.localPosition = Vector3.right * 1000; //animator will take a frame to initialize, during which the character will be in a T-pose. //So we move the character off screen, wait that initialised frame, then move the character back in place. //That avoid an ugly "T-pose" flash time yield return(new WaitForEndOfFrame()); m_Character.transform.localPosition = Vector3.zero; SetupAccessory(); } else { yield return(new WaitForSeconds(1.0f)); } } m_IsLoadingCharacter = false; } }
public void Begin() { if (!m_Rerun) { if (m_TrackSeed != -1) { Random.InitState(m_TrackSeed); } else { Random.InitState((int)System.DateTime.Now.Ticks); } // Since this is not a rerun, init the whole system (on rerun we want to keep the states we had on death) m_CurrentSegmentDistance = k_StartingSegmentDistance; m_TotalWorldDistance = 0.0f; characterController.gameObject.SetActive(true); // Spawn the player Character player = Instantiate(CharacterDatabase.GetCharacter(PlayerData.instance.characters[PlayerData.instance.usedCharacter]), Vector3.zero, Quaternion.identity); player.transform.SetParent(characterController.characterCollider.transform, false); Camera.main.transform.SetParent(characterController.transform, true); player.SetupAccesory(PlayerData.instance.usedAccessory); characterController.character = player; characterController.trackManager = this; characterController.Init(); characterController.CheatInvincible(invincible); if (m_IsTutorial) { m_CurrentThemeData = tutorialThemeData; } else { m_CurrentThemeData = ThemeDatabase.GetThemeData(PlayerData.instance.themes[PlayerData.instance.usedTheme]); } m_CurrentZone = 0; m_CurrentZoneDistance = 0; skyMeshFilter.sharedMesh = m_CurrentThemeData.skyMesh; RenderSettings.fogColor = m_CurrentThemeData.fogColor; RenderSettings.fog = true; gameObject.SetActive(true); characterController.gameObject.SetActive(true); characterController.coins = 0; characterController.premium = 0; m_Score = 0; m_ScoreAccum = 0; m_SafeSegementLeft = m_IsTutorial ? 0 : k_StartingSafeSegments; Coin.coinPool = new Pooler(currentTheme.collectiblePrefab, k_StartingCoinPoolSize); PlayerData.instance.StartRunMissions(this); #if UNITY_ANALYTICS AnalyticsEvent.GameStart(new Dictionary <string, object> { { "theme", m_CurrentThemeData.themeName }, { "character", player.characterName }, { "accessory", PlayerData.instance.usedAccessory >= 0 ? player.accessories[PlayerData.instance.usedAccessory].accessoryName : "none" } }); #endif } characterController.Begin(); StartCoroutine(WaitToStart()); }
public IEnumerator PopulateCharacters() { accessoriesSelector.gameObject.SetActive(false); PlayerData.instance.usedAccessory = -1; m_UsedAccessory = -1; if (!m_IsLoadingCharacter) { m_IsLoadingCharacter = true; GameObject newChar = null; while (newChar == null) { Character c = CharacterDatabase.GetCharacter(PlayerData.instance.characters[PlayerData.instance.usedCharacter]); if (c != null) { m_OwnedAccesories.Clear(); for (int i = 0; i < c.accessories.Length; ++i) { // Check which accessories we own. string compoundName = c.characterName + ":" + c.accessories[i].accessoryName; if (PlayerData.instance.characterAccessories.Contains(compoundName)) { m_OwnedAccesories.Add(i); } } Vector3 pos = charPosition.transform.position; if (m_OwnedAccesories.Count > 0) { pos.x = k_OwnedAccessoriesCharacterOffset; } else { pos.x = 0.0f; } charPosition.transform.position = pos; accessoriesSelector.gameObject.SetActive(m_OwnedAccesories.Count > 0); AsyncOperationHandle op = Addressables.InstantiateAsync(c.characterName); yield return(op); if (op.Result == null || !(op.Result is GameObject)) { Debug.LogWarning(string.Format("Unable to load character {0}.", c.characterName)); yield break; } newChar = op.Result as GameObject; Helpers.SetRendererLayerRecursive(newChar, k_UILayer); newChar.transform.SetParent(charPosition, false); newChar.transform.rotation = k_FlippedYAxisRotation; if (m_Character != null) { Addressables.ReleaseInstance(m_Character); } m_Character = newChar; charNameDisplay.text = c.characterName; m_Character.transform.localPosition = Vector3.right * 1000; //animator will take a frame to initialize, during which the character will be in a T-pose. //So we move the character off screen, wait that initialised frame, then move the character back in place. //That avoid an ugly "T-pose" flash time yield return(new WaitForEndOfFrame()); m_Character.transform.localPosition = Vector3.zero; SetupAccessory(); } else { yield return(new WaitForSeconds(1.0f)); } } m_IsLoadingCharacter = false; } }
/// <summary> /// 从数据库查询并加载角色信息 /// </summary> /// <returns></returns> public IEnumerator PopulateCharacters() { accessoriesSelector.gameObject.SetActive(false); PlayerData.instance.usedAccessory = -1; m_UsedAccessory = -1; if (!m_IsLoadingCharacter) { m_IsLoadingCharacter = true; GameObject newChar = null; while (newChar == null) { Character c = CharacterDatabase.GetCharacter(PlayerData.instance.characters[PlayerData.instance.usedCharater]); if (c != null) { m_OwnedAccesories.Clear(); for (int i = 0; i < c.accessories.Length; ++i) { //初始化已拥有的装饰 string compoundName = c.characterName + ":" + c.accessories[i].accessoryName; if (PlayerData.instance.characterAccessories.Contains(compoundName)) { m_OwnedAccesories.Add(i); } } //设置位置 Vector3 pos = charPosition.transform.position; if (m_OwnedAccesories.Count > 0) { pos.x = k_OwnedAccessoriesCharacterOffset; } else { pos.x = 0.0f; } charPosition.transform.position = pos; accessoriesSelector.gameObject.SetActive(m_OwnedAccesories.Count > 0); //初始化角色显示 newChar = Instantiate(c.gameObject); Helpers.SetRendererLayerRecursive(newChar, k_UILayer); newChar.transform.SetParent(charPosition, false); newChar.transform.rotation = k_FlippedYAxisRotation; if (m_Character != null) { Destroy(m_Character); } //初始化角色名字 m_Character = newChar; charNameDisplay.text = c.characterName; m_Character.transform.localPosition = Vector3.right * 1000; // 动画师需要一个帧来初始化,在此期间角色将处于一个t型。 // 我们将字符移出屏幕,等待初始帧,然后将字符移回原位。 // 避免出现难看的“t - pose”闪光时间 yield return(new WaitForEndOfFrame()); m_Character.transform.localPosition = Vector3.zero; SetupAccessory(); } else { yield return(new WaitForSeconds(1.0f)); } } m_IsLoadingCharacter = false; } }