add menu tool which can enable infinite draw distance

This commit is contained in:
in0finite 2022-01-12 03:25:17 +01:00
parent f92186362d
commit eb5894618a
3 changed files with 60 additions and 1 deletions

View file

@ -0,0 +1,46 @@
using SanAndreasUnity.Behaviours.World;
using SanAndreasUnity.Settings;
using System.Globalization;
using UnityEditor;
using UnityEngine;
namespace SanAndreasUnity.Editor
{
public class InfiniteDrawDistance : MonoBehaviour
{
private const string PrefabPath = "Assets/Prefabs";
[MenuItem(EditorCore.MenuName + "/" + "Enable infinite draw distance")]
static void Init()
{
if (EditorApplication.isPlaying)
{
EditorUtility.DisplayDialog("", "Exit play mode first", "Ok");
return;
}
if (!EditorUtility.DisplayDialog("", "This will modify some prefab parameters " +
"in order to enable infinite draw distance. Low LOD objects will not load.\n\nProceed ?", "Ok", "Cancel"))
return;
GameObject settingsPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(PrefabPath + "/Settings.prefab");
settingsPrefab.GetComponentInChildren<WorldSettings>().overridenMaxDrawDistance = 20000f;
GameObject worldPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(PrefabPath + "/World.prefab");
var cell = worldPrefab.GetComponentInChildren<Cell>();
cell.ignoreLodObjectsWhenInitializing = true;
cell.drawDistanceMultiplier = 20000f;
cell.drawDistancesPerLayers[cell.drawDistancesPerLayers.Length - 1] = 20000f;
cell.maxTimeToUpdatePerFrameMs = 200; // allow 5 FPS
PrefabUtility.SavePrefabAsset(settingsPrefab);
PrefabUtility.SavePrefabAsset(worldPrefab);
PlayerPrefs.SetString(WorldSettings.DrawDistanceSerializationName, 20000f.ToString(CultureInfo.InvariantCulture));
PlayerPrefs.Save();
EditorUtility.DisplayDialog("", "Done", "Ok");
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8d17f260a768ec418bfb32a649d9399
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -10,9 +10,11 @@ namespace SanAndreasUnity.Settings
private float _drawDistanceToApply = 0f;
public const string DrawDistanceSerializationName = "max_draw_distance";
private OptionsWindow.FloatInput m_maxDrawDistanceInput = new OptionsWindow.FloatInput
{
serializationName = "max_draw_distance",
serializationName = DrawDistanceSerializationName,
description = "Max draw distance",
minValue = WorldManager.MinMaxDrawDistance,
maxValue = WorldManager.MaxMaxDrawDistance,