/// <summary> /// en l'état il faut que le couple Compo,Inwk soit unique dans toute la hierarchie /// </summary> iNwkSync filterSyncableOnInstance(GameObject copy, string factoType) { //https://stackoverflow.com/questions/11107536/convert-string-to-type-in-c-sharp Type _type = Type.GetType(factoType); //gather all syncable in newly created object List <iNwkSync> all = new List <iNwkSync>(); all.AddRange(copy.GetComponentsInChildren <iNwkSync>()); all.AddRange(copy.GetComponentsInParent <iNwkSync>()); for (int i = 0; i < all.Count; i++) { Debug.Log(" L " + _type.GetType() + " vs " + all[i].GetType()); if (compareType(all[i].GetType(), _type)) { iNwkSync tmp = all[i] as iNwkSync; if (tmp != null) { return(tmp); } } } return(null); }
public NwkSyncableData sub(iNwkSync sync) { if (hasBroad(sync)) { Debug.LogError("already has that sync ? " + sync); return(null); } // at this point the generated IID is not final, it can be overritten just after sub (if copy) NwkSyncableData data = sync.getData(); if (data != null) { broadcasters.Add(data); //on sub l'objet que si c'est un objet local if (data.syncNwkClientUID == NwkClient.nwkUid) { frequencers.Add(data); } Debug.Log("sub '" + sync + "' to syncer"); } else { Debug.LogWarning(sync + " was not sub to syncer ?"); } return(data); }
public bool hasBroad(iNwkSync sync) { for (int i = 0; i < broadcasters.Count; i++) { if (broadcasters[i].handle == sync) { return(true); } } return(false); }
void bubbleSyncableToListeners(GameObject copy, iNwkSync sync) { List <INwkSyncListener> all = new List <INwkSyncListener>(); all.AddRange(copy.GetComponentsInChildren <INwkSyncListener>()); all.AddRange(copy.GetComponentsInParent <INwkSyncListener>()); for (int i = 0; i < all.Count; i++) { all[i].evtINwkScopeChange(sync, false); } }
public void unsub(iNwkSync sync) { if (!hasBroad(sync)) { Debug.LogError("don't have that sync to unsub"); return; } int idx = 0; while (idx < broadcasters.Count) { if (broadcasters[idx].handle == sync) { stack.RemoveAt(idx); } else { idx++; } } }
protected NwkSyncableData solveUnknownData(int cUID, int oIID, int oPID) { GameObject copy = factoryDb.copy(oPID); if (copy == null) { Debug.LogWarning("no copy possible with PID : " + oPID); return(null); } copy.name += oIID.ToString(); Debug.Log(Time.frameCount + " => copy ? " + copy); //find ref of component of that sync in newly created object NwkSyncableData curSyncData = null; iNwkSync sync = filterSyncableOnInstance(copy, factoryDb.items[oPID].type); if (sync == null) { Debug.LogError("no sync found in copy ?"); return(null); } //forcing object to generate it's data curSyncData = sync.getData(); //but won't have owner info yet, so we need to inject id info here //inject none-local stuff curSyncData.overrideData(cUID, oIID, oPID); Debug.Log(Time.frameCount + " => data ? " + curSyncData); bubbleSyncableToListeners(copy, sync); return(curSyncData); }
/// <summary> /// explains how to sub to syncer /// </summary> static public NwkSyncableData subSync(this iNwkSync instance) { return(GameObject.FindObjectOfType <NwkSyncer>().sub(instance)); }