Files
JJBB/Assets/Project/Script/GUI/Chat/ChatLinkCallFunc.cs
2024-08-23 15:49:34 +08:00

136 lines
4.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.Item;
using GCGame;
using GCGame.Table;
using Games.ChatHistory;
using System;
using System.Collections.Generic;
public class ChatLinkCallFunc : ChatLinkItem
{
private static string _InputTeamStr = StrDictionary.GetClientDictionaryString("#{5138}");
private string _ShowText;
private string _ClassName;
private string _FuncName;
private string[] _ParamNames;
private int _LinkLevel = 0;
private int _StaticFuncID;
public void SetLinkCallFunc(string showText, string className, string funcName, params string[] paramNames)
{
_ClassName = className;
_FuncName = funcName;
_ParamNames = paramNames;
_ShowText = showText;
StrInput = showText;
StrSend = StrSendStart + ((int)ChatLinkType.CallFunc).ToString() + StrSplit + _ShowText + StrSplit + _ClassName + StrSplit + _FuncName;
for (int i = 0; i < _ParamNames.Length; ++i)
{
StrSend += StrSplit + _ParamNames[i];
}
StrSend += StrSendEnd;
}
public override void SetLinkBySendStr(Text text, ChatHistoryItem chatHistory, string linkStr, string[] linkParams)
{
StrSend = linkStr;
_LinkLevel = 0;
if (linkParams.Length < 4)
{
_ShowText = (linkParams[1]);
if (!int.TryParse(linkParams[2], out _StaticFuncID))
{
return;
}
Tab_StaticFunc staticFuncRecord = TableManager.GetStaticFuncByID(_StaticFuncID, 0);
_LinkLevel = staticFuncRecord.OpenLevel;
_ClassName = staticFuncRecord.ClassName;
_FuncName = staticFuncRecord.FunctionName;
List<string> strList = new List<string>();
for (int i = 0; i < staticFuncRecord.getParamCount(); ++i)
{
string strParam = staticFuncRecord.GetParambyIndex(i);
if (!string.IsNullOrEmpty(strParam))
{
strList.Add(strParam);
}
}
_ParamNames = strList.ToArray();
}
else
{
_ShowText = (linkParams[1]);
_ClassName = (linkParams[2]);
_FuncName = (linkParams[3]);
int paramLength = linkParams.Length - 4;
_ParamNames = new string[paramLength];
for (int i = 4; i < linkParams.Length; ++i)
{
_ParamNames[i - 4] = linkParams[i];
}
}
StrInput = _ShowText;
StrShow = _ShowText;
}
protected override void LinkClick(int linkindex)
{
if (_LinkLevel > GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level)
{
GUIData.AddNotifyData("#{42697}");
return;
}
var classType = Type.GetType(_ClassName);
if (classType == null)
return;
var method = classType.GetMethod(_FuncName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
if (method != null)
method.Invoke(null, _ParamNames);
}
public static void CallStaticFunc(int staticFuncID)
{
Tab_StaticFunc staticFuncRecord = TableManager.GetStaticFuncByID(staticFuncID, 0);
var linkLevel = staticFuncRecord.OpenLevel;
if (linkLevel > GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level)
{
GUIData.AddNotifyData("#{42697}");
return;
}
var className = staticFuncRecord.ClassName;
var funcName = staticFuncRecord.FunctionName;
List<string> strList = new List<string>();
for (int i = 0; i < staticFuncRecord.getParamCount(); ++i)
{
string strParam = staticFuncRecord.GetParambyIndex(i);
if (!string.IsNullOrEmpty(strParam))
{
strList.Add(strParam);
}
}
var paramStrs = strList.ToArray();
var classType = Type.GetType(className);
if (classType == null)
return;
var method = classType.GetMethod(funcName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
if (method != null)
method.Invoke(null, paramStrs);
}
}