Example #1
0
            public void OnLoadSucc(PlayerEntity player, UnityObject unityObj)
            {
                GameObject go = unityObj;

                HandleLoadedModel(player, go);

                player.AddAsset(unityObj);

                player.AddFirstPersonModel(go);

                player.appearanceInterface.FirstPersonAppearance = new FirstPersonAppearanceManager(player.firstPersonAppearance);

                go.name = "P1_" + player.entityKey;
                go.transform.SetParent(player.RootGo().transform);
                go.transform.localPosition = new Vector3(0, player.firstPersonAppearance.FirstPersonHeight, player.firstPersonAppearance.FirstPersonForwardOffset);
                go.transform.localRotation = Quaternion.identity;
                go.transform.localScale    = Vector3.one;
                _logger.InfoFormat("P1 loaded: {0}", player.entityKey);

                player.AddFirstPersonAnimator(go.GetComponent <Animator>());

                var ik = go.AddComponent <PlayerIK>();

                ik.SetAnimator(AvatarIKGoal.LeftHand, player.firstPersonAnimator.UnityAnimator);
                ik.SetIKLayer(AvatarIKGoal.LeftHand, NetworkAnimatorLayer.FirstPersonIKPassLayer);
                ik.SetAnimator(AvatarIKGoal.RightHand, player.firstPersonAnimator.UnityAnimator);
                ik.SetIKLayer(AvatarIKGoal.RightHand, NetworkAnimatorLayer.FirstPersonIKPassLayer);

                BoneTool.CacheTransform(go);

                if (player.isFlagSelf)
                {
                    var animationEvent = go.AddComponent <AnimationClipEvent>();
                    animationEvent.Player = player;
                    player.animatorClip.ClipManager.SetAnimationCleanEventCallback(animationEvent.InterruptAnimationEventFunc);
                }
                else
                {
                    go.AddComponent <ThirdPersonAnimationClipEvent>();
                }

                player.firstPersonAnimator.UnityAnimator.Update(0);

                player.appearanceInterface.Appearance.SetFirstPersonCharacter(go);
                player.appearanceInterface.FirstPersonAppearance.SetFirstPersonCharacter(go);

                player.appearanceInterface.Appearance.SetAnimatorP1(player.firstPersonAnimator.UnityAnimator);

                player.stateInterface.State.SetName(player.RootGo().name);

                player.characterBoneInterface.CharacterBone.SetFirstPersonCharacter(go);

                if (!player.hasFpAnimStatus)
                {
                    player.AddFpAnimStatus(NetworkAnimatorUtil.CreateAnimatorLayers(player.firstPersonAnimator.UnityAnimator),
                                           NetworkAnimatorUtil.GetAnimatorParams(player.firstPersonAnimator.UnityAnimator));
                }

                // 禁用非可见状态下的动画更新
                if (!player.isFlagSelf)
                {
                    player.firstPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.CullUpdateTransforms;
                }
                else
                {
                    player.firstPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
                }
            }