JJBB/Assets/Project/Script/GUI/Advance/PopAdvanceTipCtr.cs

341 lines
11 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using GCGame.Table;
using Games.Item;
public class PopAdvanceTipCtr : MonoBehaviour {
public static PopAdvanceTipCtr Instance;
void Awake()
{
Instance = this;
}
private int _TotalRemainTime = 5;
private void OnEnable()
{
InitRemainTimeDesc();
}
public void InitRemainTimeDesc()
{
//默认五秒后关闭界面
_TotalRemainTime = 5;
_RemainTimeDesc.text = StrDictionary.GetClientDictionaryString("#{1311}", _TotalRemainTime);
}
private void OnDestroy()
{
Instance = null;
}
public Text _Name;
public Text _RemainTimeDesc;
public UICameraTexture _ModelCamera;
public Transform _AnimationTransParent;
private const string effectName = "effect";
private int _MissionId = -1;
private int _NextMissionId = -1;
public void InitFuncpreviewPanel(int funcPreViewId, int missionId = -1, int nextMissionId = -1)
{
_MissionId = missionId;
_NextMissionId = nextMissionId;
Tab_FunctionPreview funcPreview = TableManager.GetFunctionPreviewByID(funcPreViewId, 0);
if(funcPreview == null)
{
OnCloseBtnClick();
return;
}
_Name.text = funcPreview.UIShowName;
ActiviteFunc(funcPreview);
if (!funcPreview.ShowCharModelId.Equals("-1"))
{
int neeShowCharModelId = -1;
string modelIdStr = funcPreview.PopOpenFunctionModelId;
bool isStr = false;
for (int 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(funcPreview.PopOpenFunctionModelId);
}
ShowModel(neeShowCharModelId);
}
else
{
ShowAnimation(funcPreview.ShowBundelPathId);
}
}
private bool _IsHideAdvancePanel = false;
public void HideAdvancePanel()
{
_IsHideAdvancePanel = true;
if (AdvanceMountPanelCtr.Instance && AdvanceMountPanelCtr.Instance.gameObject.activeInHierarchy)
{
AdvanceMountPanelCtr.Instance.gameObject.SetActive(false);
}
}
private enum ActiveType
{
Invalid = -1,
Advance = 0, //进阶
}
public void ActiviteFunc(Tab_FunctionPreview viewTab)
{
if (viewTab.ActiveItemId != -1)
{
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
if (backPack.GetItemCountByDataId(viewTab.ActiveItemId) > 0)
{
//使用道具
if (Singleton<ObjManager>.Instance.MainPlayer)
{
GameItem 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))
{
CG_REQ_ADVANCE req = (CG_REQ_ADVANCE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ADVANCE);
req.SetOptionType((int)AdvanceBase.ReqType.ADVANCE_OPTION);
req.SetType((int)viewTab.ActiveFunSubType);
req.SetParam1(1); //自动购买
req.SetParam2(0);
req.SendPacket();
}
}
break;
}
}
}
private int _CurAdvanceType = -1;
private bool _IsOpenAdvance = false;
public void InitAdvancePanel(int advanceBaseId, bool isAutoAdvance)
{
_IsOpenAdvance = isAutoAdvance;
Tab_AdvanceBase advanceBase = TableManager.GetAdvanceBaseByID(advanceBaseId, 0);
if(advanceBase == null)
{
OnCloseBtnClick();
return;
}
_Name.text = advanceBase.Name;
_CurAdvanceType = (advanceBaseId - advanceBase.Level) / 1000 - 1;
HideAdvancePanel();
GlobalData.CurAdvanceType = _CurAdvanceType;
switch (_CurAdvanceType)
{
case (int)AdvanceBase.AdvanceType.Ride:
{
Tab_MountBase mountBase = TableManager.GetMountBaseByID(advanceBase.ModelId, 0);
if (mountBase == null)
{
return;
}
Tab_CharMount charMount = TableManager.GetCharMountByID(mountBase.ModelID, 0);
if (charMount == null)
{
return;
}
_ModelCamera.InitMountModelPath(charMount, delegate() {
_ModelCamera.gameObject.SetActive(true);
});
}
break;
case (int)AdvanceBase.AdvanceType.Wing:
{
_ModelCamera.InitWingModelPath(advanceBase, null, delegate() {
_ModelCamera.gameObject.SetActive(true);
});
}
break;
default:
{
//ShowAnimation(advanceBase.ModelId);
Tab_CharModel charModel = TableManager.GetCharModelByID(advanceBase.ModelId, 0);
if(charModel == null)
{
return;
}
_ModelCamera.InitModelPath(charModel.ResPath, charModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true, delegate (){
_ModelCamera.gameObject.SetActive(true);
});
}
break;
}
}
public void ShowModel(int charModelId)
{
_ModelCamera.gameObject.SetActive(true);
_AnimationTransParent.gameObject.SetActive(false);
Tab_CharModel charModel= TableManager.GetCharModelByID(charModelId, 0);
if (charModel == null)
{
_ModelCamera.gameObject.SetActive(false);
return;
}
_ModelCamera.InitModelPath(charModel.ResPath, charModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true, delegate ()
{
_ModelCamera.gameObject.SetActive(true);
});
}
private GameObject _AnimationObj;
public void ShowAnimation(int bundlePathId)
{
_ModelCamera.gameObject.SetActive(false);
_AnimationTransParent.gameObject.SetActive(true);
Tab_BundlePath bundlePath = TableManager.GetBundlePathByID(bundlePathId, 0);
if(bundlePath == null)
{
_AnimationTransParent.gameObject.SetActive(false);
return;
}
string[] pos = bundlePath.Pos.Split(';');
Vector3 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)
{
_AnimationObj = Instantiate(resObj);
_AnimationObj.gameObject.name = effectName;
//寻找父节点下是否有effect
Transform oldObj = this.transform.Find(effectName);
if (oldObj == null)
{
_AnimationObj.transform.SetParent(_AnimationTransParent);
_AnimationObj.transform.localPosition = landPos;
_AnimationObj.transform.localScale = Vector3.one * bundlePath.Scale;
_AnimationObj.transform.localRotation = Quaternion.Euler(Vector3.zero);
}
else
{
_AnimationObj.transform.SetParent(oldObj.parent);
_AnimationObj.transform.localPosition = landPos;
_AnimationObj.transform.localScale = Vector3.one * bundlePath.Scale;
_AnimationObj.transform.localRotation = oldObj.localRotation;
GameObject.Destroy(oldObj.gameObject);
}
}
},
new Hashtable());
}
public void OnCloseBtnClick()
{
GuideLogic._isShowCompleteMissionGuide = false; //这边指引置为false
if(_IsHideAdvancePanel)
{
UIManager.ShowUI(UIInfo.AdvanceMountPanel, delegate (bool bSucess, object param)
{
if (bSucess)
{
AdvanceMountPanelCtr.Instance.SetAdvanceType(GlobalData.CurAdvanceType);
AdvanceMountPanelCtr.Instance.OnMenuItemClick(AdvanceMenuItemPanelCtr.MenuItemOptType.Advance);
if (_IsOpenAdvance)
{
AdvancePanelCtr.Instance.itemPanel.SetOutsideSetting();
AdvancePanelCtr.Instance.itemPanel.autoAdvanceToggle.isOn = true;
}
}
});
_IsHideAdvancePanel = false;
}
//Debug.LogError("MissionId : " + _MissionId);
if (_MissionId != -1)
{
var missionNext = TableManager.GetMissionNextByID(_MissionId, 0);
if (missionNext != null)
_NextMissionId = missionNext.GetMissionIDbyIndex(0);
if (GuideLogic.Instance())
{
GuideLogic.OnMissionComplateStatic(_MissionId, _NextMissionId); //主要是为了记录下一个任务ID
}
else
{
GameManager.gameManager.MissionManager.MissionPathFinder(_NextMissionId);
}
_MissionId = -1;
_NextMissionId = -1;
}
UIManager.CloseUI(UIInfo.PopAdvanceTip);
}
private void OnDisable()
{
DesAnimationObj();
}
private void DesAnimationObj()
{
if (_AnimationObj != null)
{
_AnimationObj.transform.SetParent(null);
_AnimationObj.SetActive(false);
GameObject.Destroy(_AnimationObj.gameObject);
}
}
private float _CountTime = 0.0f;
private void Update()
{
if(_TotalRemainTime >= 0)
{
_CountTime += Time.deltaTime;
if(_CountTime >= 1.0f)
{
_CountTime = 1 - _CountTime;
_TotalRemainTime--;
if(_TotalRemainTime == 0)
{
OnCloseBtnClick();
}
_RemainTimeDesc.text = StrDictionary.GetClientDictionaryString("#{1311}", _TotalRemainTime);
}
}else
{
OnCloseBtnClick();
}
}
}