update coffee.internal
parent
a9c2b19edf
commit
d3c6c63a07
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Profiling;
|
using UnityEngine.Profiling;
|
||||||
|
@ -11,6 +12,48 @@ namespace Coffee.UIParticleInternal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class ComponentExtensions
|
internal static class ComponentExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get components in children of a specific type in the hierarchy of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static T[] GetComponentsInChildren<T>(this Component self, int depth)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
var results = ListPool<T>.Rent();
|
||||||
|
self.GetComponentsInChildren_Internal(results, depth);
|
||||||
|
var array = results.ToArray();
|
||||||
|
ListPool<T>.Return(ref results);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get components in children of a specific type in the hierarchy of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static void GetComponentsInChildren<T>(this Component self, List<T> results, int depth)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
results.Clear();
|
||||||
|
self.GetComponentsInChildren_Internal(results, depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GetComponentsInChildren_Internal<T>(this Component self, List<T> results, int depth)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
if (!self || results == null || depth < 0) return;
|
||||||
|
|
||||||
|
var tr = self.transform;
|
||||||
|
if (tr.TryGetComponent<T>(out var t))
|
||||||
|
{
|
||||||
|
results.Add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (depth - 1 < 0) return;
|
||||||
|
var childCount = tr.childCount;
|
||||||
|
for (var i = 0; i < childCount; i++)
|
||||||
|
{
|
||||||
|
tr.GetChild(i).GetComponentsInChildren(results, depth - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get or add a component of a specific type to a GameObject.
|
/// Get or add a component of a specific type to a GameObject.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Conditional = System.Diagnostics.ConditionalAttribute;
|
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
#if ENABLE_COFFEE_LOGGER
|
#if ENABLE_COFFEE_LOGGER
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
#else
|
||||||
|
using Conditional = System.Diagnostics.ConditionalAttribute;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Coffee.UIParticleInternal
|
namespace Coffee.UIParticleInternal
|
||||||
|
|
|
@ -42,6 +42,34 @@ namespace Coffee.UIParticleInternal
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static void Get(Hash128 hash, ref Material material, string shaderName)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Get");
|
||||||
|
s_Repository.Get(hash, ref material, x => new Material(Shader.Find(x))
|
||||||
|
{
|
||||||
|
hideFlags = HideFlags.DontSave | HideFlags.NotEditable
|
||||||
|
}, shaderName);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static void Get(Hash128 hash, ref Material material, string shaderName, string[] keywords)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Get");
|
||||||
|
s_Repository.Get(hash, ref material, x => new Material(Shader.Find(x.shaderName))
|
||||||
|
{
|
||||||
|
hideFlags = HideFlags.DontSave | HideFlags.NotEditable,
|
||||||
|
shaderKeywords = x.keywords
|
||||||
|
}, (shaderName, keywords));
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds or retrieves a cached material based on the hash.
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue