// Scan the list of pending resolvers, and see if we have an Object mapped to the requested GUID.
        // Once a resolver is complete, it will be removed from the list.
        // GUID maps are only removed once the target Object is destroyed
        public void ResolveLinks()
        {
            // Define that is only set once the SimpleCrossSceneReferenceSetup has run once
            // This is because the XSR.Codegen.CrossSceneReference_Codegen_Entry won't exist in the User assembly
            // until after codegen runs
#if SIMPLE_CROSS_SCENE_REFERENCES
            if (ResolveTargets.Count > 0 && LinkTargets.Count > 0)
            {
#if SIMPLE_CROSS_SCENE_REFERENCES_DEBUG
                Stopwatch timer = new Stopwatch();
                timer.Start();
#endif
                // Loop over resolvers
                for (int i = ResolveTargets.Count - 1; i >= 0; i--)
                {
                    CrossSceneReferenceSetupData resolve = ResolveTargets[i];
                    if (LinkTargets.TryGetValue(resolve.GUID, out Object Value))
                    {
                        // A mapped GUID was found. Use the codegen class to assign the Object value to the field
                        XSR.Codegen.CrossSceneReference_Codegen_Entry.Set(resolve.ClassHash, resolve.RouteHash, resolve.Target, Value, resolve.Context);
                        ResolveTargets.RemoveAt(i);
                    }
                }

#if SIMPLE_CROSS_SCENE_REFERENCES_DEBUG
                timer.Stop();
                UnityEngine.Debug.Log($"XSR manager spent {timer.ElapsedMilliseconds}ms resolving links");
#endif
            }
#endif
        }
 public void DeregisterResolver(CrossSceneReferenceSetupData resolver)
 {
     for (int i = ResolveTargets.Count - 1; i >= 0; i--)
     {
         if (ResolveTargets[i].Target == resolver.Target)
         {
             ResolveTargets.RemoveAt(i);
         }
     }
 }
Ejemplo n.º 3
0
        public void AddResolverData(CrossSceneReferenceSetupData data)
        {
            bool updated = false;

            for (int i = 0; i < ResolverData.Count; i++)
            {
                CrossSceneReferenceSetupData existingData = ResolverData[i];
                if (existingData.ClassHash == data.ClassHash &&
                    existingData.RouteHash == data.RouteHash &&
                    existingData.Target == data.Target)
                {
                    existingData.GUID = data.GUID;
                    ResolverData[i]   = existingData;
                    updated           = true;
                }
            }

            if (!updated)
            {
                ResolverData.Add(data);
            }

            Prune();
        }
 // Register a resolver
 public void RegisterResolver(CrossSceneReferenceSetupData resolver)
 {
     ResolveTargets.Add(resolver);
     ResolveLinks();
 }