Skip to content

Commit 9df6316

Browse files
committed
Fixed SyncedVarHook issue
1 parent f45ac57 commit 9df6316

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

MLAPI/Attributes/SyncedVar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class SyncedVar : Attribute
1111
/// <summary>
1212
/// The method name to invoke when the SyncVar get's updated.
1313
/// </summary>
14-
public string hook;
14+
public string hookMethodName;
1515
/// <summary>
1616
/// If true, the syncedVar will only be synced to the owner.
1717
/// </summary>

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,24 @@ internal void SyncVarInit()
213213
{
214214
if(sortedFields[i].IsDefined(typeof(SyncedVar), true))
215215
{
216-
object[] syncedVarAttributes = sortedFields[i].GetCustomAttributes(typeof(SyncedVar), true);
217-
MethodInfo method = null;
218-
if (!string.IsNullOrEmpty(((SyncedVar)syncedVarAttributes[0]).hook))
219-
{
220-
method = GetType().GetMethod(((SyncedVar)syncedVarAttributes[0]).hook, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
221-
break;
222-
}
216+
SyncedVar attribute = ((SyncedVar)sortedFields[i].GetCustomAttributes(typeof(SyncedVar), true)[0]);
217+
218+
MethodInfo hookMethod = null;
219+
220+
if (!string.IsNullOrEmpty(attribute.hookMethodName))
221+
hookMethod = GetType().GetMethod(attribute.hookMethodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
222+
223223
FieldType fieldType = FieldTypeHelper.GetFieldType(sortedFields[i].FieldType);
224224
if (fieldType != FieldType.Invalid)
225225
{
226226
syncedVarFields.Add(new SyncedVarField()
227227
{
228228
Dirty = false,
229-
Target = ((SyncedVar)sortedFields[i].GetCustomAttributes(typeof(SyncedVar), true)[0]).target,
229+
Target = attribute.target,
230230
FieldInfo = sortedFields[i],
231231
FieldType = fieldType,
232232
FieldValue = sortedFields[i].GetValue(this),
233-
HookMethod = method
233+
HookMethod = hookMethod
234234
});
235235
}
236236
else

0 commit comments

Comments
 (0)