【问题标题】:How to save and load environment in a survival type game?如何在生存类游戏中保存和加载环境?
【发布时间】:2020-10-16 18:53:38
【问题描述】:

我正在开发一款生存类型的游戏,在这个游戏中,整个地图是手动制作的,并分成多个 512x512 大小的块/地形。根据玩家位置加载和卸载块。

我面临的问题是保存和加载块环境。在游戏中,玩家可以砍伐树木并重新种植。

考虑到不知道块中的位置和数量,我不能使用池系统,如果我在加载块时实例化所有树,我可能会调用数千个实例化调用,这将杀死表演。

我应该如何解决这个问题,有什么好的解决方案?谢谢

【问题讨论】:

    标签: c# performance unity3d tree environment


    【解决方案1】:

    好吧,我刚刚找到了解决方案。 可寻址对象。使用Addressables.LoadAssetAsyncAddressables.InstantiateAsync

    我做了一个简单的测试,我创建了 5000 个复杂的网格并获得了零延迟。真是难以置信。

    这是代码,如果有人感兴趣的话。

    using System.Collections;
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    using SystemRan = System.Random;
    
    public class Massinstantiation : MonoBehaviour
    {
        const string location = "Assets/TestObject.prefab";
    
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                StartCoroutine(Instantiate());
            }
        }
    
        public IEnumerator Instantiate()
        {
            var loadAsset = Addressables.LoadAssetAsync<GameObject>(location);
    
            yield return loadAsset;
    
            if (loadAsset.Status == AsyncOperationStatus.Succeeded)
            {
                SystemRan rand = new SystemRan();
                for (int i = 0; i < 5000; i++)
                {
                    var obj = Addressables.InstantiateAsync(location, new Vector3(rand.Next(-250, 250), 0, rand.Next(-250, 250)), Quaternion.identity, null);
                    yield return obj.IsDone;
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多