//------------------------------------------------------------ // Game Framework // Copyright © 2013-2021 Jiang Yin. All rights reserved. // Homepage: https://gameframework.cn/ // Feedback: mailto:ellan@gameframework.cn //------------------------------------------------------------ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityGameFramework.Runtime; namespace MetaClient { public class CustomRoleForm : UGuiForm { public Text curShow; public Slider curSlider; public Button[] btnList; public GameObject point; private EditableBodyPart curSelect = EditableBodyPart.None; private List bonesTrans = new List(); private List pointList = new List(); #if UNITY_2017_3_OR_NEWER protected override void OnOpen(object userData) #else protected internal override void OnOpen(object userData) #endif { base.OnOpen(userData); RefreshBtn(); bonesTrans = CustomManager.Instance.testPlayer.GetBonesTrans(); for (int i = 0; i < bonesTrans.Count; i++) { var newpoint = GameObject.Instantiate(point,transform); pointList.Add(newpoint); } } private void Start() { RefreshBtn(); } private void RefreshBtn() { for (int i = 0; i < btnList.Length; i++) { var btn = btnList[i]; btn.GetComponentInChildren().text = ((EditableBodyPart)i).ToString(); } } #if UNITY_2017_3_OR_NEWER protected override void OnClose(bool isShutdown, object userData) #else protected internal override void OnClose(bool isShutdown, object userData) #endif { base.OnClose(isShutdown, userData); } public void ClickFaceChangeBtn(int part) { curSelect = (EditableBodyPart)part; RefreshSliderValue(); } public void Update() { UpdateCustomBodyBoneTransShow(); } private void RefreshSliderValue() { curShow.text = curSelect.ToString(); curSlider.value = CustomManager.Instance.GetBodyBoneValue(curSelect); } public void OnSliderValueChange(float value) { if(curSelect == EditableBodyPart.None) { return; } GameEntry.Event.Fire(this, CustomRoleBodyEventArgs.Create(curSelect, new Vector3(value, 0, 0))); } private void UpdateCustomBodyBoneTransShow() { for (int i = 0; i < bonesTrans.Count; i++) { var point = pointList[i]; var pos = Camera.main.WorldToScreenPoint(bonesTrans[i].position); point.transform.position = pos; } } } }