using System; using System.Collections; using System.Collections.Generic; using GameFramework.Event; using UnityEngine; using HumanoidEditor; namespace MetaClient { public class CustomManager : MonoBehaviour { public static CustomManager Instance; public RoleCustomData bodyData; public const float valueFloating = 1f; public CustomRoleController testPlayer = null; private void Awake() { Instance = this; } public void Init() { GameEntry.Event.Subscribe(CustomRoleBodyEventArgs.EventId, UpdateBody); testPlayer = GameObject.Find("biaozhunnv").GetComponent(); bodyData = new RoleCustomData(); for (int i = 0; i < 6; i++) { bodyData.bodyList.Add(i, new PartData((EditableBodyPart)i, ModifyType.LengthWidthThick)); } //初始缩放 testPlayer.GetNormalAniBonesScale(ref bodyData.orginLocalScaleList); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.Chest); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperArmUp); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperArmDown); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperLegUp); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.UpperLegDown); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.LowerLegUp); testPlayer.GetExtraAniBonesScale(ref bodyData.orginLocalScaleList, EditableBodyPart.LowerLegDown); //初始位置 testPlayer.GetExtraAniBonesPosition(ref bodyData.orginLocalPositionList, EditableBodyPart.Chest); //初始旋转 testPlayer.GetExtraAniBonesRotate(ref bodyData.orginLocalRotationList, EditableBodyPart.Chest); } public void Clear() { GameEntry.Event.Unsubscribe(CustomRoleBodyEventArgs.EventId, UpdateBody); } private void UpdateBody(object sender, GameEventArgs e) { CustomRoleBodyEventArgs crf = (CustomRoleBodyEventArgs)e; if (crf != null) { bodyData.bodyList[(int)crf.Part].floatValue = 1 + (crf.ChangeValue.x - 0.5f) * valueFloating; if (testPlayer != null) { testPlayer.UpdateBoneScale(crf.Part, bodyData.bodyList[(int)crf.Part].floatValue); } } } public float GetBodyBoneValue(EditableBodyPart part) { return 0.5f + (bodyData.bodyList[(int)part].floatValue - 1) / valueFloating; } /// /// 重置角色数据 /// public void ResetRole() { if(testPlayer == null) { Debug.LogError("没有模型存在"); return; } Debug.Log("重置模型"); foreach (var item in bodyData.bodyList) { var key = item.Key; var value = item.Value; value.floatValue = 1; } //重置缩放 foreach (var item in bodyData.orginLocalScaleList) { var key = item.Key; var value = item.Value; testPlayer.SetBoneScale(key, value); } //重置旋转 foreach (var item in bodyData.orginLocalRotationList) { var key = item.Key; var value = item.Value; testPlayer.SetBoneRot(key, value); } //重置位置 foreach (var item in bodyData.orginLocalPositionList) { var key = item.Key; var value = item.Value; testPlayer.SetBonePos(key, value); } } } }