add skin color modifier

This commit is contained in:
2025-01-07 21:43:47 +02:00
parent bf4bdfdfd1
commit 090ffeb17d
34 changed files with 532 additions and 15 deletions
@@ -4,6 +4,7 @@ using UMA;
using UMA.CharacterSystem;
using System.Collections.Generic;
using UnityEngine.UI;
using static UnityEngine.Rendering.DebugUI;
public class CharacterDescriptor : MonoBehaviour
{
@@ -79,4 +80,10 @@ public class CharacterDescriptor : MonoBehaviour
_dna["belly"].Set(value);
_avatar.BuildCharacter();
}
public void ChangeSkinColor(Color color)
{
_avatar.SetColor("Skin",color);
_avatar.UpdateColors(true);
}
}
+40
View File
@@ -0,0 +1,40 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ImageColorPicker : MonoBehaviour, IPointerClickHandler
{
public Color selectedColor;
[Serializable]
public class ColorEvent : UnityEvent<Color> { }
public ColorEvent OnColorPicked = new ColorEvent();
public void OnPointerClick(PointerEventData eventData)
{
selectedColor = GetColor(GetPointUVPosition());
OnColorPicked.Invoke(selectedColor);
}
private Color GetColor(Vector2 pos)
{
Texture2D texture = GetComponent<Image>().sprite.texture;
Color selected = texture.GetPixelBilinear(pos.x, pos.y);
selected.a = 1;
return selected;
}
private Vector2 GetPointUVPosition()
{
Vector3[] imageCorners = new Vector3[4];
gameObject.GetComponent<RectTransform>().GetWorldCorners(imageCorners);
float texWidth = imageCorners[2].x - imageCorners[0].x;
float texHeight = imageCorners[2].y - imageCorners[0].y;
float uvX = (Input.mousePosition.x - imageCorners[0].x) / texWidth;
float uvY = (Input.mousePosition.y - imageCorners[0].y) / texHeight;
return new Vector2(uvX, uvY);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2f3eb60cba57441478f606990bede4d9