1
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
"GUID:045a42f233e479d41adc32d02b99631e",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3"
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:296866320aab85a42a0403bf684bac59"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
95
Src/Unity/Scripts/Scenes/Editor/MaterialPaletteWindow.cs
Normal file
95
Src/Unity/Scripts/Scenes/Editor/MaterialPaletteWindow.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class MaterialPaletteWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Scenes/Material Palette")]
|
||||
public static void Open()
|
||||
{
|
||||
GetWindow<MaterialPaletteWindow>().Show();
|
||||
}
|
||||
|
||||
private Button buildButton;
|
||||
private Label _titleLabel;
|
||||
private VisualElement _container;
|
||||
|
||||
private MeshRenderer[] _renderers=Array.Empty<MeshRenderer>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
UnityEditor.Selection.selectionChanged += OnSelectionChanged;
|
||||
|
||||
rootVisualElement.Clear();
|
||||
_titleLabel = rootVisualElement.Create<Label>();
|
||||
_container = rootVisualElement.Create<VisualElement>();
|
||||
|
||||
_titleLabel.text = "选择一个物体";
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UnityEditor.Selection.selectionChanged -= OnSelectionChanged;
|
||||
}
|
||||
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
var actives = UnityEditor.Selection.gameObjects;
|
||||
|
||||
_container.Clear();
|
||||
|
||||
_renderers = actives.SelectMany(x => x.GetComponentsInChildren<MeshRenderer>()).ToArray();
|
||||
|
||||
var materials = _renderers.SelectMany(x => x.sharedMaterials).Distinct().ToArray();
|
||||
|
||||
_titleLabel.text = actives is not {Length:0} ?$"选择了{actives.Length }个物体,{materials.Length}个材质" : "未选择物体";
|
||||
|
||||
foreach (var material in materials)
|
||||
{
|
||||
var filed = _container.Create<ObjectField>();
|
||||
filed.label = material.name;
|
||||
filed.objectType = typeof(Material);
|
||||
filed.allowSceneObjects = false;
|
||||
filed.value = material;
|
||||
filed.RegisterValueChangedCallback(OnChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnChanged(ChangeEvent<Object> evt)
|
||||
{
|
||||
if(evt.newValue is not Material value) return;
|
||||
var list = new List<Object>();
|
||||
foreach (var renderer in _renderers)
|
||||
{
|
||||
var sharedMaterials = renderer.sharedMaterials;
|
||||
var isDirty = false;
|
||||
for (var i = 0; i < sharedMaterials.Length; i++)
|
||||
{
|
||||
var current = sharedMaterials[i];
|
||||
if(current != evt.previousValue) continue;
|
||||
sharedMaterials[i] = value;
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
if (!isDirty) continue;
|
||||
renderer.sharedMaterials = sharedMaterials;
|
||||
list.Add(renderer);
|
||||
EditorUtility.SetDirty(renderer);
|
||||
}
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f86a9770a998a44fb9d7e115249a507
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit.IO;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -105,6 +107,8 @@ namespace BITKit.SceneManagement
|
||||
private readonly Dictionary<string, Scene> LoadedObjects = new();
|
||||
private CancellationToken _cancellationToken;
|
||||
|
||||
private readonly ConcurrentDictionary<string,ResourcePackage> _packages=new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
@@ -126,8 +130,25 @@ namespace BITKit.SceneManagement
|
||||
|
||||
public string[] GetScenes(params string[] tags)
|
||||
{
|
||||
var infos = YooAssets.GetAssetInfos(tags);
|
||||
return infos.Where(x=>x.Address.Split("_")[0] is "Maps").Select(x=>x.Address).ToArray();
|
||||
try
|
||||
{
|
||||
_packages.Clear();
|
||||
var list = new List<string>();
|
||||
foreach (var package in YooAssetUtils.RegisteredResourcePackages)
|
||||
{
|
||||
foreach (var assetInfo in package.GetAssetInfos(tags))
|
||||
{
|
||||
list.Add(assetInfo.Address);
|
||||
_packages.TryAdd(assetInfo.Address,package);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Warning<ISceneService>(JsonHelper.Get(YooAssetUtils.RegisteredPackages) );
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask LoadSceneAsync(string sceneName, CancellationToken cancellationToken,
|
||||
@@ -166,7 +187,10 @@ namespace BITKit.SceneManagement
|
||||
// }
|
||||
|
||||
var sceneMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
|
||||
var handle = YooAssets.LoadSceneAsync(sceneName, sceneMode);
|
||||
|
||||
var package = _packages[sceneName];
|
||||
|
||||
var handle = package.LoadSceneAsync(sceneName, sceneMode);
|
||||
while (handle.IsDone is false)
|
||||
{
|
||||
var progress = handle.Progress;
|
||||
@@ -176,7 +200,7 @@ namespace BITKit.SceneManagement
|
||||
LoadedObjects.Add(sceneName, handle.SceneObject);
|
||||
|
||||
OnSceneLoadProgress?.Invoke(sceneName, 1);
|
||||
await Task.Delay(100, cancellationToken);
|
||||
await Task.Delay(384, cancellationToken);
|
||||
OnSceneLoaded?.Invoke(sceneName);
|
||||
stopwatchWatcher.Stop();
|
||||
// if (activateOnLoad is false)
|
||||
|
Reference in New Issue
Block a user