Files
JJBB/Assets/Project/Script/Obj/Obj_Characters/Obj_CollectItem.cs
2024-08-23 15:49:34 +08:00

149 lines
4.8 KiB
C#

using System.Collections;
using Games.GlobeDefine;
using GCGame.Table;
using UnityEngine;
namespace Games.LogicObj
{
public class Obj_Init_CollectItem : Obj_Init_Data
{
public Tab_CollectItem collectItem;
public int index;
public Obj_Init_CollectItem()
{
CleanUp();
}
public override void CleanUp()
{
base.CleanUp();
collectItem = null;
index = -1;
}
}
public class Obj_CollectItem : Obj
{
public const int MaxParamCount = 4;
private readonly int[] IntParam = new int[MaxParamCount];
private readonly string[] StrParam = new string[MaxParamCount];
public Obj_CollectItem()
{
CleanUp();
m_ObjType = GameDefine_Globe.OBJ_TYPE.OBJ_COLLECTITEM;
}
protected Obj_NPCHeadUI m_headUIObj;
public override UIPathData HeadUiPath
{
get { return Obj_NPCHeadUI.pathData; }
}
public override bool Init(ObjParent_Init_Data initData)
{
var result = base.Init(initData);
if (result == false)
return false;
var inidata1 = initData as Obj_Init_CollectItem;
if (inidata1 == null)
return false;
SetIntParam(1, inidata1.collectItem.Index);
SetIntParam(0, inidata1.collectItem.CharModelID);
ModelID = inidata1.collectItem.CharModelID;
SetIntParam(2, inidata1.index);
var hash = new Hashtable {{"Tab_CollectItem", inidata1.collectItem}};
gameObject.tag = "CollectItem";
gameObject.name = inidata1.m_StrName;
ObjManager.Instance.AddPoolOtherGameObj(inidata1.m_StrName, this);
var charModel = TableManager.GetCharModelByID(ModelID, 0);
if (null != charModel) m_DeltaHeight = charModel.HeadInfoHeight;
if(inidata1.collectItem.ShowName == 1)
CreateNameBoard();
CreateModel(inidata1.collectItem.CharModelID, table: hash);
return true;
}
protected override void OnObjDestroy()
{
base.OnObjDestroy();
}
protected override void CreateModelOver(Hashtable hashTable)
{
base.CreateModelOver(hashTable);
if (hashTable == null)
return;
if (hashTable.ContainsKey("Tab_CollectItem"))
{
var collectItem = hashTable["Tab_CollectItem"] as Tab_CollectItem;
if (collectItem != null)
transform.localRotation = Quaternion.Euler(collectItem.RotX, collectItem.RotY, collectItem.RotZ);
;
if(ModelNode!=null && ModelNode.model!=null)
{
ModelNode.model.transform.localPosition = new Vector3(0, collectItem.PosY, 0);
}
}
}
public override void InitNameBoard(Obj_HeadUI headUiItem)
{
base.InitNameBoard(headUiItem);
m_headUIObj = (Obj_NPCHeadUI)headUiItem;
m_headUIObj.HideHp(false);
m_headUIObj.SetNameColor(GCGame.Utils.GetColorByString(StrDictionary.GetClientDictionaryString("#{5560}")));
Tab_CharModel charModel = TableManager.GetCharModelByID(ModelID, 0);
if(charModel!=null)
{
m_headUIObj.SetName(charModel.Name);
}
else
{
m_headUIObj.SetName("");
}
}
public void BreakCollectState(Tab_MissionCollectItem collectItem)
{
if (collectItem == null)
return;
if ((collectItem.RemoveType & 1) != 0)
for (var i = 0; i < collectItem.getEffectIDCount(); i++)
ObjEffectLogic.StopEffect(collectItem.GetEffectIDbyIndex(i));
}
private void CleanUp()
{
for (var i = 0; i < MaxParamCount; i++)
{
IntParam[i] = 0;
StrParam[i] = "";
}
}
public void SetIntParam(int nIndex, int nValue)
{
if (nIndex >= 0 && nIndex < MaxParamCount) IntParam[nIndex] = nValue;
}
public int GetIntParamByIndex(int nIndex)
{
if (nIndex >= 0 && nIndex < MaxParamCount) return IntParam[nIndex];
return 0;
}
//public void SetStrParam(int nIndex, string strValue)
//{
// if (nIndex >= 0 && nIndex < MaxParamCount) StrParam[nIndex] = strValue;
//}
//public string GetStrParamByIndex(int nIndex)
//{
// if (nIndex >= 0 && nIndex < MaxParamCount) return StrParam[nIndex];
// return "";
//}
}
}