Beispiel #1
0
    static IEnumerator PerformLoad(JSONLevelLoader loader, Action <JSONLevelLoader> complete)
    {
        yield return(loader.StartCoroutine(loader.Load(0, Time.timeScale)));

        if (complete != null)
        {
            complete(loader);
        }
    }
Beispiel #2
0
 private void Awake()
 {
     timeScaleAfterLoading = Time.timeScale;
     Current = this;
     if (pixel == null)
     {
         pixel = new Texture2D(1, 1);
     }
 }
 private void Awake()
 {
     timeScaleAfterLoading = Time.timeScale;
     Current = this;
     if (pixel == null)
     {
         pixel = new Texture2D(1, 1);
     }
 }
Beispiel #4
0
 private void Awake()
 {
     this.timeScaleAfterLoading = Time.timeScale;
     JSONLevelLoader.Current    = this;
     if (JSONLevelLoader.pixel == null)
     {
         JSONLevelLoader.pixel = new Texture2D(1, 1);
     }
 }
 void CompletedJSONLoad(JSONLevelLoader loader)
 {
     targetGameObject = loader.Last;
 }
Beispiel #6
0
 void CompletedJSONLoad(JSONLevelLoader loader)
 {
     targetGameObject = loader.Last;
 }
Beispiel #7
0
    public IEnumerator Load(int numberOfFrames, float timeScale = 0f)
    {
        JSONLevelLoader.loadingCount++;
        float oldFixedTime = Time.fixedDeltaTime;

        Time.fixedDeltaTime = 9f;
        for (;;)
        {
            int num;
            numberOfFrames = (num = numberOfFrames) - 1;
            if (num <= 0)
            {
                break;
            }
            yield return(new WaitForEndOfFrame());
        }
        if (LevelSerializer.ShouldCollect && timeScale == 0f)
        {
            GC.Collect();
        }
        LevelSerializer.RaiseProgress("Initializing", 0f);
        if (this.Data.rootObject != null)
        {
            Debug.Log((!this.Data.StoredObjectNames.Any((JSONLevelSerializer.StoredItem sn) => sn.Name == this.$this.Data.rootObject)) ? ("Not found " + this.Data.rootObject) : ("Located " + this.Data.rootObject));
        }
        if (!this.DontDelete)
        {
            foreach (UniqueIdentifier uniqueIdentifier in UniqueIdentifier.AllIdentifiers.Where(delegate(UniqueIdentifier n)
            {
                JSONLevelLoader $this = this.$this;
                return(this.$this.Data.StoredObjectNames.All((JSONLevelSerializer.StoredItem sn) => sn.Name != n.Id));
            }).ToList <UniqueIdentifier>())
            {
                try
                {
                    bool flag = false;
                    JSONLevelLoader.OnDestroyObject(uniqueIdentifier.gameObject, ref flag);
                    if (!flag)
                    {
                        UnityEngine.Object.Destroy(uniqueIdentifier.gameObject);
                    }
                }
                catch (Exception ex)
                {
                    Radical.LogWarning("Problem destroying object " + uniqueIdentifier.name + " " + ex.ToString());
                }
            }
        }
        List <UniqueIdentifier> flaggedObjects = new List <UniqueIdentifier>();

        LevelSerializer.RaiseProgress("Initializing", 0.25f);
        Vector3 position = new Vector3(0f, 2000f, 2000f);

        foreach (JSONLevelSerializer.StoredItem storedItem in from c in this.Data.StoredObjectNames
                 where UniqueIdentifier.GetByName(c.Name) == null
                 select c)
        {
            try
            {
                if (storedItem.createEmptyObject || storedItem.ClassId == null || !LevelSerializer.AllPrefabs.ContainsKey(storedItem.ClassId))
                {
                    storedItem.GameObject = new GameObject("CreatedObject");
                    storedItem.GameObject.transform.position = position;
                    EmptyObjectIdentifier emptyObjectIdentifier = storedItem.GameObject.AddComponent <EmptyObjectIdentifier>();
                    storedItem.GameObject.AddComponent <StoreMaterials>();
                    storedItem.GameObject.AddComponent <StoreMesh>();
                    emptyObjectIdentifier.IsDeserializing = true;
                    emptyObjectIdentifier.Id = storedItem.Name;
                    if (emptyObjectIdentifier.Id == this.Data.rootObject)
                    {
                        Debug.Log("Set the root object on an empty");
                    }
                    flaggedObjects.Add(emptyObjectIdentifier);
                }
                else
                {
                    GameObject gameObject = LevelSerializer.AllPrefabs[storedItem.ClassId];
                    bool       flag2      = false;
                    JSONLevelLoader.CreateGameObject(gameObject, ref flag2);
                    if (flag2)
                    {
                        Debug.LogWarning("Cancelled");
                        continue;
                    }
                    UniqueIdentifier[] componentsInChildren = gameObject.GetComponentsInChildren <UniqueIdentifier>();
                    foreach (UniqueIdentifier uniqueIdentifier2 in componentsInChildren)
                    {
                        uniqueIdentifier2.IsDeserializing = true;
                    }
                    storedItem.GameObject = UnityEngine.Object.Instantiate <GameObject>(gameObject, position, Quaternion.identity);
                    storedItem.GameObject.GetComponent <UniqueIdentifier>().Id = storedItem.Name;
                    if (storedItem.GameObject.GetComponent <UniqueIdentifier>().Id == this.Data.rootObject)
                    {
                        Debug.Log("Set the root object on a prefab");
                    }
                    foreach (UniqueIdentifier uniqueIdentifier3 in componentsInChildren)
                    {
                        uniqueIdentifier3.IsDeserializing = false;
                    }
                    flaggedObjects.AddRange(storedItem.GameObject.GetComponentsInChildren <UniqueIdentifier>());
                }
                position += Vector3.right * 50f;
                storedItem.GameObject.GetComponent <UniqueIdentifier>().Id = storedItem.Name;
                storedItem.GameObject.name = storedItem.GameObjectName;
                if (storedItem.ChildIds.Count > 0)
                {
                    List <UniqueIdentifier> list4 = storedItem.GameObject.GetComponentsInChildren <UniqueIdentifier>().ToList <UniqueIdentifier>();
                    int num2 = 0;
                    while (num2 < list4.Count && num2 < storedItem.ChildIds.Count)
                    {
                        list4[num2].Id = storedItem.ChildIds[num2];
                        num2++;
                    }
                }
                if (storedItem.Children.Count > 0)
                {
                    List <StoreInformation> componentsInChildrenWithClause = JSONLevelSerializer.GetComponentsInChildrenWithClause(storedItem.GameObject);
                    this._indexDictionary.Clear();
                    foreach (StoreInformation storeInformation in componentsInChildrenWithClause)
                    {
                        if (storedItem.Children.ContainsKey(storeInformation.ClassId))
                        {
                            if (!this._indexDictionary.ContainsKey(storeInformation.ClassId))
                            {
                                this._indexDictionary[storeInformation.ClassId] = 0;
                            }
                            storeInformation.Id = storedItem.Children[storeInformation.ClassId][this._indexDictionary[storeInformation.ClassId]];
                            this._indexDictionary[storeInformation.ClassId] = this._indexDictionary[storeInformation.ClassId] + 1;
                        }
                    }
                }
            }
            catch (Exception ex2)
            {
                Debug.LogError(ex2);
                Radical.LogWarning(string.Concat(new object[]
                {
                    "Problem creating an object ",
                    storedItem.GameObjectName,
                    " with classID ",
                    storedItem.ClassId,
                    " ",
                    ex2
                }));
            }
        }
        HashSet <GameObject> loadedGameObjects = new HashSet <GameObject>();

        LevelSerializer.RaiseProgress("Initializing", 0.75f);
        foreach (JSONLevelSerializer.StoredItem storedItem2 in this.Data.StoredObjectNames)
        {
            GameObject byName = UniqueIdentifier.GetByName(storedItem2.Name);
            if (byName == null)
            {
                Radical.LogNow("Could not find " + storedItem2.GameObjectName + " " + storedItem2.Name, new object[0]);
            }
            else
            {
                loadedGameObjects.Add(byName);
                if (storedItem2.Components != null && storedItem2.Components.Count > 0)
                {
                    List <Component> list2 = (from c in byName.GetComponents <Component>()
                                              where !typeof(UniqueIdentifier).IsAssignableFrom(c.GetType())
                                              select c).ToList <Component>();
                    foreach (Component component in list2)
                    {
                        if (!storedItem2.Components.ContainsKey(component.GetType().FullName))
                        {
                            UnityEngine.Object.Destroy(component);
                        }
                    }
                }
                JSONLevelLoader.SetActive(byName, storedItem2.Active);
                if (storedItem2.setExtraData)
                {
                    byName.layer = storedItem2.layer;
                    byName.tag   = storedItem2.tag;
                }
            }
        }
        LevelSerializer.RaiseProgress("Initializing", 0.85f);
        if (this.rootObject != null && UniqueIdentifier.GetByName(this.Data.rootObject) == null)
        {
            Debug.Log("No root object has been configured");
        }
        foreach (JSONLevelSerializer.StoredItem storedItem3 in from c in this.Data.StoredObjectNames
                 where !string.IsNullOrEmpty(c.ParentName)
                 select c)
        {
            GameObject byName2 = UniqueIdentifier.GetByName(storedItem3.ParentName);
            GameObject byName3 = UniqueIdentifier.GetByName(storedItem3.Name);
            if (byName3 != null && byName2 != null)
            {
                byName3.transform.parent = byName2.transform;
            }
        }
        Time.timeScale = timeScale;
        LevelSerializer.RaiseProgress("Initializing", 1f);
        using (new Radical.Logging())
        {
            int currentProgress = 0;
            UnitySerializer.FinalProcess process;
            using (new UnitySerializer.ForceJSON())
            {
                using (new UnitySerializer.SerializationSplitScope())
                {
                    using (new UnitySerializer.SerializationScope())
                    {
                        foreach (var <> __AnonType in this.Data.StoredItems.GroupBy((JSONLevelSerializer.StoredData i) => i.Name, (string name, IEnumerable <JSONLevelSerializer.StoredData> cps) => new
                        {
                            Name = name,
                            Components = (from cp in cps
                                          where cp.Name == name
                                          select cp).GroupBy((JSONLevelSerializer.StoredData cp) => cp.Type, (string type, IEnumerable <JSONLevelSerializer.StoredData> components) => new
                            {
                                Type = type,
                                List = components.ToList <JSONLevelSerializer.StoredData>()
                            }).ToList()
                        }))
                        {
                            GameObject byName4 = UniqueIdentifier.GetByName(< > __AnonType.Name);
                            if (byName4 == null)
                            {
                                Radical.LogWarning(< > __AnonType.Name + " was null");
                            }
                            else
                            {
                                foreach (var <> __AnonType2 in < > __AnonType.Components)
                                {
                                    try
                                    {
                                        LevelSerializer.RaiseProgress("Loading", (float)(++currentProgress) / (float)this.Data.StoredItems.Count);
                                        Type type = UnitySerializer.GetTypeEx(< > __AnonType2.Type);
                                        if (type != null)
                                        {
                                            this.Last = byName4;
                                            bool flag3 = false;
                                            JSONLevelLoader.LoadData(byName4, ref flag3);
                                            JSONLevelLoader.LoadComponent(byName4, type.Name, ref flag3);
                                            if (!flag3)
                                            {
                                                List <Component> list = (from c in byName4.GetComponents(type)
                                                                         where c.GetType() == type
                                                                         select c).ToList <Component>();
                                                while (list.Count > < > __AnonType2.List.Count)
                                                {
                                                    UnityEngine.Object.DestroyImmediate(list.Last <Component>());
                                                    list.Remove(list.Last <Component>());
                                                }
                                                if (type == typeof(NavMeshAgent))
                                                {
                                                    < > __AnonType2 <string, List <JSONLevelSerializer.StoredData> > cp1 = < > __AnonType2;
Beispiel #8
0
 private void Awake()
 {
     this.timeScaleAfterLoading = Time.timeScale;
     JSONLevelLoader.Current = this;
     if (JSONLevelLoader.pixel == null)
     {
         JSONLevelLoader.pixel = new Texture2D(1, 1);
     }
 }