private void OnTimerUpInitCharacter(int seq, object arg) { TimerManager.instance.RemoveTimer(OnTimerUpInitCharacter); IDictionary partitions = arg as IDictionary; if (m_CharacterInstance == null) { return; } AvatarComponent avatar = m_CharacterInstance.GetComponent <AvatarComponent>(); if (avatar == null) { avatar = m_CharacterInstance.AddComponent <AvatarComponent>(); int partitionCount = m_Partitions.Count; for (int i = 0; i < partitionCount; i++) { if (partitions != null && partitions.Contains(m_Partitions[i].Name)) { avatar.AddPartition(m_Partitions[i].Name, partitions[m_Partitions[i].Name].ToString()); if (IsPlayer) { PartitionObject.PlayerPartitions.Add(partitions[m_Partitions[i].Name].ToString()); } } else { avatar.AddPartition(m_Partitions[i].Name, m_Partitions[i].AssetName); if (IsPlayer) { PartitionObject.PlayerPartitions.Add(m_Partitions[i].AssetName); } } } } OnTimerUpInitAvatar(0, avatar); }
/// <summary> /// 实例化角色.将根据身上记录的部件数据组装 /// </summary> public void InstantiateCharacter() { if (m_MoveSetPrefab != null) { if (m_CharacterInstance == null) { // EB.Debug.LogObjectMgrAsset("<color=#ff0000>克隆CharacterVariant变体身上记录的预置体</color>同时身上的部件进行初始化,<color=#00ff00>{0}</color>", m_MoveSetPrefab.name); m_CharacterInstance = GameObject.Instantiate(m_MoveSetPrefab, transform.position, transform.rotation) as GameObject; m_CharacterInstance.name = m_MoveSetPrefab.name; AvatarComponent avatar = m_CharacterInstance.GetComponent <AvatarComponent>(); if (avatar == null) { avatar = m_CharacterInstance.AddComponent <AvatarComponent>(); int partitionCount = m_Partitions.Count; for (int i = 0; i < partitionCount; i++) { avatar.AddPartition(m_Partitions[i].Name, m_Partitions[i].AssetName); if (IsPlayer) { PartitionObject.PlayerPartitions.Add(m_Partitions[i].AssetName); } } } avatar.PreviewTransformName = string.IsNullOrEmpty(PreviewTransform) ? DefaultPreviewTransform : PreviewTransform; avatar.RootBoneTransformName = string.IsNullOrEmpty(RootBoneTransform) ? DefaultRootBoneTransform : RootBoneTransform; avatar.SyncLoad = SyncLoad; avatar.InitAvatar(); m_CharacterInstance.transform.SetParent(transform.parent); } else { // EB.Debug.LogObjectMgrAsset("<color=#00ffff>已经_克隆过这个预置体</color>:<color=#00ff00>{0}</color>,将其设置可见", m_MoveSetPrefab.name); m_CharacterInstance.transform.SetParent(transform.parent); m_CharacterInstance.CustomSetActive(true); AvatarComponent avatar = m_CharacterInstance.GetComponent <AvatarComponent>(); if (avatar != null) { avatar.SyncLoad = SyncLoad; int partitionCount = m_Partitions.Count; for (int i = 0; i < partitionCount; i++) { avatar.LoadEquipment(m_Partitions[i].Name, m_Partitions[i].AssetName); if (IsPlayer) { PartitionObject.PlayerPartitions.Add(m_Partitions[i].AssetName); } } } } InitFX(m_MoveSetPrefab.name); } else { EB.Debug.LogError("[" + Time.frameCount + "]为什么角色变体没有相应的预置体呢?"); } //TimerManager.instance.AddLateUpdateTimer(70, 1, OnTimerUp); }