362 lines
12 KiB
C#
362 lines
12 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Games.Mission;
|
||
using GCGame.Table;
|
||
using Module.Log;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class FunctionPreviewCtr : MonoBehaviour
|
||
{
|
||
private const string effectName = "effect";
|
||
|
||
public static FunctionPreviewCtr Instance;
|
||
|
||
private int _LastShowFuncViewId = -1;
|
||
private int curNeedShowFuncViewId = -1;
|
||
|
||
private int curViewId = -1;
|
||
|
||
private int initFuncViewId = -1;
|
||
|
||
private int lastCompleteMainMissionId = -1;
|
||
|
||
private readonly Dictionary<int, MissionInterval> missionIntervalDic = new Dictionary<int, MissionInterval>();
|
||
|
||
private void Awake()
|
||
{
|
||
Instance = this;
|
||
modelCamera.isPreview = true;
|
||
GetFuncMissionIntervalDic();
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
OptionShowPanel();
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
Instance = null;
|
||
}
|
||
|
||
public void GetFuncMissionIntervalDic()
|
||
{
|
||
var tabDic = TableManager.GetFunctionPreview().Values;
|
||
foreach (var info in tabDic)
|
||
if (!missionIntervalDic.ContainsKey(info.Id))
|
||
{
|
||
var missionInterval = new MissionInterval(info.OpenFuncMissionId,
|
||
info.CloseFuncMissionId, info.OpenNeedLevel,
|
||
info.CloseNeedLevel);
|
||
missionIntervalDic.Add(info.Id, missionInterval);
|
||
}
|
||
}
|
||
|
||
public void OnMissionComplteOver(int missionId = -1, int nextMissionID = -1)
|
||
{
|
||
if (missionId != -1) SetLastCompleteMainMissionId(missionId);
|
||
|
||
var missionBase = TableManager.GetMissionBaseByID(missionId, 0);
|
||
if(missionBase != null
|
||
&& (missionBase.MissionType != (int)MISSIONTYPE.MISSION_DAILY || missionBase.MissionType != (int)MISSIONTYPE.MISSION_BRANCH))
|
||
{
|
||
if (missionId != -1)
|
||
{
|
||
initFuncViewId = curNeedShowFuncViewId;
|
||
var viewTab = TableManager.GetFunctionPreviewByID(initFuncViewId, 0);
|
||
if (viewTab != null && missionId == viewTab.CloseFuncMissionId && viewTab.IsNeedPopActiveFunc != -1)
|
||
{
|
||
GuideLogic._isShowCompleteMissionGuide = true;
|
||
|
||
UIManager.ShowUI(UIInfo.PopAdvanceTip, delegate (bool bSucess, object param)
|
||
{
|
||
if (bSucess)
|
||
{
|
||
if (PopAdvanceTipCtr.Instance)
|
||
PopAdvanceTipCtr.Instance.InitFuncpreviewPanel(initFuncViewId, missionId, nextMissionID);
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
if (nextMissionID >= 0) //0为初始任务
|
||
{
|
||
var missionNext = TableManager.GetMissionNextByID(nextMissionID, 0);
|
||
if (missionNext != null)
|
||
{
|
||
nextMissionID = missionNext.GetMissionIDbyIndex(0);
|
||
if (GuideLogic.Instance())
|
||
{
|
||
GuideLogic.Instance().NextMissionID = nextMissionID;
|
||
GuideLogic.OnMissionComplateStatic(missionId, missionNext.GetMissionIDbyIndex(0));
|
||
}
|
||
else
|
||
{
|
||
GameManager.gameManager.MissionManager.MissionPathFinder(nextMissionID);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (GuideLogic.Instance())
|
||
GuideLogic.OnMissionComplateStatic(missionId, -1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//获取需要显示的ViewTabId必须放在后面,
|
||
GetNeedShowFuncViewId();
|
||
OptionShowPanel();
|
||
}
|
||
|
||
public void OnLevelChange()
|
||
{
|
||
if (lastCompleteMainMissionId <= 0) GetLastCompleteMainMissionId();
|
||
|
||
GetNeedShowFuncViewId();
|
||
OptionShowPanel();
|
||
}
|
||
|
||
public void SetLastCompleteMainMissionId(int missionId)
|
||
{
|
||
var missionBase = TableManager.GetMissionBaseByID(missionId, 0);
|
||
if (missionBase != null && missionBase.MissionType == (int) MISSIONTYPE.MISSION_MAIN)
|
||
lastCompleteMainMissionId = lastCompleteMainMissionId >= missionId ? lastCompleteMainMissionId : missionId;
|
||
}
|
||
|
||
public void GetLastCompleteMainMissionId()
|
||
{
|
||
if (lastCompleteMainMissionId != -1) // != -1证明已经获取了,后面只用在完成任务的时候赋值就可以了
|
||
return;
|
||
|
||
var missionDic = TableManager.GetMissionBase().Values;
|
||
foreach (var info in missionDic)
|
||
if (info.MissionType == (int) MISSIONTYPE.MISSION_MAIN)
|
||
{
|
||
if (GameManager.gameManager.MissionManager.IsMissionHaveDone(info.Id))
|
||
lastCompleteMainMissionId = lastCompleteMainMissionId > info.Id
|
||
? lastCompleteMainMissionId
|
||
: info.Id;
|
||
else
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
public void GetNeedShowFuncViewId()
|
||
{
|
||
curNeedShowFuncViewId = -1;
|
||
var playerLevel = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level;
|
||
foreach (var info in missionIntervalDic)
|
||
if (info.Value.openMissionId != -1)
|
||
{
|
||
if (lastCompleteMainMissionId >= info.Value.openMissionId &&
|
||
lastCompleteMainMissionId < info.Value.closeMissionId)
|
||
{
|
||
curNeedShowFuncViewId = info.Key;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (info.Value.openNeedLevel != -1)
|
||
if (playerLevel >= info.Value.openNeedLevel && playerLevel < info.Value.closeNeedLevel)
|
||
{
|
||
curNeedShowFuncViewId = info.Key;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
//是否要关闭对应的UI或者打开对应的UI
|
||
public void OptionShowPanel()
|
||
{
|
||
if (curNeedShowFuncViewId == -1)
|
||
{
|
||
ShowPanel.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
ShowPanel.SetActive(true);
|
||
ShowFunctionPreviewPanelById();
|
||
}
|
||
|
||
public void ShowFunctionPreviewPanelById()
|
||
{
|
||
//if (_LastShowFuncViewId == curNeedShowFuncViewId) return;
|
||
_LastShowFuncViewId = curNeedShowFuncViewId;
|
||
|
||
curViewId = curNeedShowFuncViewId;
|
||
var viewTab = TableManager.GetFunctionPreviewByID(curNeedShowFuncViewId, 0);
|
||
if (viewTab == null)
|
||
{
|
||
ShowPanel.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
ShowPanel.SetActive(true);
|
||
if (!viewTab.ShowCharModelId.Equals("-1"))
|
||
InitThreeDPanel(viewTab);
|
||
else if (!viewTab.ShowIconPath.Equals("-1"))
|
||
InitTwoDPanel(viewTab);
|
||
else
|
||
InitBundlePathPanel(viewTab);
|
||
|
||
InitNameIconAndFuncDesc(viewTab);
|
||
}
|
||
|
||
public void InitNameIconAndFuncDesc(Tab_FunctionPreview viewTab)
|
||
{
|
||
LoadAssetBundle.Instance.SetImageSprite(nameIcon, viewTab.NameIconPath, LoadImageOver);
|
||
funcDesc.text = viewTab.OpenFuncDesc;
|
||
}
|
||
|
||
public void LoadImageOver(bool isSucess, GameObject obj)
|
||
{
|
||
if (isSucess) obj.GetComponent<Image>().SetNativeSize();
|
||
}
|
||
|
||
public void InitTwoDPanel(Tab_FunctionPreview viewTab)
|
||
{
|
||
twoDPanel.SetActive(true);
|
||
threeDPanel.SetActive(false);
|
||
bundlePathPanel.SetActive(false);
|
||
LoadAssetBundle.Instance.SetImageSprite(funIcon, viewTab.ShowIconPath);
|
||
funIcon.rectTransform.sizeDelta = new Vector2(float.Parse(viewTab.ShowRecSize.Split('|')[0]),
|
||
float.Parse(viewTab.ShowRecSize.Split('|')[1]));
|
||
}
|
||
|
||
public void InitThreeDPanel(Tab_FunctionPreview viewTab)
|
||
{
|
||
twoDPanel.SetActive(false);
|
||
threeDPanel.SetActive(true);
|
||
bundlePathPanel.SetActive(false);
|
||
|
||
//是否需要解析
|
||
var neeShowCharModelId = -1;
|
||
var modelIdStr = viewTab.ShowCharModelId;
|
||
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.ShowCharModelId);
|
||
|
||
var charModel = TableManager.GetCharModelByID(neeShowCharModelId, 0);
|
||
if (charModel == null)
|
||
{
|
||
Debug.LogErrorFormat("CharModel is null :{0}", viewTab.ShowCharModelId);
|
||
return;
|
||
}
|
||
|
||
modelCamera.InitModelPath(charModel.ResPath, charModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true,
|
||
delegate { modelCamera.gameObject.SetActive(true); });
|
||
}
|
||
|
||
public void InitBundlePathPanel(Tab_FunctionPreview viewTab)
|
||
{
|
||
twoDPanel.SetActive(false);
|
||
threeDPanel.SetActive(false);
|
||
bundlePathPanel.SetActive(true);
|
||
|
||
var bundlePath = TableManager.GetBundlePathByID(viewTab.ShowBundelPathId, 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());
|
||
}
|
||
|
||
|
||
public void OnMaskClick()
|
||
{
|
||
if (curViewId == -1)
|
||
{
|
||
gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
UIManager.ShowUI(UIInfo.FuncPreviewTip, delegate(bool bSucess, object param)
|
||
{
|
||
if (bSucess) FuncPreviewTipCtr.Instance.InitTips(curViewId);
|
||
});
|
||
}
|
||
|
||
public class MissionInterval
|
||
{
|
||
public int closeMissionId;
|
||
public int closeNeedLevel;
|
||
public int openMissionId;
|
||
public int openNeedLevel;
|
||
|
||
public MissionInterval(int _OpenMissionId, int _CloseMissionId, int _OpenNeedLevel, int _CloseNeedLevel)
|
||
{
|
||
openMissionId = _OpenMissionId;
|
||
closeMissionId = _CloseMissionId;
|
||
openNeedLevel = _OpenNeedLevel;
|
||
closeNeedLevel = _CloseNeedLevel;
|
||
}
|
||
}
|
||
|
||
#region
|
||
|
||
public Image funIcon;
|
||
public UICameraTexture modelCamera;
|
||
public Image nameIcon;
|
||
public Text funcDesc;
|
||
|
||
public GameObject twoDPanel;
|
||
public GameObject threeDPanel;
|
||
public GameObject bundlePathPanel;
|
||
public Transform bundlePathIconParent;
|
||
public GameObject ShowPanel;
|
||
|
||
#endregion
|
||
} |