Ejemplo n.º 1
0
    private void ParseScript()
    {
        ScriptParser scriptParser = new ScriptParser();

        scriptParser.Parse("StaticBatching/StaticBatching.txt", true);
        for (int i = 0; i < scriptParser.GetKeysCount(); i++)
        {
            Key key = scriptParser.GetKey(i);
            if (key.GetName() == "Mesh" && !this.m_ReplaceMap.ContainsKey(key.GetVariable(0).SValue))
            {
                StaticObjectsReplace staticObjectsReplace = new StaticObjectsReplace();
                staticObjectsReplace.m_PrefabName = key.GetVariable(1).SValue;
                staticObjectsReplace.m_Prefab     = GreenHellGame.Instance.GetPrefab(staticObjectsReplace.m_PrefabName);
                DebugUtils.Assert(staticObjectsReplace.m_Prefab != null, "[StaticObjectsManager:ParseScript] Can't find prefab - " + staticObjectsReplace.m_PrefabName, true, DebugUtils.AssertType.Info);
                this.m_ReplaceMap.Add(key.GetVariable(0).SValue, staticObjectsReplace);
            }
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (LoadingScreen.Get().m_Active)
        {
            return;
        }
        List <StaticObjectClass> objectsInRadius = this.m_QuadTree.GetObjectsInRadius(Player.Get().gameObject.transform.position, 10f, false);

        for (int i = 0; i < objectsInRadius.Count; i++)
        {
            StaticObjectClass staticObjectClass = objectsInRadius[i];
            if (staticObjectClass.m_GameObject.activeSelf && staticObjectClass.m_State != 1 && !this.m_ObjectsRemovedFromStatic.Contains(staticObjectClass))
            {
                StaticObjectsReplace staticObjectsReplace = null;
                if (this.m_ReplaceMap.TryGetValue(staticObjectClass.m_GameObject.name, out staticObjectsReplace))
                {
                    staticObjectClass.m_GameObject.SetActive(false);
                    this.m_ObjectsRemovedFromStatic.Add(staticObjectClass);
                    GameObject gameObject;
                    if (this.m_EnablePooling)
                    {
                        if (this.m_Pool[staticObjectsReplace.m_PrefabName].Count > 0)
                        {
                            gameObject = this.m_Pool[staticObjectsReplace.m_PrefabName].ElementAt(0);
                            this.m_Pool[staticObjectsReplace.m_PrefabName].RemoveAt(0);
                        }
                        else
                        {
                            gameObject = UnityEngine.Object.Instantiate <GameObject>(staticObjectsReplace.m_Prefab);
                            this.m_TempItemList.Clear();
                            gameObject.GetComponents <Item>(this.m_TempItemList);
                            if (this.m_TempItemList.Count > 0)
                            {
                                this.m_TempItemList[0].m_CanSaveNotTriggered = false;
                            }
                        }
                        gameObject.SetActive(true);
                    }
                    else
                    {
                        gameObject = UnityEngine.Object.Instantiate <GameObject>(staticObjectsReplace.m_Prefab);
                        this.m_TempItemList.Clear();
                        gameObject.GetComponents <Item>(this.m_TempItemList);
                        if (this.m_TempItemList.Count > 0)
                        {
                            this.m_TempItemList[0].m_CanSaveNotTriggered = false;
                        }
                    }
                    this.m_ReplacedMap.Add(staticObjectClass, gameObject);
                    gameObject.transform.position   = staticObjectClass.m_GameObject.transform.parent.position;
                    gameObject.transform.rotation   = staticObjectClass.m_GameObject.transform.parent.rotation;
                    gameObject.transform.localScale = staticObjectClass.m_GameObject.transform.parent.localScale;
                    Item component = gameObject.GetComponent <Item>();
                    if (component)
                    {
                        component.Initialize(false);
                    }
                }
            }
        }
        int j = 0;

        while (j < this.m_ObjectsRemovedFromStatic.Count)
        {
            StaticObjectClass staticObjectClass2 = this.m_ObjectsRemovedFromStatic[j];
            if (!objectsInRadius.Contains(staticObjectClass2))
            {
                GameObject gameObject2 = null;
                if (this.m_ReplacedMap.TryGetValue(staticObjectClass2, out gameObject2))
                {
                    if (gameObject2 != null)
                    {
                        if (this.m_EnablePooling)
                        {
                            gameObject2.transform.position = this.m_PoolPosition;
                            gameObject2.SetActive(false);
                            this.m_Pool[this.m_ReplaceMap[staticObjectClass2.m_GameObject.name].m_PrefabName].Add(gameObject2);
                            staticObjectClass2.m_GameObject.SetActive(true);
                        }
                        else
                        {
                            UnityEngine.Object.Destroy(gameObject2);
                            if (staticObjectClass2.m_GameObject == null)
                            {
                                this.m_ObjectsRemovedFromStatic.Remove(staticObjectClass2);
                                continue;
                            }
                            staticObjectClass2.m_GameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        if (staticObjectClass2.m_GameObject == null)
                        {
                            this.m_ObjectsRemovedFromStatic.Remove(staticObjectClass2);
                            continue;
                        }
                        staticObjectClass2.m_State = 1;
                        if (staticObjectClass2.m_GameObject.transform.parent != null)
                        {
                            staticObjectClass2.m_GameObject.transform.parent.gameObject.SetActive(false);
                        }
                    }
                    this.m_ReplacedMap.Remove(staticObjectClass2);
                    this.m_ObjectsRemovedFromStatic.Remove(staticObjectClass2);
                }
                else
                {
                    j++;
                }
            }
            else
            {
                j++;
            }
        }
        if (this.m_ReplacedMap.Count > 0)
        {
            Dictionary <StaticObjectClass, GameObject> .Enumerator enumerator = this.m_ReplacedMap.GetEnumerator();
            if (enumerator.MoveNext())
            {
                KeyValuePair <StaticObjectClass, GameObject> keyValuePair = enumerator.Current;
                if (keyValuePair.Key.m_GameObject == null)
                {
                    Dictionary <StaticObjectClass, GameObject> replacedMap = this.m_ReplacedMap;
                    keyValuePair = enumerator.Current;
                    replacedMap.Remove(keyValuePair.Key);
                }
            }
            enumerator.Dispose();
        }
    }