initial upload
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Extensions
|
||||
{
|
||||
public static class GameObjectExtension
|
||||
{
|
||||
public static T GetOrAddComponent<T>(this GameObject gameObject) where T : Component
|
||||
{
|
||||
return gameObject.TryGetComponent(out T t) ? t : gameObject.AddComponent<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60b5cd27ba404cd42a0608590d0d6b96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Convai/Scripts/Runtime/Extensions/ImageExtensions.cs
Normal file
14
Assets/Convai/Scripts/Runtime/Extensions/ImageExtensions.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Extensions
|
||||
{
|
||||
public static class ImageExtensions
|
||||
{
|
||||
public static Image WithColorValue(this Image image, float? r = null, float? g = null, float? b = null, float? a = null)
|
||||
{
|
||||
image.color = new Color(r ?? image.color.r, g ?? image.color.g, b ?? image.color.b, a ?? image.color.a);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bde7d53e94e232744aa2b649f44847f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Extensions
|
||||
{
|
||||
public static class SkinnedMeshRendererExtension
|
||||
{
|
||||
public static void SetBlendShapeWeightInterpolate(this SkinnedMeshRenderer renderer, int index, float value, float weight)
|
||||
{
|
||||
renderer.SetBlendShapeWeight(index, Mathf.Lerp(renderer.GetBlendShapeWeight(index), value, weight));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3db3cb9745d4844fa122272c2f7b11d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,32 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Extensions
|
||||
{
|
||||
public static class TransformExtensions
|
||||
{
|
||||
public static T GetComponentOnChildWithMatchingRegex<T>(this Transform transform, string regexStringPattern)
|
||||
{
|
||||
// Initialize a variable to store the found SkinnedMeshRenderer.
|
||||
T targetComponent = default;
|
||||
|
||||
// Define a regular expression pattern for matching child object names.
|
||||
Regex regexPattern = new(regexStringPattern);
|
||||
|
||||
// Iterate through each child of the parentTransform.
|
||||
foreach (Transform child in transform)
|
||||
// Check if the child's name matches the regex pattern.
|
||||
if (regexPattern.IsMatch(child.name))
|
||||
{
|
||||
// If a match is found, get the SkinnedMeshRenderer component of the child.
|
||||
targetComponent = child.GetComponent<T>();
|
||||
|
||||
// If a SkinnedMeshRenderer is found, break out of the loop.
|
||||
if (targetComponent != null) break;
|
||||
}
|
||||
|
||||
// Return the found SkinnedMeshRenderer (or null if none is found).
|
||||
return targetComponent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ca02589b1584674caf2cd1ff39cdfc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user