Assets/Deps/emotitron/Network/NST/NSTHelper.cs
/// <summary>
/// Make a barebones copy of an object including only empty gameobjects and colliders.
/// </summary>
Make a barebones copy of an object including only empty gameobjects and colliders.
Make a barebones copy of an object including only empty gameobjects and colliders .
private static void CloneChildrenAndColliders(NetworkSyncTransform nst, GameObject rootGO, GameObject targetgo)
		{
			for (int pe = 0; pe < nst.positionElements.Count; pe++)
			{
				if (rootGO.gameObject == nst.positionElements[pe].gameobject)
				{
					nst.positionElements[pe].rewindGO = targetgo;
				}
			}
			for (int re = 0; re < nst.rotationElements.Count; re++)
			{
				if (rootGO.gameObject == nst.rotationElements[re].gameobject)
					nst.rotationElements[re].rewindGO = targetgo;
			}
			for (int i = 0; i < rootGO.transform.childCount; i++)
			{
				Transform src = rootGO.transform.GetChild(i);
				Transform copy = new GameObject(src.name).transform;
				copy.parent = targetgo.transform;
				copy.localPosition = src.localPosition;
				copy.localScale = src.localScale;
				copy.localRotation = src.localRotation;
				copy.gameObject.SetActive(src.gameObject.activeSelf);
				Collider orig = src.GetComponent<Collider>();
				if (orig != null && nst.rewindHitLayers.value.GetBitInMask(src.gameObject.layer))  
				{
					Collider newcol = copy.gameObject.AddColliderCopy(orig);
					newcol.isTrigger = true;
				}
				CloneChildrenAndColliders(nst, rootGO.transform.GetChild(i).gameObject, copy.gameObject);
			}
		}
private static void CloneChildrenAndColliders ( NetworkSyncTransform nst , GameObject rootGO , GameObject targetgo ) { for ( int pe = 0 ; pe < nst . positionElements . Count ; pe ++ ) { if ( rootGO . gameObject == nst . positionElements [ pe ] . gameobject ) { nst . positionElements [ pe ] . rewindGO = targetgo ; } } for ( int re = 0 ; re < nst . rotationElements . Count ; re ++ ) { if ( rootGO . gameObject == nst . rotationElements [ re ] . gameobject ) nst . rotationElements [ re ] . rewindGO = targetgo ; } for ( int i = 0 ; i < rootGO . transform . childCount ; i ++ ) { Transform src = rootGO . transform . GetChild ( i ) ; Transform copy = new GameObject ( src . name ) . transform ; copy . parent = targetgo . transform ; copy . localPosition = src . localPosition ; copy . localScale = src . localScale ; copy . localRotation = src . localRotation ; copy . gameObject . SetActive ( src . gameObject . activeSelf ) ; Collider orig = src . GetComponent < Collider > ( ) ; if ( orig != null && nst . rewindHitLayers . value . GetBitInMask ( src . gameObject . layer ) ) { Collider newcol = copy . gameObject . AddColliderCopy ( orig ) ; newcol . isTrigger = true ; } CloneChildrenAndColliders ( nst , rootGO . transform . GetChild ( i ) . gameObject , copy . gameObject ) ; } }
Make a barebones copy of an object including only empty gameobjects and colliders.
Make a barebones copy of an object including only empty gameobjects and colliders .
// If we are replicating one of the rotation gameobjects, store its clone // See if this gameobject is used by rotation elements, if so we want to associate it with that element // Find all children //((src.gameObject.layer & nst.rewindHitLayers.value) > 0))
nst
NetworkSyncTransform
rootGO
GameObject
targetgo
GameObject