// Attach style mesh, return the new game object. private GameObject AttachSkinComponent(GameObject attachingObject) { // Create one new object for this mesh renderer. GameObject attachingRoot = new GameObject(attachingObject.name); // Attach to avatar object. Vector3 oldScale = avatar.gameObject.transform.localScale; avatar.gameObject.transform.localScale = new Vector3(1, 1, 1); ObjectUtility.AttachToParentAndResetLocalPosAndRotation(avatar.AvatarObject, attachingRoot); // Copy SkinnedMeshRenderer. foreach (SkinnedMeshRenderer renderer in attachingObject.GetComponentsInChildren <SkinnedMeshRenderer>(true)) { // Create one new object for this mesh renderer. GameObject newSubMsh = new GameObject(renderer.sharedMesh.name); ObjectUtility.AttachToParentAndResetLocalPosAndRotation(attachingRoot, newSubMsh); // Copy renderer. SkinnedMeshRenderer newRenderer = newSubMsh.AddComponent <SkinnedMeshRenderer>(); newRenderer.sharedMesh = renderer.sharedMesh; newRenderer.sharedMaterials = renderer.sharedMaterials; newRenderer.quality = renderer.quality; newRenderer.updateWhenOffscreen = renderer.updateWhenOffscreen; Transform[] bones = new Transform[renderer.bones.Length]; for (int i = 0; i < renderer.bones.Length; i++) { var bone = ObjectUtility.FindChildObject(avatar.AvatarObject, renderer.bones[i].name); if (bone == null) { Debug.LogError(string.Format("Bone {0} is missing", renderer.bones[i].name)); continue; } bones[i] = bone; } newRenderer.bones = bones; } // Reset local scale. avatar.gameObject.transform.localScale = oldScale; // Set to current layer. ObjectUtility.SetObjectLayer(attachingRoot, avatar.gameObject.layer); return(attachingRoot); }
public void PlayFx(string parameter) { string effectName, parentGameObjectName; AnimationEventHandler.PlayFxParameter.Parse(parameter, out effectName, out parentGameObjectName); Transform parentGO = this.gameObject.transform; if (string.IsNullOrEmpty(parentGameObjectName) == false) { parentGO = ObjectUtility.FindChildObject(parentGO, parentGameObjectName); } FxManager.Instance.PlayFX(effectName, parentGO.gameObject, false, true, true, true); Debug.LogError("这里需要改,如果用的话"); }
// Mount style mesh. private GameObject MountComponent(Transform mountingObject, string mountBoneName, string mountingMakerName) { // Find mount mountBone. var mountBone = ObjectUtility.FindChildObject(avatar.AvatarObject, mountBoneName); if (mountBone == null) { #if ENABLE_AVATAR_COMPONENT_LOG Debug.LogWarning("Not found the mount bone on base object : " + mountBoneName); #endif return(null); } // Find mount mountBone in first depth children. var mountingBone = ObjectUtility.FindChildObject(mountingObject, mountingMakerName, true); if (mountingBone == null) { #if ENABLE_AVATAR_COMPONENT_LOG Debug.LogWarning("Not found the mount mountBone in usedComponent model: " + mountingObject.name + " " + mountingMakerName); #endif return(null); } // Create one new object for this usedComponent. Transform mountingRoot = new GameObject(mountingObject.gameObject.name).transform; ObjectUtility.UnifyWorldTrans(mountingBone, mountingRoot); // Attach to mounting root ObjectUtility.AttachToParentAndKeepWorldTrans(mountingRoot, mountingObject); // Set to layer. ObjectUtility.SetObjectLayer(mountingRoot.gameObject, avatar.gameObject.layer); // Attach to mount bone. Transform avatarTrans = avatar.gameObject.transform; Vector3 oldScale = avatarTrans.localScale; avatarTrans.localScale = Vector3.one; ObjectUtility.AttachToParentAndResetLocalPosAndRotation(mountBone, mountingRoot); avatarTrans.localScale = oldScale; return(mountingRoot.gameObject); }
// Play Pfx. public void PlayPfx(FXController fx, int destroyMode, int userData, string modelBone, string bone, bool boneFollow, Vector3 offset, Vector3 rotate, bool useSpecificPosition, Vector3 specificPosition) { // Set Render layer /** * Bug 记录。 * * 对于魔化卫庄的组合技,这个技能在主Action中有目标选择,但是每一个伤害事件都有自己的目标选择,最终可能有一种情况,即所有的EventTargetRecord中的目标均不包含Action选择的目标 * 在主Action中配置了一些播放特效的事件,这些事件服务器不作处理,也不会发给客户端,而是由客户端自己根据配置文件构建,构建时使用ActionRecord的TargetAvtarIndexs里的AvatarIndex, * 指定的AvatarIndex可能不在任何EventTargetRecord中,所以SkillCombatRound在遮罩屏幕时不会将这个角色点亮,导致“由这个角色”释放的特效也没有被点亮 * * 修改逻辑,如果正处于屏幕遮罩中,那么所有的特效都有应该具有SceneMaskLayer */ //BattleScene bs = BattleScene.GetBattleScene(); //int Layer = 0; //if (bs != null && bs.IsEnableSceneMask) // Layer = GameDefines.SceneMaskLayer; //else Layer = avatar.gameObject.layer; int Layer = avatar.gameObject.layer; // Set Render layer fx.Root.gameObject.layer = Layer; foreach (var subObj in fx.Root.GetComponentsInChildren <Transform>()) { subObj.gameObject.layer = Layer; } // If bone follow, attach to this bone. if (boneFollow) { var attachingGO = fx.Root; // Try to find specified if (modelBone != "") { var modelBoneObj = ObjectUtility.FindChildObject(attachingGO, modelBone); if (modelBoneObj != null) { attachingGO = modelBoneObj; } } // If specify bone, to this bone. if (bone != "") { var boneGO = ObjectUtility.FindChildObject(avatar.AvatarObject, bone); if (boneGO == null) { Debug.LogWarning(string.Format("Can not find bone:{0} in avatar", bone)); } ObjectUtility.AttachToParentAndResetLocalPosAndRotation(boneGO, attachingGO); } // Has no specify bone, to the root bone. else { ObjectUtility.AttachToParentAndResetLocalPosAndRotation(avatar.CachedTransform, attachingGO); } } // If not bone follow, just play at this bone position. else { // If specify bone, use this bone position. if (bone != "") { var boneGO = ObjectUtility.FindChildObject(avatar.CachedTransform, bone); if (boneGO == null) { Debug.LogWarning(string.Format("Can not find bone:{0} in avatar", bone)); } ObjectUtility.UnifyWorldTrans(boneGO, fx.Root); } // Has specific transform, use the transform. else if (useSpecificPosition) { fx.Root.position = specificPosition; } // Has no specify bone, use the root bone position. else { ObjectUtility.UnifyWorldTrans(avatar.CachedTransform, fx.Root); } } fx.Root.Translate(offset); fx.Root.Rotate(rotate); if (destroyMode != AvatarAction.Effect._DestroyType.Normal) { // Add to dictionary. var fxInst = new FxInst(fx, destroyMode, userData); fxMap[fxInst.instanceId] = fxInst; // Set auto destroy flag to Pfx script. //FXController PfxScript = fx.GetComponentInChildren<FXController>(); //if (PfxScript != null) { fx.autoDestroy = true; // Pfx will not loop except buff. if (destroyMode == AvatarAction.Effect._DestroyType.Buff) { fx.loop = true; } if (destroyMode == AvatarAction.Effect._DestroyType.BlockAction) { fx.AddFinishCallback(PfxFinishedBb, fxInst); } } } }