예제 #1
0
    public override void load(SavableData data)
    {
        if (data is PadData)
        {
            PadData savableData = (PadData)(data);

            gameObject.SetActive(savableData.active);
            ID = savableData.ID;
            transform.position = savableData.pos;
            transform.rotation = savableData.rot;

            if (savableData.testRefID != String.Empty)
            {
                testRef = SavableBehaviour.GetObject(savableData.testRefID)?.GetComponent <RefSerialzationTest>();
            }
            else
            {
                testRef = null;
            }
        }
        else
        {
            Debug.LogError("Passed data is of invalid type");
        }
    }
예제 #2
0
    public static void RegisterUUID(SavableBehaviour aID)
    {
        string UID;

        if (m_ObjToUUID.TryGetValue(aID, out UID))
        {
            // found object instance, update ID
            aID.m_UUID     = UID;
            aID.m_IDBackup = aID.m_UUID;
            if (!m_UUIDtoObj.ContainsKey(UID))
            {
                m_UUIDtoObj.Add(UID, aID);
            }
            return;
        }

        if (string.IsNullOrEmpty(aID.m_UUID))
        {
            // No ID yet, generate a new one.
            aID.m_UUID     = System.Guid.NewGuid().ToString();
            aID.m_IDBackup = aID.m_UUID;
            m_UUIDtoObj.Add(aID.m_UUID, aID);
            m_ObjToUUID.Add(aID, aID.m_UUID);
            return;
        }

        SavableBehaviour tmp;

        if (!m_UUIDtoObj.TryGetValue(aID.m_UUID, out tmp))
        {
            // ID not known to the DB, so just register it
            m_UUIDtoObj.Add(aID.m_UUID, aID);
            m_ObjToUUID.Add(aID, aID.m_UUID);
            return;
        }
        if (tmp == aID)
        {
            // DB inconsistency
            m_ObjToUUID.Add(aID, aID.m_UUID);
            return;
        }
        if (tmp == null)
        {
            // object in DB got destroyed, replace with new
            m_UUIDtoObj[aID.m_UUID] = aID;
            m_ObjToUUID.Add(aID, aID.m_UUID);
            return;
        }
        // we got a duplicate, generate new ID
        aID.m_UUID     = System.Guid.NewGuid().ToString();
        aID.m_IDBackup = aID.m_UUID;
        m_UUIDtoObj.Add(aID.m_UUID, aID);
        m_ObjToUUID.Add(aID, aID.m_UUID);
    }
예제 #3
0
 public static string GetID(SavableBehaviour savableBehaviour)
 {
     if (m_ObjToUUID.ContainsKey(savableBehaviour))
     {
         return(m_ObjToUUID[savableBehaviour]);
     }
     else
     {
         return(null);
     }
 }
예제 #4
0
    public override SavableData save()
    {
        PadData savableData = new PadData();

        savableData.ID     = SavableBehaviour.GetID(this);
        savableData.active = gameObject.activeSelf;
        savableData.pos    = transform.position;
        savableData.rot    = transform.rotation;

        SavableBehaviour testRefSavable = testRef?.GetComponent <SavableBehaviour>();

        if (testRefSavable != null)
        {
            savableData.testRefID = testRefSavable.ID;
        }
        else
        {
            savableData.testRefID = System.String.Empty;
        }

        return(savableData);
    }
예제 #5
0
 public static bool UUIDexists(SavableBehaviour id)
 {
     return(m_UUIDtoObj.ContainsKey(id.ID));
 }
예제 #6
0
 public static void UnregisterUUID(SavableBehaviour aID)
 {
     m_UUIDtoObj.Remove(aID.m_UUID);
     m_ObjToUUID.Remove(aID);
 }