Files
JJBB/Assets/Project/Script/GUI/Other/FuncPreviewTipCtr.cs

301 lines
10 KiB
C#
Raw Permalink Normal View History

2024-08-23 15:49:34 +08:00
using System.Collections;
using Games.Item;
using GCGame.Table;
using Module.Log;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
public class FuncPreviewTipCtr : MonoBehaviour
{
private const string effectName = "effect";
public static FuncPreviewTipCtr Instance;
public GameObject activeBtn;
public Text activeDesc;
public Transform bundlePathIconParent;
public GameObject bundlePathPanel;
private float countTime;
public Image funcIcon;
public Text funcName;
public Image funcNameIcon;
private bool isActivePanel;
public UICameraTexture modelCamera;
private string needActionAnimationName = "";
public GameObject threeDPanel;
private float totalTimes = 5.0f;
public GameObject twoDPanel;
private Tab_FunctionPreview viewTab;
public UIContainerBase _MenuContainer;
private void Awake()
{
Instance = this;
InitMenuItem();
}
private void OnDestroy()
{
Instance = null;
}
void InitMenuItem()
{
List<int> _MenuItemIdList = new List<int>();
foreach(var tab in TableManager.GetFunctionPreview())
{
if (!_MenuItemIdList.Contains(tab.Key))
_MenuItemIdList.Add(tab.Key);
}
_MenuContainer.InitContentItem(_MenuItemIdList);
}
public void OnMenuItemClick(int tipsId)
{
InitTips(tipsId, false, false);
}
public void ShowMenuItemMarkIcon(int tipId, bool isAuotoPosition)
{
_MenuContainer.ForeachActiveItem<FuncPreviewMenuItem>((item)=> {
item.ShowMarkIcon(item._CurFuncPreviewId == tipId);
if(isAuotoPosition && item._CurFuncPreviewId == tipId)
{
PositionItem(_MenuContainer.GetItemLocalPosition(item));
}
});
}
void PositionItem(Vector3 pos)
{
var fixedPosY = Mathf.Clamp(Mathf.Abs(pos.y), 0, _MenuContainer._ContainerObj.sizeDelta.y);
_MenuContainer._ContainerObj.localPosition = new Vector3(0, Mathf.Abs(fixedPosY) - 58, 0);
}
public void InitTips(int viewId, bool isShowActiveBtn = false, bool isAutoPosition = true)
{
isActivePanel = isShowActiveBtn;
viewTab = TableManager.GetFunctionPreviewByID(viewId, 0);
if (viewTab == null) return;
ShowMenuItemMarkIcon(viewId, isAutoPosition);
if (!viewTab.PreviewModelId.Equals("-1"))
{
threeDPanel.SetActive(true);
twoDPanel.SetActive(false);
bundlePathPanel.SetActive(false);
needActionAnimationName = viewTab.AnimationName;
//是否需要解析
var neeShowCharModelId = -1;
var modelIdStr = viewTab.PreviewModelId;
var isStr = false;
for (var index = 0; index < modelIdStr.Length; index++)
if (modelIdStr[index].Equals('|'))
{
neeShowCharModelId =
int.Parse(modelIdStr.Split('|')[GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession]);
isStr = true;
break;
}
if (!isStr) neeShowCharModelId = int.Parse(viewTab.PreviewModelId);
if (neeShowCharModelId == -1)
{
LogModule.ErrorLog("neeShowCharModelId is -1");
return;
}
var charModel = TableManager.GetCharModelByID(neeShowCharModelId, 0);
if (charModel != null) modelCamera.InitModelPath(charModel.ResPath, charModel);
}
else if (!viewTab.PreViewIconPath.Equals("-1"))
{
threeDPanel.SetActive(false);
twoDPanel.SetActive(true);
bundlePathPanel.SetActive(false);
LoadAssetBundle.Instance.SetImageSprite(funcIcon, viewTab.PreViewIconPath);
funcIcon.rectTransform.sizeDelta = new Vector2(float.Parse(viewTab.PreviewRecSize.Split('|')[0]),
float.Parse(viewTab.PreviewRecSize.Split('|')[1]));
}
else
{
threeDPanel.SetActive(false);
twoDPanel.SetActive(false);
bundlePathPanel.SetActive(true);
var bundlePath = TableManager.GetBundlePathByID(viewTab.PreViewBundlePathId, 0);
if (bundlePath == null)
{
LogModule.ErrorLog("BundlePath is null");
return;
}
var pos = bundlePath.Pos.Split(';');
var landPos = new Vector3(float.Parse(pos[0]), float.Parse(pos[1]), float.Parse(pos[2]));
LoadAssetBundle.Instance.LoadGameObject(LoadAssetBundle.BUNDLE_PATH_EFFECT, bundlePath.Name,
delegate(string assetName, GameObject resObj, Hashtable hashParam)
{
if (resObj != null)
{
var ani = Instantiate(resObj);
ani.gameObject.name = effectName;
//寻找父节点下是否有effect
var oldObj = bundlePathIconParent.Find(effectName);
if (oldObj == null)
{
ani.transform.SetParent(bundlePathIconParent);
ani.transform.localPosition = landPos;
ani.transform.localScale = Vector3.one;
ani.transform.localRotation = Quaternion.Euler(Vector3.zero);
ani.GetComponent<RectTransform>().sizeDelta = new Vector2(
ani.GetComponent<RectTransform>().sizeDelta.x * bundlePath.Scale,
ani.GetComponent<RectTransform>().sizeDelta.y * bundlePath.Scale);
}
else
{
ani.transform.SetParent(bundlePathIconParent);
ani.transform.localPosition = landPos;
ani.transform.localScale = Vector3.one;
ani.transform.localRotation = oldObj.localRotation;
ani.GetComponent<RectTransform>().sizeDelta = new Vector2(
ani.GetComponent<RectTransform>().sizeDelta.x * bundlePath.Scale,
ani.GetComponent<RectTransform>().sizeDelta.y * bundlePath.Scale);
Destroy(oldObj.gameObject);
}
}
},
new Hashtable());
}
InitActiveBtnInfo();
InitNameAndNameIcon();
}
public void InitActiveBtnInfo()
{
funcNameIcon.gameObject.SetActive(!isActivePanel);
activeBtn.SetActive(isActivePanel);
activeDesc.text = StrDictionary.GetClientDictionaryString("#{47023}", totalTimes);
}
private void OnEnable()
{
totalTimes = 5.0f;
countTime = 0.0f;
}
private void Update()
{
if (isActivePanel)
{
if (totalTimes > 0)
{
countTime += Time.deltaTime;
if (countTime >= 1.0f)
{
activeDesc.text = StrDictionary.GetClientDictionaryString("#{47023}", --totalTimes);
countTime = 1.0f - countTime;
}
}
else
{
activeDesc.text = StrDictionary.GetClientDictionaryString("#{47023}", 0);
OnActiveBtnClick();
}
}
}
public void OnActiveBtnClick()
{
if (viewTab == null)
{
UIManager.CloseUI(UIInfo.FuncPreviewTip);
return;
}
if (viewTab.ActiveItemId != -1)
{
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
if (backPack.GetItemCountByDataId(viewTab.ActiveItemId) > 0)
if (Singleton<ObjManager>.Instance.MainPlayer)
{
var item = new GameItem();
item.DataID = viewTab.ActiveItemId;
Singleton<ObjManager>.Instance.MainPlayer.UseItem(item);
}
}
else //开启功能
{
//进阶部分激活
switch (viewTab.ActiveFunType)
{
case (int) ActiveType.Advance:
{
if (viewTab.ActiveFunSubType != -1 &&
!AdvanceCanadvanceCtr.GetInstance().IsAdvanceFuncOpen(viewTab.ActiveFunSubType))
{
//var req = (CG_REQ_ADVANCE) PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ADVANCE);
//req.SetOptionType((int) AdvanceBase.ReqType.ADVANCE_OPTION);
//req.SetType(viewTab.ActiveFunSubType);
//req.SetParam1(1); //自动购买
//req.SetParam2(0);
//req.SendPacket();
}
}
break;
}
}
UIManager.CloseUI(UIInfo.FuncPreviewTip);
}
public void InitNameAndNameIcon()
{
if (viewTab == null) return;
funcName.text = viewTab.PreviewFuncName;
LoadAssetBundle.Instance.SetImageSprite(funcNameIcon, viewTab.PreviewFuncNameIconPath,
delegate(bool isSucess, GameObject obj)
{
if (isSucess) funcNameIcon.SetNativeSize();
});
}
public void OnModelClick()
{
if (needActionAnimationName.Equals("")) return;
if (!needActionAnimationName.Equals(""))
{
var animator = modelCamera._FakeObj.FakeObj.GetComponentInChildren<Animator>();
if (animator == null) LogModule.ErrorLog("Animator is null");
animator.Play(viewTab.AnimationName);
}
}
public void OnCloseBntClick()
{
if (isActivePanel) OnActiveBtnClick(); //需要
UIManager.CloseUI(UIInfo.FuncPreviewTip);
}
private enum ActiveType
{
Invalid = -1,
Advance = 0 //进阶
}
}