Skip to content

Commit

Permalink
OnValueChangeMethods added and some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AncientEntity committed Jul 13, 2020
1 parent 202f9af commit a708859
Show file tree
Hide file tree
Showing 6 changed files with 643 additions and 598 deletions.
1,177 changes: 593 additions & 584 deletions Assembly-CSharp.csproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Assets/EntityNetworkingSystems/Scripts/AnimationNetworker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class AnimationNetworker : MonoBehaviour
private NetworkObject net;
//private Thread handleAnimation;



void Start()
{
anim = GetComponent<Animator>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static GameObject NetInstantiate(int prefabDomain, int prefabID, Vector3
nObj.prefabID = gOID.prefabID;
nObj.networkID = gOID.netObjID;
nObj.sharedObject = gOID.isShared;
nObj.detectNetworkStarts = NetworkData.instance.networkPrefabList[gOID.prefabDomainID].detectNetworkStarts;

nObj.Initialize();
//nObj.DoRpcFieldInitialization();
Expand Down
56 changes: 44 additions & 12 deletions Assets/EntityNetworkingSystems/Scripts/NetBackbone/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ void Awake()

}

void Start()
{
foreach(NetworkField f in fields)
{
f.InitializeSpecialFields();
}
}
//void Start()
//{
// foreach(NetworkField f in fields)
// {
// f.InitializeSpecialFields();
// }
//}



Expand Down Expand Up @@ -75,7 +75,6 @@ public void Initialize()
{
continue;
}

c.SendMessage("NetworkStart");
}
}
Expand Down Expand Up @@ -303,13 +302,24 @@ public void CallRPC(string rpcName, Packet.sendType sendType = Packet.sendType.c
}
}

public void FieldAddOnChangeMethod(string fieldName, UnityAction<FieldArgs> action)
public void FieldAddOnChangeMethod(string fieldName, UnityAction<FieldArgs> action, bool invokeNow=false)
{
foreach(NetworkField netField in fields)
{
if(netField.fieldName == fieldName)
{
netField.onValueChange.AddListener(action);

if(invokeNow == true)
{
FieldArgs constructedArgs = new FieldArgs();
constructedArgs.fieldName = fieldName;
constructedArgs.networkID = networkID;
constructedArgs.fieldValue = netField.GetField();

netField.onValueChange.Invoke(constructedArgs);
}

return;
}
}
Expand All @@ -325,7 +335,7 @@ public void ManagePositionField(FieldArgs args)
//}

Vector3 newPos = args.GetValue<SerializableVector>().ToVec3();//sVec.ToVec3();
print(newPos);
//print(newPos);
transform.position = newPos;
//Debug.Log(newPos);
}
Expand Down Expand Up @@ -365,6 +375,7 @@ public enum valueInitializer
};
public valueInitializer defaultValue = valueInitializer.None;
public OnFieldChange onValueChange = new OnFieldChange();
public OnValueMethodData[] onValueChangeMethods;
public bool shouldBeProximity = false;
private string jsonData = "notinitialized";
private string jsonDataTypeName = "notinitialized";
Expand Down Expand Up @@ -442,7 +453,6 @@ public void InitializeDefaultValue(NetworkObject netObj)

//initialized = true; //Gets set in LocalFieldSet


if(!InitializeSpecialFields())
{
switch (defaultValue)
Expand Down Expand Up @@ -556,7 +566,7 @@ public void UpdateField<T>(T value, int netObjID, bool immediateOnSelf = true)

public void LocalFieldSet<T>(T newValue, bool invokeOnChange = true)
{
InitializeSpecialFields(true); //Cause when data gets sent over the network it may miss doing this, then there wont be able special UnityEvents added.
//InitializeSpecialFields(true); //Cause when data gets sent over the network it may miss doing this, then there wont be able special UnityEvents added.

if (ENSUtils.IsSimple(newValue.GetType()))
{
Expand All @@ -577,6 +587,19 @@ public void LocalFieldSet<T>(T newValue, bool invokeOnChange = true)
if (invokeOnChange)
{
onValueChange.Invoke(constructedArgs);

//You can also input the method names as strings, not as efficient but sometimes necessary.
if (onValueChangeMethods != null)
{
foreach (OnValueMethodData methodData in onValueChangeMethods)
{
if (netObj.GetComponent(methodData.componentTypeName) != null)
{
netObj.GetComponent(methodData.componentTypeName).SendMessage(methodData.methodName, constructedArgs);
}
}
}

}
}

Expand Down Expand Up @@ -618,6 +641,7 @@ public NetworkField Clone()
//newField.initialized = initialized;
newField.shouldBeProximity = shouldBeProximity;
newField.specialFieldsInitialized = false;
newField.onValueChangeMethods = onValueChangeMethods;
return newField;
}
public static NetworkFieldPacket GenerateNFP<T>(string fieldName, T newValue, bool immediateOnSelf = false, int netObjID=-1)
Expand All @@ -637,6 +661,13 @@ public static NetworkFieldPacket GenerateNFP<T>(string fieldName, T newValue, bo
}


[System.Serializable]
public struct OnValueMethodData
{
public string componentTypeName;
public string methodName;
}


}

Expand Down Expand Up @@ -680,6 +711,7 @@ public NetworkFieldPacket(int netID, string fieldName, JsonPacketObject val, boo
data = val;
this.immediateOnSelf = immediateOnSelf;
}


}

Expand Down
1 change: 1 addition & 0 deletions Assets/EntityNetworkingSystems/Scripts/NetworkData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class GameObjectList
public GameObject[] prefabList;
[Space]
//These will automatically get applied to objects in this certain prefab domain when created, and if it doesn't have a netobj on it already.
public bool detectNetworkStarts = false;
public List<NetworkField> defaultFields;
public RPC[] defaultRpcs;
}
Expand Down
4 changes: 2 additions & 2 deletions EntityNetworkingSystems.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{623B26A5-0F12-A230-B10C-90EBE7F4FA0F}"
EndProject
Global
Expand Down

0 comments on commit a708859

Please sign in to comment.