using System; using System.Collections; using System.Collections.Generic; using GameFramework.Event; using UnityEngine; using HumanoidEditor; using GameFramework.DataTable; 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("标准女").GetComponent(); bodyData = new RoleCustomData(); //初始化 IDataTable drCB = GameEntry.DataTable.GetDataTable(); DRCustomBody[] dtCB = drCB.GetAllDataRows(); for (int i = 0; i < dtCB.Length; i++) { bodyData.bodyList.Add(dtCB[i].Id, new PartData(dtCB[i].Id,(EditableBodyPart)dtCB[i].Part, (ModifyType)dtCB[i].ModifyType)); } //初始缩放 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) { //更新数据 IDataTable drCB = GameEntry.DataTable.GetDataTable(); var formData = drCB.GetDataRow(crf.Part); if(formData == null) { Debug.LogError(crf.Part + ": 表里不存在此行数据"); return; } bodyData.bodyList[crf.Part].floatValue = 1 + (crf.ChangeValue.x - 0.5f) * valueFloating; //通过更新的数据更新骨骼缩放 if (testPlayer != null) { switch ((ModifyType)formData.ModifyType) { case ModifyType.Length: testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(0, 0, 1), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue); break; case ModifyType.Width: testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(0, 1, 0), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue); break; case ModifyType.Thick: testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(1, 0, 0), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue); break; case ModifyType.LengthWidthThick: testPlayer.UpdateBoneScale((EditableBodyPart)formData.Part, new Vector3(1, 1, 1), formData.IsKeepChildrenScale, bodyData.bodyList[crf.Part].floatValue); break; case ModifyType.Angle: break; case ModifyType.UpDown: break; case ModifyType.LeftRight: break; case ModifyType.ForwardBehind: break; default: break; } } } } public float GetBodyBoneValue(int id) { return 0.5f + (bodyData.bodyList[id].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); } } } }