示例#1
0
    /// <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);
    }
示例#2
0
    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);
    }
示例#3
0
 public bool hasBroad(iNwkSync sync)
 {
     for (int i = 0; i < broadcasters.Count; i++)
     {
         if (broadcasters[i].handle == sync)
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
    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);
        }
    }
示例#5
0
    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++;
            }
        }
    }
示例#6
0
    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);
    }
示例#7
0
 /// <summary>
 /// explains how to sub to syncer
 /// </summary>
 static public NwkSyncableData subSync(this iNwkSync instance)
 {
     return(GameObject.FindObjectOfType <NwkSyncer>().sub(instance));
 }