333 lines
9.7 KiB
C#
333 lines
9.7 KiB
C#
using cfg.CharacterCfg;
|
|
using Framework;
|
|
using System.Collections.Generic;
|
|
using Gameplay;
|
|
using PhxhSDK;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Constants = Framework.Constants;
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
public class UIPosterController : UIWindow
|
|
{
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Image Image_BG;
|
|
public Button Button_Back;
|
|
public TMP_Text Text_Back;
|
|
public Button Button_Home;
|
|
public Image Image_Poster;
|
|
public Button Button_Poster;
|
|
public TMP_Text Text_Poster;
|
|
public Image Image_LightBar;
|
|
public Button Button_Poster_Default;
|
|
public TMP_Text Text_Poster_Default;
|
|
public Button Button_Model;
|
|
public TMP_Text Text_Model;
|
|
public Image Image_LightBar01;
|
|
public Button Button_Model_Default;
|
|
public TMP_Text Text_Model_Default;
|
|
|
|
private CharacterDataInfo _characterData;
|
|
private EshowType mCurShowType = EshowType.Pic;
|
|
|
|
private Sprite ui2Dpic;
|
|
private CharacterAttri characterAttri;
|
|
private GameObject showModel;
|
|
private GameObject viewModel = null;
|
|
private Vector3 PosterScale = Vector3.one;
|
|
private float scaleXiShu = 1;
|
|
private GameObject modelParent;
|
|
List<GameObject> childGo ;
|
|
|
|
|
|
private enum EshowType
|
|
{
|
|
Pic,
|
|
Model,
|
|
}
|
|
|
|
|
|
///Auto Gen End///
|
|
|
|
// Use this for initialization
|
|
public override void OnAwake()
|
|
{
|
|
//bind UI GameObj
|
|
UIPosterBinder.GetComponents(this);
|
|
BindButton(Button_Back, OnButton_BackClick);
|
|
BindButton(Button_Poster, OnButton_Poster);
|
|
BindButton(Button_Model, OnButton_Model);
|
|
BindButton(Button_Poster_Default, OnButton_Poster);
|
|
BindButton(Button_Model_Default, OnButton_Model);
|
|
BindButton(Button_Home, OnClickHome);
|
|
|
|
modelParent = FindObj("Model");
|
|
childGo= new List<GameObject>();
|
|
|
|
|
|
}
|
|
private void OnClickHome()
|
|
{
|
|
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
|
|
}
|
|
|
|
//float xoffset = 0;
|
|
//float yoffset = 0;
|
|
//Vector3 curPostion = Vector3.zero;
|
|
//private void OnFingerDrag(Vector2 delta)
|
|
//{
|
|
|
|
// if (mCurShowType == EshowType.Pic)
|
|
// {
|
|
|
|
|
|
// // Image_Poster.transform.localPosition = new Vector3(Image_Poster.transform.localPosition.x+delta.x, Image_Poster.transform.localPosition.y + delta.y, 0);
|
|
|
|
|
|
// if ((Image_Poster.transform.localPosition.x + delta.x) >= (Screen.width/2- (500*Image_Poster.transform.localScale.x)))
|
|
// {
|
|
// xoffset = Screen.width / 2 - (500 * Image_Poster.transform.localScale.x);
|
|
// }
|
|
// else if (((Image_Poster.transform.localPosition.x + delta.x) <=(-Screen.width/2+(500*Image_Poster.transform.localScale.x))))
|
|
// {
|
|
// xoffset = -Screen.width / 2 + (500* Image_Poster.transform.localScale.x);
|
|
// }
|
|
// else
|
|
// {
|
|
// xoffset = Image_Poster.transform.localPosition.x + delta.x;
|
|
// }
|
|
// if ((Image_Poster.transform.localPosition.y + delta.y) >= ((Screen.height/2)- Image_Poster.rectTransform.sizeDelta.y/2 * Image_Poster.transform.localScale.x))
|
|
// {
|
|
// yoffset = ((Screen.height / 2) - (Image_Poster.rectTransform.sizeDelta.y / 2 * Image_Poster.transform.localScale.x));
|
|
// }
|
|
// else if (((Image_Poster.transform.localPosition.y + delta.y) <= ((-Screen.height / 2)+ (Image_Poster.rectTransform.sizeDelta.y/2* Image_Poster.transform.localScale.x))))
|
|
// {
|
|
// yoffset = -Screen.height / 2+(Image_Poster.rectTransform.sizeDelta.y / 2 * Image_Poster.transform.localScale.x);
|
|
// }
|
|
// else
|
|
// {
|
|
// yoffset = Image_Poster.transform.localPosition.y + delta.y;
|
|
// }
|
|
// Image_Poster.transform.localPosition = new Vector3(xoffset, yoffset, 0);
|
|
|
|
// }
|
|
//}
|
|
|
|
private void OnFingersZoom(float delta)
|
|
{
|
|
if (mCurShowType != EshowType.Pic) return;
|
|
if (delta > 0)
|
|
{
|
|
if (scaleXiShu >= 0.5f)
|
|
{
|
|
scaleXiShu = 0.5f;
|
|
}else
|
|
{
|
|
scaleXiShu += 0.05f;
|
|
}
|
|
Image_Poster.transform.localScale = PosterScale * scaleXiShu;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (scaleXiShu <= 0.25f)
|
|
{
|
|
scaleXiShu = 0.25f;
|
|
}
|
|
else
|
|
{
|
|
scaleXiShu -= 0.05f;
|
|
}
|
|
Image_Poster.transform.localScale = PosterScale * scaleXiShu;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
private void OnButton_Model()
|
|
{
|
|
if(mCurShowType==EshowType.Model)
|
|
{
|
|
return;
|
|
}
|
|
RefreshModel();
|
|
}
|
|
|
|
private void RefreshModel()
|
|
{
|
|
modelParent.SetActive(true);
|
|
Image_Poster.gameObject.SetActive(false);
|
|
mCurShowType = EshowType.Model;
|
|
RefreshChangeBtn();
|
|
|
|
if (viewModel!=null)
|
|
{
|
|
return;
|
|
}
|
|
viewModel = GameObject.Instantiate(showModel);
|
|
viewModel.transform.SetParent(modelParent.transform);
|
|
viewModel.transform.localPosition =new Vector3(0,-309,-247);
|
|
viewModel.transform.localScale = new Vector3(540,540,540);
|
|
viewModel.transform.localRotation= new Quaternion(0,180,0,1);
|
|
viewModel.gameObject.layer = 5;
|
|
FindChild(viewModel.gameObject);
|
|
for (int i = 0; i < childGo.Count; i++)
|
|
{
|
|
childGo[i].layer = 5;
|
|
}
|
|
}
|
|
|
|
private void FindChild(GameObject child)
|
|
{
|
|
|
|
//利用for循环 获取物体下的全部子物体
|
|
for (int c = 0; c < child.transform.childCount; c++)
|
|
{
|
|
//如果子物体下还有子物体 就将子物体传入进行回调查找 直到物体没有子物体为止
|
|
if (child.transform.GetChild(c).childCount > 0)
|
|
{
|
|
FindChild(child.transform.GetChild(c).gameObject);
|
|
|
|
}
|
|
childGo.Add(child.transform.GetChild(c).gameObject);
|
|
|
|
|
|
}
|
|
}
|
|
private void OnButton_Poster()
|
|
{
|
|
if (mCurShowType == EshowType.Pic)
|
|
{
|
|
return;
|
|
|
|
}
|
|
|
|
Refresh2DPic();
|
|
}
|
|
private void RefreshChangeBtn()
|
|
{
|
|
Button_Poster.gameObject.SetActive(mCurShowType == EshowType.Pic);
|
|
Button_Model_Default.gameObject.SetActive(mCurShowType !=EshowType.Model);
|
|
Button_Poster_Default.gameObject.SetActive(mCurShowType != EshowType.Pic);
|
|
Button_Model.gameObject.SetActive(mCurShowType == EshowType.Model);
|
|
}
|
|
private void Refresh2DPic()
|
|
{
|
|
modelParent.SetActive(false);
|
|
Image_Poster.gameObject.SetActive(true);
|
|
Image_Poster.sprite = ui2Dpic;
|
|
Image_Poster.SetNativeSize();
|
|
Image_Poster.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
|
mCurShowType = EshowType.Pic;
|
|
RefreshChangeBtn();
|
|
}
|
|
|
|
private void LoadCfg()
|
|
{
|
|
OnLoadPostCfg();
|
|
OnPicLoaded();
|
|
OnModelLoaded();
|
|
}
|
|
|
|
|
|
private void ResetModel()
|
|
{
|
|
childGo.Clear();
|
|
viewModel.Destroy();
|
|
viewModel = null;
|
|
}
|
|
|
|
|
|
private void OnLoadPostCfg()
|
|
{
|
|
characterAttri=TableManager.Instance.Tables.CharacterAttri;
|
|
}
|
|
private void OnModelLoaded()
|
|
{
|
|
AssetManager.Instance.LoadAssetOnCallBack<GameObject>(TableManager.Instance.Tables.SkinCfg.Get(Constants.DEFULT_SKINID, _characterData.Cfg.RoleID).PrefabPath, onLoadModel);
|
|
|
|
}
|
|
|
|
private void onLoadModel(GameObject modelObj)
|
|
{
|
|
showModel =modelObj;
|
|
|
|
}
|
|
|
|
private void OnButton_BackClick()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
//invoke when open window
|
|
protected override void OnOpenWindow(object tempInfo)
|
|
{
|
|
|
|
InputManager.Instance.OnFingersMove += OnFingersZoom;
|
|
//InputManager.Instance.OnFingerMoveUI += OnFingerDrag;
|
|
InputManager.Instance.OnFingerMoveUI += RotateMonster;
|
|
mCurShowType = EshowType.Pic;
|
|
ResetModel();
|
|
_characterData = tempInfo as CharacterDataInfo;
|
|
Image_Poster.gameObject.SetActive(false);
|
|
LoadCfg();
|
|
CommonUtils.SetImageBlur(GetComponent<Image>("blurObj"));
|
|
|
|
}
|
|
|
|
private void RotateMonster(Vector2 delta)
|
|
{
|
|
if (delta == Vector2.zero) return;
|
|
if (viewModel != null)
|
|
{
|
|
viewModel.transform.Rotate(Vector3.up, delta.x);
|
|
}
|
|
}
|
|
|
|
|
|
private void RefreshUI()
|
|
{
|
|
if(mCurShowType==EshowType.Pic)
|
|
{
|
|
Refresh2DPic();
|
|
}else
|
|
{
|
|
RefreshModel();
|
|
}
|
|
}
|
|
|
|
private void OnPicLoaded()
|
|
{
|
|
AssetManager.Instance.LoadAssetOnCallBack<Sprite>(CommonUtils.GetCharacterPicPath(_characterData.Cfg.RoleID, CommonUtils.ECharacterPicPathType.Poster),onLoadPic);
|
|
}
|
|
|
|
private void onLoadPic(Sprite sprite)
|
|
{
|
|
ui2Dpic= sprite;
|
|
RefreshUI();
|
|
Image_Poster.gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
private void UnLoad()
|
|
{
|
|
AssetManager.Instance.Unload(CommonUtils.GetCharacterPicPath(_characterData.Cfg.RoleID, CommonUtils.ECharacterPicPathType.Poster));
|
|
AssetManager.Instance.Unload(TableManager.Instance.Tables.SkinCfg.Get(Constants.DEFULT_SKINID,_characterData.Cfg.RoleID).DisplayPrefabPath);
|
|
|
|
}
|
|
//invoke when close window
|
|
protected override void OnCloseWindow()
|
|
{
|
|
UnLoad();
|
|
InputManager.Instance.OnFingersMove -= OnFingersZoom;
|
|
// InputManager.Instance.OnFingerMoveUI -= OnFingerDrag;
|
|
InputManager.Instance.OnFingerMoveUI -= RotateMonster;
|
|
EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
|
|
}
|
|
} |