mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
add some world tools
This commit is contained in:
parent
0dc2a4c42d
commit
0ebaef839a
2 changed files with 83 additions and 0 deletions
72
Assets/Scripts/Editor/WorldTools.cs
Normal file
72
Assets/Scripts/Editor/WorldTools.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Editor/WorldTools.cs.meta
Normal file
11
Assets/Scripts/Editor/WorldTools.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1fe5e7d676649843bcb4aa69ceb5ee7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue