add some world tools

This commit is contained in:
in0finite 2022-01-29 05:54:20 +01:00
parent 0dc2a4c42d
commit 0ebaef839a
2 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using SanAndreasUnity.Behaviours.World;
using SanAndreasUnity.Utilities;
using SanAndreasUnity.Behaviours;
using System.Linq;
namespace SanAndreasUnity.Editor
{
public class WorldTools
{
private static IEnumerable<Transform> GetAllWorldObjects()
{
var world = Cell.Singleton;
if (world == null)
return Enumerable.Empty<Transform>();
return world.transform.GetFirstLevelChildren();
}
[MenuItem(EditorCore.MenuName + "/World/Select all world objects")]
static void SelectAllWorldObjects()
{
Object[] objectsToSelect = GetAllWorldObjects()
.Select(_ => (Object)_)
.ToArrayOfLength(Cell.Singleton.transform.childCount);
if (objectsToSelect.Length == 0)
return;
Selection.objects = objectsToSelect;
}
[MenuItem(EditorCore.MenuName + "/World/Enable all world objects")]
static void EnableAllWorldObjects()
{
GetAllWorldObjects().ForEach(_ => _.gameObject.SetActive(true));
}
[MenuItem(EditorCore.MenuName + "/World/Disable all world objects")]
static void DisableAllWorldObjects()
{
GetAllWorldObjects().ForEach(_ => _.gameObject.SetActive(false));
}
private static IEnumerable<Transform> GetAllWorldObjectsCloseToCamera()
{
SceneView lastActiveSceneView = SceneView.lastActiveSceneView;
if (lastActiveSceneView == null)
return Enumerable.Empty<Transform>();
Vector2 pos = lastActiveSceneView.camera.transform.position.ToVec2WithXAndZ();
return GetAllWorldObjects()
.Where(_ => Vector2.Distance(_.transform.position.ToVec2WithXAndZ(), pos) < 600f);
}
[MenuItem(EditorCore.MenuName + "/World/Enable all world objects close to camera")]
static void EnableAllWorldObjectsCloseToCamera()
{
GetAllWorldObjectsCloseToCamera().ForEach(_ => _.gameObject.SetActive(true));
}
[MenuItem(EditorCore.MenuName + "/World/Disable all world objects close to camera")]
static void DisableAllWorldObjectsCloseToCamera()
{
GetAllWorldObjectsCloseToCamera().ForEach(_ => _.gameObject.SetActive(false));
}
}
}

View file

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