Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #285 from phalasz/object-instantiation
Browse files Browse the repository at this point in the history
Fix Object instantiated at Vector3.zero and then slide to position when interpolation is on
  • Loading branch information
NFMynster authored Aug 20, 2019
2 parents 73cbb73 + cb7433c commit eacb104
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace BeardedManStudios.Forge.Networking.Unity
if (Networker != null)
Networker.objectCreated -= CaptureObjects;
}

private void CaptureObjects(NetworkObject obj)
{
if (obj.CreateCode < 0)
return;

>:FOREACH networkObjects:<
>:ELSEIF:< (obj is >:[i]:<NetworkObject)
{
Expand All @@ -47,7 +47,7 @@ namespace BeardedManStudios.Forge.Networking.Unity

if (newObj == null)
return;

newObj.Initialize(obj);

if (objectInitialized != null)
Expand All @@ -65,21 +65,6 @@ namespace BeardedManStudios.Forge.Networking.Unity
obj.pendingInitialized -= InitializedObject;
}

>:FOREACH networkObjects:<
[Obsolete("Use Instantiate>:[i]:< instead, its shorter and easier to type out ;)")]
public >:[i]:<Behavior Instantiate>:[i]:<NetworkObject(int index = 0, Vector3? position = null, Quaternion? rotation = null, bool sendTransform = true)
{
var go = Instantiate(>:[i]:<NetworkObject[index]);
var netBehavior = go.GetComponent<>:[i]:<Behavior>();
var obj = netBehavior.CreateNetworkObject(Networker, index);
go.GetComponent<>:[i]:<Behavior>().networkObject = (>:[i]:<NetworkObject)obj;

FinalizeInitialization(go, netBehavior, obj, position, rotation, sendTransform);

return netBehavior;
}
>:ENDFOREACH:<

>:FOREACH networkObjects:<
/// <summary>
/// Instantiate an instance of >:[i]:<
Expand All @@ -94,6 +79,7 @@ namespace BeardedManStudios.Forge.Networking.Unity
public >:[i]:<Behavior Instantiate>:[i]:<(int index = 0, Vector3? position = null, Quaternion? rotation = null, bool sendTransform = true)
{
var go = Instantiate(>:[i]:<NetworkObject[index]);
go.SetActive(false);
var netBehavior = go.GetComponent<>:[i]:<Behavior>();

NetworkObject obj = null;
Expand Down Expand Up @@ -129,7 +115,7 @@ namespace BeardedManStudios.Forge.Networking.Unity
go.GetComponent<>:[i]:<Behavior>().networkObject = (>:[i]:<NetworkObject)obj;

FinalizeInitialization(go, netBehavior, obj, position, rotation, sendTransform);

return netBehavior;
}
>:ENDFOREACH:<
Expand Down
5 changes: 2 additions & 3 deletions ForgeUnity/Assets/BeardedManStudios/Scripts/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,15 @@ protected virtual void FinalizeInitialization(GameObject go, INetworkBehavior ne
go.transform.position = position.Value;
}

//if (sendTransform)
// obj.SendRpc(NetworkBehavior.RPC_SETUP_TRANSFORM, Receivers.AllBuffered, go.transform.position, go.transform.rotation);

if (!skipOthers)
{
// Go through all associated network behaviors in the hierarchy (including self) and
// Assign their TempAttachCode for lookup later. Should use an incrementor or something
uint idOffset = 1;
ProcessOthers(go.transform, obj, ref idOffset, (NetworkBehavior)netBehavior);
}

go.SetActive(true);
}

/// <summary>
Expand Down

0 comments on commit eacb104

Please sign in to comment.