public static bool HasObstacleBetweenPlayerAndItem(PlayerEntity player, Vector3 targetCenter, GameObject item) { // Logger.Debug("HasObstacleBeteenPlayerAndItem"); if (null == player) { Logger.Error("player is null"); return(true); } _castCount = 0; /*var startPoint = player.cameraStateOutputNew.FinalArchorPosition; * int mask = ~(UnityLayerManager.GetLayerMask(EUnityLayerName.UserInputRaycast) | UnityLayerManager.GetLayerMask(EUnityLayerName.Player) | UnityLayerManager.GetLayerMask(EUnityLayerName.Vehicle) | UnityLayerManager.GetLayerMask(EUnityLayerName.NoCollisionWithBullet) | UnityLayerManager.GetLayerMask(EUnityLayerName.NoCollisionWithEntity));*/ var startPoint = BoneMount.FindChildBoneFromCache(player.RootGo(), BoneName.CharacterHeadBoneName).position; var dir = startPoint - targetCenter; var ray = new Ray(targetCenter, dir.normalized); var inRangeOffset = -0.01f; var hits = Physics.RaycastAll(ray, dir.magnitude - inRangeOffset, UnityLayers.PickupObstacleLayerMask); foreach (var hit in hits) { Logger.DebugFormat("hit {0}", hit.collider.name); if (Ignore(hit, player, item)) { continue; } else { return(true); } } return(false); }
protected override void ExecuteUserCmd(PlayerEntity playerEntity, IUserCmd cmd) { if (!cmd.IsSprayPaint) { isSprayPainting = false; return; } if (isSprayPainting) { return; } isSprayPainting = true; var root = _contexts.player.flagSelfEntity.RootGo(); Transform cameraTran = _contexts.player.cameraObj.MainCamera.transform; Transform headTran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); /*头部*/ if (headTran == null || cameraTran == null) { _logger.DebugFormat("error headTran or cameraTran !"); return; } Vector3 forward = cameraTran.forward; Vector3 head = root.transform.eulerAngles; var paintIdList = _contexts.ui.uI.PaintIdList; var selectedPaintIndex = _contexts.ui.uI.SelectedPaintIndex; if (0 == selectedPaintIndex) { selectedPaintIndex = PaintUiAdapter.SelectValidIndex(paintIdList); _contexts.ui.uI.SelectedPaintIndex = selectedPaintIndex; } if (paintIdList == null || paintIdList.Count <= selectedPaintIndex || paintIdList[selectedPaintIndex] == 0) { _logger.DebugFormat("error paintIdList or selectedPaintIndex : " + selectedPaintIndex); //TODO 未装备喷漆提示 return; } try { PlaySprayAudio(); } catch (Exception e) { _logger.DebugFormat(e.Message); } RaycastHit raycastHit; Ray ray = new Ray(headTran.position, cameraTran.forward); if (Physics.Raycast(ray, out raycastHit, 3.0f)) { if (!IsIgnore(raycastHit.collider.gameObject)) { _logger.DebugFormat("SendSprayMessage"); SendMarkMessage(raycastHit.point, raycastHit.normal, head, paintIdList[selectedPaintIndex]); } } }
private void CheckExplosionEffect(ClientEffectEntity entity) { PlayerEntity player = AllContexts.player.flagSelfEntity; Vector3 playerPos = player.position.Value; Vector3 pos = entity.position.Value; Transform tran; if (player.appearanceInterface.Appearance.IsFirstPerson) { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } else { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } if (null != tran) { playerPos = tran.position; } //距离 float dis = Vector3.Distance(playerPos, pos); if (dis < 9) { player.AudioController().PlayDizzyAudio(dis, 9); } }
public static Vector3 GetHandWeaponPosition(this PlayerEntity playerEntity) { Vector3 ret = playerEntity.position.Value; Transform tran; if (playerEntity.appearanceInterface.Appearance.IsFirstPerson) { if (null == playerEntity.playerInfo.FirstPersonRightHand) { var root = playerEntity.RootGo(); playerEntity.playerInfo.FirstPersonRightHand = BoneMount.FindChildBoneFromCache(root, BoneName.CharRightHand); } tran = playerEntity.playerInfo.FirstPersonRightHand; } else { if (null == playerEntity.playerInfo.ThirdPersonRightHand) { var root = playerEntity.RootGo(); playerEntity.playerInfo.ThirdPersonRightHand = BoneMount.FindChildBoneFromCache(root, BoneName.CharRightHand); } tran = playerEntity.playerInfo.ThirdPersonRightHand; } if (null != tran) { ret = tran.position; } return(ret); }
public static Vector3 GetPlayerTopPosition(PlayerEntity playerEntity) { Vector3 ret = playerEntity.position.Value; Transform tran; if (!playerEntity.hasAppearanceInterface) { return(Vector3.zero); } if (playerEntity.appearanceInterface.Appearance.IsFirstPerson) { if (null == playerEntity.playerInfo.FirstPersonHead) { var root = playerEntity.RootGo(); playerEntity.playerInfo.FirstPersonHead = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } tran = playerEntity.playerInfo.FirstPersonHead; } else { if (null == playerEntity.playerInfo.ThirdPersonHead) { var root = playerEntity.RootGo(); playerEntity.playerInfo.ThirdPersonHead = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } tran = playerEntity.playerInfo.ThirdPersonHead; } if (null != tran) { ret = tran.position; ret.y += 0.3f; } return(ret); }
// 仅限于瞄镜的变化 public void RefreshRemovableAttachment(GameObject go, bool hasSights) { var ironSights = BoneMount.FindChildBoneFromCache(go, BoneName.RemovableIronSights); var rail = BoneMount.FindChildBoneFromCache(go, BoneName.RemovableRail); if (ironSights != null) { if (hasSights) { AppearanceUtils.DisableRender(ironSights.gameObject); } else { AppearanceUtils.EnableRender(ironSights.gameObject); } } if (rail != null) { if (hasSights) { AppearanceUtils.EnableRender(rail.gameObject); } else { AppearanceUtils.DisableRender(rail.gameObject); } } }
protected override string OnProcess(Contexts contexts, PlayerEntity player, string[] args) { var weaponP1 = player.appearanceInterface.Appearance.GetWeaponP1InHand(); if (null != weaponP1) { var upper = BoneMount.FindChildBoneFromCache(weaponP1, BoneName.ScopeLocator); var renderers = upper.GetComponentsInChildren <Renderer>(); var sb = new StringBuilder(); foreach (var renderer in renderers) { var mat = renderer.material; sb.AppendLine("name : " + renderer.name); sb.AppendLine("mat : " + mat.name); sb.AppendLine("renderQueue : " + mat.renderQueue); if (mat.HasProperty("_Mode")) { sb.AppendLine("mode : " + mat.GetFloat("_Mode")); } } Logger.Error(sb.ToString()); return(sb.ToString()); } else { return("no weapon p1"); } }
private void OpenDepthOfField(PlayerEntity player) { Logger.InfoFormat("openDepthOfField"); if (SharedConfig.IsServer) { return; } Transform scope = BoneMount.FindChildBoneFromCache(player.firstPersonModel.Value, BoneName.ScopeLocator); var dofParams = player.WeaponController().HeldWeaponAgent.GetDOFParams(); bool needDefaultSet = false; if (scope != null && scope.childCount != 0) { var script = scope.GetComponentInChildren <AbstractEffectMonoBehaviour>(); if (script != null) { SetDof(dofParams, script); } else if (dofParams[0] == "1") { needDefaultSet = true; } } else { needDefaultSet = true; } if (needDefaultSet) { var script = player.effects.GetEffect("DepthOfFieldPostEffectMask"); if (script != null) { var mono = script as AbstractEffectMonoBehaviour; if (mono != null) { mono.enabled = true; } try { SetDof(dofParams, mono); script.SetParam("Enable", true); } catch (Exception e) { Logger.ErrorFormat("error when Enable:"); } } } }
private void GetP3Bones(GameObject obj) { if (null == obj) { return; } _neckP3 = BoneMount.FindChildBone(obj, BoneName.CharacterNeckBoneName); _headP3 = BoneMount.FindChildBone(obj, BoneName.CharacterHeadBoneName); _rightClavicleP3 = BoneMount.FindChildBone(obj, BoneName.CharacterRightClavicleName); _spine = BoneMount.FindChildBoneFromCache(obj, BoneName.CharacterSpineName); _spine1 = BoneMount.FindChildBoneFromCache(obj, BoneName.CharacterSpine1Name); }
private void GrenadeDamageHandler(ThrowingEntity throwing) { PlayerEntity sourcePlayer = null; if (throwing.hasOwnerId) { sourcePlayer = _contexts.player.GetEntityWithEntityKey(throwing.ownerId.Value); } Vector3 hitPoint; foreach (PlayerEntity player in _players) { float dis = Vector3.Distance(throwing.position.Value, player.position.Value); //头部 Vector3 headPos = player.position.Value; Transform tran; if (player.appearanceInterface.Appearance.IsFirstPerson) { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } else { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } if (null != tran) { headPos = tran.position; } if (dis < throwing.throwingData.Config.DamageRadius && ((!throwing.throwingData.IsFly && throwing.ownerId.Value == player.entityKey.Value) || !CommonMathUtil.Raycast(throwing.position.Value, player.position.Value, dis, _layerMask, out hitPoint) || !CommonMathUtil.Raycast(throwing.position.Value, headPos, dis, _layerMask, out hitPoint))) { float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage; _throwingHitHandler.OnPlayerDamage(sourcePlayer, player, new PlayerDamageInfo(damage, (int)EUIDeadType.Weapon, (int)EBodyPart.Chest, GetWeaponIdBySubType((EWeaponSubType)throwing.throwingData.WeaponSubType))); } } foreach (VehicleEntity vehicle in _vehicles) { float dis = Vector3.Distance(throwing.position.Value, vehicle.position.Value); if (dis < throwing.throwingData.Config.DamageRadius && !CommonMathUtil.Raycast(throwing.position.Value, vehicle.position.Value, dis, _layerMask, out hitPoint)) { float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage; _throwingHitHandler.OnVehicleDamage(vehicle, damage); } } }
private void ResetRagDollRootBoneTransform() { if (null == _characterP3) { return; } var rootBone = BoneMount.FindChildBoneFromCache(_characterP3, BoneName.CharacterBipPelvisBoneName); if (null == rootBone) { return; } rootBone.localPosition = Vector3.zero; rootBone.localRotation = Quaternion.identity; }
protected override void ExecuteUserCmd(PlayerEntity playerEntity, IUserCmd cmd) { if (!cmd.IsSprayPaint) { isSprayPainting = false; return; } if (isSprayPainting) { return; } isSprayPainting = true; debugSize.x = 1.2f; debugSize.y = 4.0f; debugSize.z = 1.2f; var root = _contexts.player.flagSelfEntity.RootGo(); Transform cameraTran = _contexts.player.cameraObj.MainCamera.transform; Transform headTran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); /*头部*/ Vector3 forward = cameraTran.forward; Vector3 head = cameraTran.eulerAngles; Vector3 position = headTran.position + forward * debugSize.y * 0.6f + headTran.up * 0.2f; RaycastHit raycastHit; Ray ray = new Ray(cameraTran.position, cameraTran.forward); if (Physics.Raycast(ray, out raycastHit)) { var paintIdList = _contexts.ui.uI.PaintIdList; var selectedPaintIndex = _contexts.ui.uI.SelectedPaintIndex; if (paintIdList == null || paintIdList.Count <= selectedPaintIndex) { _logger.DebugFormat("error paintIdList or selectedPaintIndex : " + selectedPaintIndex); return; } _logger.DebugFormat("SendSprayMessage"); /*SendMarkMessage(position, forward, head, paintIdList[selectedPaintIndex]);*/ SendMarkMessage(raycastHit.point, raycastHit.normal, head, paintIdList[selectedPaintIndex]); } }
private void GrenadeDamageHandler(ThrowingEntity throwing) { PlayerEntity sourcePlayer = null; if (throwing.hasOwnerId) { sourcePlayer = _contexts.player.GetEntityWithEntityKey(throwing.ownerId.Value); } Vector3 hitPoint; foreach (PlayerEntity player in _players) { float dis = Vector3.Distance(throwing.position.Value, player.position.Value); //头部 Vector3 headPos = player.position.Value; Transform tran; if (player.appearanceInterface.Appearance.IsFirstPerson) { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } else { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } if (null != tran) { headPos = tran.position; } if (dis < throwing.throwingData.Config.DamageRadius && ((!throwing.throwingData.IsFly && throwing.ownerId.Value == player.entityKey.Value) || !CommonMathUtil.Raycast(throwing.position.Value, player.position.Value, dis, _layerMask, out hitPoint) || !CommonMathUtil.Raycast(throwing.position.Value, headPos, dis, _layerMask, out hitPoint))) { float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage; _throwingHitHandler.OnPlayerDamage(sourcePlayer, player, new PlayerDamageInfo(damage, (int)EUIDeadType.Weapon, (int)EBodyPart.None, GetWeaponIdBySubType((EWeaponSubType)throwing.throwingData.WeaponSubType))); } } foreach (VehicleEntity vehicle in _vehicles) { float dis = Vector3.Distance(throwing.position.Value, vehicle.position.Value); if (dis < throwing.throwingData.Config.DamageRadius && !CommonMathUtil.Raycast(throwing.position.Value, vehicle.position.Value, dis, _layerMask, out hitPoint)) { float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage; _throwingHitHandler.OnVehicleDamage(vehicle, damage); } } var colliders = Physics.OverlapSphere(throwing.position.Value, throwing.throwingData.Config.DamageRadius, UnityLayerManager.GetLayerMask(EUnityLayerName.UserInputRaycast) | UnityLayerManager.GetLayerMask(EUnityLayerName.Glass)); foreach (var collider in colliders) { CreateMapObjWhenBomb(collider, sourcePlayer); var distance = Vector3.Distance(collider.transform.position, throwing.position.Value); float trueDamage = distance > throwing.throwingData.Config.DamageRadius ? 0f : Mathf.Max(0f, throwing.throwingData.Config.BaseDamage * (1 - distance / throwing.throwingData.Config.DamageRadius)); if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.UserInputRaycast)) { var parent = collider.transform; while (null != parent) { var fractured = parent.GetComponent <FracturedObject>(); if (null != fractured) { if (!HasObstacle(collider.transform.position, throwing.position.Value, (obstacleTrans) => { var obstacleParent = obstacleTrans.parent; while (null != obstacleParent) { if (obstacleParent == fractured.transform) { return(true); } obstacleParent = obstacleParent.parent; } return(false); })) { fractured.Explode(Vector3.zero, trueDamage); } break; } parent = parent.parent; } } if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Glass)) { var parent = collider.transform; while (null != parent) { var fractured = parent.GetComponent <FracturedGlassyChunk>(); if (null != fractured) { fractured.MakeBroken(); } parent = parent.parent; } } } }
public void OnLoadSucc(PlayerEntity player, UnityObject unityObj) { if (null == unityObj || null == unityObj.AsGameObject) { Logger.ErrorFormat("CharacterLog-- playerEntity: {0} unityObj is Null", player.entityKey); } GameObject go = unityObj; if (player.hasThirdPersonModel) { _assetManager.Recycle(player.thirdPersonModel.UnityObjectValue); player.RemoveAsset(player.thirdPersonModel.UnityObjectValue); } player.ReplaceThirdPersonModel(go, unityObj); var provider = SingletonManager.Get <HitBoxTransformProviderCache>() .GetProvider(player.thirdPersonModel.Value); HitBoxComponentUtility.InitHitBoxComponent(player.entityKey.Value, player, provider); RemoveRagdollOnServerSide(go, provider.GetHitBoxColliders().Values.ToList()); HandleLoadedModel(player, go); InitCharacterControllerSetting(player); player.AddAsset(unityObj); go.name = go.name.Replace("(Clone)", ""); go.transform.SetParent(GetThirdModelParent(player.RootGo().transform)); go.transform.localPosition = new Vector3(0, 0, 0); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; Logger.InfoFormat("CharacterLog-- P3 loaded: {0}", player.entityKey); BoneTool.CacheTransform(go); player.ReplaceBones(null, null, null); player.bones.Head = BoneMount.FindChildBoneFromCache(go, BoneName.CharacterHeadBoneName); player.bones.Spine = BoneMount.FindChildBoneFromCache(go, BoneName.CharacterSpineName); player.ReplaceThirdPersonAnimator(go.GetComponent <Animator>()); if (player.hasFsmInputRelateInterface) { player.fsmInputRelateInterface.Relate.InitLimit(); player.fsmInputRelateInterface.Relate.CreateAllLimitFsmInput(player.thirdPersonAnimator.UnityAnimator); } var ik = go.AddComponent <PlayerIK>(); ik.SetAnimator(AvatarIKGoal.LeftHand, player.thirdPersonAnimator.UnityAnimator); ik.SetIKLayer(AvatarIKGoal.LeftHand, NetworkAnimatorLayer.ThirdPersonIKPassLayer); ik.SetAnimator(AvatarIKGoal.RightHand, player.thirdPersonAnimator.UnityAnimator); ik.SetIKLayer(AvatarIKGoal.RightHand, NetworkAnimatorLayer.ThirdPersonIKPassLayer); if (player.isFlagSelf) { var animationEvent = go.AddComponent <AnimationClipEvent>(); animationEvent.Player = player; player.animatorClip.ClipManager.SetAnimationCleanEventCallback(animationEvent .InterruptAnimationEventFunc); } else { go.AddComponent <ThirdPersonAnimationClipEvent>(); } // 设置大厅传入的roleId和avatarId player.appearanceInterface.Appearance.SetRoleModelIdAndInitAvatar(player.playerInfo.RoleModelId, player.playerInfo.AvatarIds); player.characterControllerInterface.CharacterController.SetCharacterRoot(player.characterContoller.Value .gameObject); player.appearanceInterface.Appearance.SetRootGo(player.RootGo()); player.appearanceInterface.Appearance.SetThirdPersonCharacter(go); player.appearanceInterface.Appearance.SetRagDollComponent(player.ragDoll); player.characterControllerInterface.CharacterController.SetThirdModel(player.thirdPersonModel.Value); player.characterBoneInterface.CharacterBone.SetCharacterRoot(player.characterContoller.Value .gameObject); player.characterBoneInterface.CharacterBone.SetThirdPersonCharacter(go); ForceCrouch(player.thirdPersonAnimator.UnityAnimator); player.characterBoneInterface.CharacterBone.SetStableCrouchPelvisRotation(); ForceStand(player.thirdPersonAnimator.UnityAnimator); player.characterBoneInterface.CharacterBone.SetStableStandPelvisRotation(); player.appearanceInterface.Appearance.SetAnimatorP3(player.thirdPersonAnimator.UnityAnimator); player.appearanceInterface.Appearance.PlayerReborn(); player.characterControllerInterface.CharacterController.PlayerReborn(); if (player.hasStateInterface) { player.stateInterface.State.PlayerReborn(); } if (player.hasPlayerInfo) { player.playerInfo.InitTransform(); } player.ReplaceNetworkAnimator( NetworkAnimatorUtil.CreateAnimatorLayers(player.thirdPersonAnimator.UnityAnimator), NetworkAnimatorUtil.GetAnimatorParams(player.thirdPersonAnimator.UnityAnimator)); player.networkAnimator.SetEntityName(player.entityKey.ToString()); player.ReplaceOverrideNetworkAnimator(); if (SharedConfig.IsServer) { player.ReplaceNetworkAnimatiorServerTime(0); } // 禁用非可见状态下的动画更新,在获取Stable状态之后 if (SharedConfig.IsServer || !player.isFlagSelf) { player.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.CullUpdateTransforms; } else { player.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate; } //人物变身、换肤时,清空特效数据 if (player.hasEffects) { player.effects.ResetEffects(); } // 处理显隐 if (player.hasGamePlay) { PlayerEntityUtility.SetVisibility(go, player.gamePlay.Visibility); } }
public void SetThirdPersonCharacter(GameObject obj) { _characterP3 = obj; _rightClavicleP3 = BoneMount.FindChildBoneFromCache(obj, BoneName.CharacterRightClavicleName); _rightHandP3 = BoneMount.FindChildBoneFromCache(obj, BoneName.CharacterRightHandName); }
public void Init(IEntity entity, AssetStatus status) { var go = status.Object.AsGameObject; var player = entity as PlayerEntity; RemoveRagdollOnServerSide(go); player.AddThirdPersonModel(go); go.name = go.name.Replace("(Clone)", ""); go.transform.SetParent(player.RootGo().transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; _logger.InfoFormat("P3 loaded: {0}", player.entityKey); BoneTool.CacheTransform(go); if (!player.hasBones) { player.AddBones(null, null, null); } player.bones.Head = BoneMount.FindChildBoneFromCache(go, BoneName.CharacterHeadBoneName); player.bones.Spine = BoneMount.FindChildBoneFromCache(go, BoneName.CharacterSpineName); player.AddThirdPersonAnimator(go.GetComponent <Animator>()); var ik = go.AddComponent <PlayerIK>(); ik.SetAnimator(AvatarIKGoal.LeftHand, player.thirdPersonAnimator.UnityAnimator); ik.SetIKLayer(AvatarIKGoal.LeftHand, NetworkAnimatorLayer.ThirdPersonIKPassLayer); ik.SetAnimator(AvatarIKGoal.RightHand, player.thirdPersonAnimator.UnityAnimator); ik.SetIKLayer(AvatarIKGoal.RightHand, NetworkAnimatorLayer.ThirdPersonIKPassLayer); if (player.isFlagSelf) { var animationEvent = go.AddComponent <AnimationClipEvent>(); animationEvent.Player = player; player.animatorClip.ClipManager.SetAnimationCleanEventCallback(animationEvent.InterruptAnimationEventFunc); // 设置大厅传入的roleId和avatarId player.appearanceInterface.Appearance.SetRoleModelIdAndInitAvatar(player.playerInfo.RoleModelId, player.playerInfo.AvatarIds); } else { go.AddComponent <ThirdPersonAnimationClipEvent>(); } player.characterControllerInterface.CharacterController.SetCharacterRoot(player.characterContoller.Value.gameObject); player.appearanceInterface.Appearance.SetThirdPersonCharacter(go); player.thirdPersonAnimator.UnityAnimator.Update(0); player.characterBoneInterface.CharacterBone.SetCharacterRoot(player.characterContoller.Value.gameObject); player.characterBoneInterface.CharacterBone.SetThirdPersonCharacter(go); player.characterBoneInterface.CharacterBone.SetStablePelvisRotation(); player.appearanceInterface.Appearance.SetAnimatorP3(player.thirdPersonAnimator.UnityAnimator); player.appearanceInterface.Appearance.PlayerReborn(); player.characterControllerInterface.CharacterController.PlayerReborn(); // 实际应该使用SharedConfig.IsServer,但离线模式中其值为false if (!player.hasNetworkAnimator) { player.AddNetworkAnimator(NetworkAnimatorUtil.CreateAnimatorLayers(player.thirdPersonAnimator.UnityAnimator), NetworkAnimatorUtil.GetAnimatorParams(player.thirdPersonAnimator.UnityAnimator)); player.networkAnimator.SetEntityName(player.entityKey.ToString()); } if (SharedConfig.IsServer) { player.AddNetworkAnimatiorServerTime(0); } // 禁用非可见状态下的动画更新,在获取Stable状态之后 if (SharedConfig.IsServer || !player.isFlagSelf) { player.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.CullUpdateTransforms; } else { player.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate; } }
private void CheckFlash(ClientEffectEntity entity) { PlayerEntity player = AllContexts.player.flagSelfEntity; //闪光弹位置 Vector3 pos = entity.position.Value; //水里1米 if (SingletonManager.Get <MapConfigManager>().InWater(pos)) { float wy = SingletonManager.Get <MapConfigManager>().WaterSurfaceHeight(pos); if (!float.IsNaN(wy) && wy - pos.y > 1) { return; } } bool isShow = false; float alpha = 0, keepTime = 0, decayTime = 0; Vector3 playerPos = player.position.Value; //位置稍上抬 pos.y += 0.1f; //玩家头部位置 Transform tran; if (player.appearanceInterface.Appearance.IsFirstPerson) { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } else { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } if (null != tran) { playerPos = tran.position; } //距离 float dis = Vector3.Distance(playerPos, pos); if (dis >= 40) { return; } float diffAngle = 0; //判断是否手上爆炸 bool isHandBomb = entity.hasEffectRotation && entity.effectRotation.Yaw > 0; if (!(entity.ownerId.Value == player.entityKey.Value && isHandBomb)) { //遮挡 Vector3 hitPoint; bool isHit = CommonMathUtil.Raycast(playerPos, pos, dis, _layerMask, out hitPoint); if (isHit) { return; } //角度 float yaw = CommonMathUtil.TransComAngle(player.orientation.Yaw); float angle = CommonMathUtil.GetAngle(new Vector2(pos.x, pos.z), new Vector2(playerPos.x, playerPos.z)); diffAngle = Mathf.Abs(angle - yaw); diffAngle = Mathf.Min(360 - diffAngle, diffAngle); } if (diffAngle <= 60) { if (dis < 20) { isShow = true; alpha = 1; keepTime = Mathf.Max(1.2f, 3 * Mathf.Pow(0.4f, dis / 30)); decayTime = alpha / 0.4f; } else if (dis < 40) { isShow = true; alpha = 1 - dis * 0.00025f; keepTime = 0; decayTime = alpha / 0.4f; } } else if (diffAngle <= 90) { if (dis <= 20) { isShow = true; alpha = Mathf.Max(0, 1 - dis * 0.00025f); keepTime = 0; decayTime = alpha / 0.4f; } } else if (diffAngle <= 180) { if (dis <= 10) { isShow = true; alpha = Mathf.Max(0, 0.8f - dis * 0.00025f); keepTime = 0; decayTime = alpha / 0.5f; } } if (isShow) { ScreenFlashInfo screenFlashInfo = new ScreenFlashInfo(); screenFlashInfo.IsShow = true; screenFlashInfo.Alpha = alpha; screenFlashInfo.KeepTime = keepTime; screenFlashInfo.DecayTime = decayTime; AllContexts.ui.uI.ScreenFlashInfo = screenFlashInfo; player.AudioController().PlayDizzyAudio(dis, 40); // GameAudioMedia.PlayFlashDizzyAudio(pos,Math.Min(0,40-dis)); } }
public void OnLoadSucc(PlayerEntity player, UnityObject unityObj) { GameObject go = unityObj; player.AddThirdPersonModel(go); var provider = SingletonManager.Get <HitBoxTransformProviderCache>() .GetProvider(player.thirdPersonModel.Value); HitBoxComponentUtility.InitHitBoxComponent(player.entityKey.Value, player, provider); RemoveRagdollOnServerSide(go, provider.GetHitBoxColliders().Values.ToList()); HandleLoadedModel(player, go); player.AddAsset(unityObj); go.name = go.name.Replace("(Clone)", ""); go.transform.SetParent(player.RootGo().transform); go.transform.localPosition = new Vector3(0, -PlayerEntityUtility.CcSkinWidth, 0); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; _logger.InfoFormat("P3 loaded: {0}", player.entityKey); BoneTool.CacheTransform(go); if (!player.hasBones) { player.AddBones(null, null, null); } player.bones.Head = BoneMount.FindChildBoneFromCache(go, BoneName.CharacterHeadBoneName); player.bones.Spine = BoneMount.FindChildBoneFromCache(go, BoneName.CharacterSpineName); player.AddThirdPersonAnimator(go.GetComponent <Animator>()); var ik = go.AddComponent <PlayerIK>(); ik.SetAnimator(AvatarIKGoal.LeftHand, player.thirdPersonAnimator.UnityAnimator); ik.SetIKLayer(AvatarIKGoal.LeftHand, NetworkAnimatorLayer.ThirdPersonIKPassLayer); ik.SetAnimator(AvatarIKGoal.RightHand, player.thirdPersonAnimator.UnityAnimator); ik.SetIKLayer(AvatarIKGoal.RightHand, NetworkAnimatorLayer.ThirdPersonIKPassLayer); if (player.isFlagSelf) { var animationEvent = go.AddComponent <AnimationClipEvent>(); animationEvent.Player = player; player.animatorClip.ClipManager.SetAnimationCleanEventCallback(animationEvent.InterruptAnimationEventFunc); } else { go.AddComponent <ThirdPersonAnimationClipEvent>(); } // 设置大厅传入的roleId和avatarId player.appearanceInterface.Appearance.SetRoleModelIdAndInitAvatar(player.playerInfo.RoleModelId, player.playerInfo.AvatarIds); player.characterControllerInterface.CharacterController.SetCharacterRoot(player.characterContoller.Value.gameObject); player.appearanceInterface.Appearance.SetThirdPersonCharacter(go); player.thirdPersonAnimator.UnityAnimator.Update(0); player.characterControllerInterface.CharacterController.SetThirdModel(player.thirdPersonModel.Value); player.characterBoneInterface.CharacterBone.SetCharacterRoot(player.characterContoller.Value.gameObject); player.characterBoneInterface.CharacterBone.SetThirdPersonCharacter(go); player.characterBoneInterface.CharacterBone.SetStablePelvisRotation(); player.appearanceInterface.Appearance.SetAnimatorP3(player.thirdPersonAnimator.UnityAnimator); player.appearanceInterface.Appearance.PlayerReborn(); player.characterControllerInterface.CharacterController.PlayerReborn(); // 实际应该使用SharedConfig.IsServer,但离线模式中其值为false if (!player.hasNetworkAnimator) { player.AddNetworkAnimator(NetworkAnimatorUtil.CreateAnimatorLayers(player.thirdPersonAnimator.UnityAnimator), NetworkAnimatorUtil.GetAnimatorParams(player.thirdPersonAnimator.UnityAnimator)); player.networkAnimator.SetEntityName(player.entityKey.ToString()); } if (!player.hasOverrideNetworkAnimator) { player.AddOverrideNetworkAnimator(); } if (SharedConfig.IsServer) { player.AddNetworkAnimatiorServerTime(0); } // 禁用非可见状态下的动画更新,在获取Stable状态之后 if (SharedConfig.IsServer || !player.isFlagSelf) { player.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.CullUpdateTransforms; } else { player.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate; } // _assetManager.LoadAssetAsync(player, AssetConfig.GetCharacterHitboxAssetInfo(player.playerInfo.ModelName), new HitboxLoadResponseHandler().OnLoadSucc); }