Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
8.2 kB
7
Indexable
Never
using UnityEngine;
using Random = UnityEngine.Random;

public enum FacialFeatureType
{
    Lips,
    Nose,
    Face
    // Add more facial feature types as needed
}

public enum RaceType
{
    Human,
    Elf,
    Dwarf
    // Add more race types as needed
}

public class CharacterAppearance
{
    private float[] facialFeatures;
    private int hairStyleIndex;
    private Color hairColor;
    private bool hasFacialHair;
    private int facialHairStyleIndex;
    private Color facialHairColor;
    private float height;
    private float bodyType;
    private float size;
    private RaceType race;
    private float breastSize;

    public CharacterAppearance()
    {
        // Initialize default appearance values
        facialFeatures = new float[System.Enum.GetValues(typeof(FacialFeatureType)).Length];
        hairStyleIndex = 0;
        hairColor = Color.black;
        hasFacialHair = false;
        facialHairStyleIndex = 0;
        facialHairColor = Color.black;
        height = 1.0f;
        bodyType = 0.5f;
        size = 1.0f;
        race = RaceType.Human;
        breastSize = 0.5f;
    }

    public float GetFacialFeature(FacialFeatureType featureType)
    {
        return facialFeatures[(int)featureType];
    }

    public void SetFacialFeature(FacialFeatureType featureType, float value)
    {
        facialFeatures[(int)featureType] = value;
    }

    public int GetHairStyle()
    {
        return hairStyleIndex;
    }

    public void SetHairStyle(int styleIndex)
    {
        hairStyleIndex = styleIndex;
    }

    public Color GetHairColor()
    {
        return hairColor;
    }

    public void SetHairColor(Color color)
    {
        hairColor = color;
    }

    public bool HasFacialHair()
    {
        return hasFacialHair;
    }

    public void SetFacialHair(bool hasFacialHair)
    {
        this.hasFacialHair = hasFacialHair;
    }

    public int GetFacialHairStyle()
    {
        return facialHairStyleIndex;
    }

    public void SetFacialHairStyle(int styleIndex)
    {
        facialHairStyleIndex = styleIndex;
    }

    public Color GetFacialHairColor()
    {
        return facialHairColor;
    }

    public void SetFacialHairColor(Color color)
    {
        facialHairColor = color;
    }

    public float GetHeight()
    {
        return height;
    }

    public void SetHeight(float value)
    {
        height = value;
    }

    public float GetBodyType()
    {
        return bodyType;
    }

    public void SetBodyType(float value)
    {
        bodyType = value;
    }

    public float GetSize()
    {
        return size;
    }

    public void SetSize(float value)
    {
        size = value;
    }

    public RaceType GetRace()
    {
        return race;
    }

    public void SetRace(RaceType race)
    {
        this.race = race;
    }

    public float GetBreastSize()
    {
        return breastSize;
    }

    public void SetBreastSize(float value)
    {
        breastSize = value;
    }
}

public class CharacterGenerator : MonoBehaviour
{
    private CharacterAppearance characterAppearance;
    public GameObject characterVisuals; // Reference to the character's visual representation
    public Transform cameraTarget; // Reference to the camera target (character)

    private void Awake()
    {
        characterAppearance = new CharacterAppearance();
    }

    private void Start()
    {
        GenerateCharacter();
    }

    public void GenerateCharacter()
    {
        GenerateFacialFeatures();
        FocusCameraOnCharacter();
        GenerateHair();
        GenerateFacialHair();
        GenerateHeight();
        GenerateBodyType();
        GenerateSize();
        GenerateRace();
        GenerateBreasts();
        ApplyAppearance();
    }

    private void GenerateFacialFeatures()
    {
        float lips = Random.Range(0f, 1f);
        float nose = Random.Range(0f, 1f);
        float face = Random.Range(0f, 1f);

        characterAppearance.SetFacialFeature(FacialFeatureType.Lips, lips);
        characterAppearance.SetFacialFeature(FacialFeatureType.Nose, nose);
        characterAppearance.SetFacialFeature(FacialFeatureType.Face, face);
    }

    private void GenerateHair()
    {
        int hairStyle = Random.Range(0, 5);
        Color hairColor = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));

        characterAppearance.SetHairStyle(hairStyle);
        characterAppearance.SetHairColor(hairColor);
    }

    private void GenerateFacialHair()
    {
        bool hasFacialHair = Random.value > 0.5f;
        int facialHairStyle = Random.Range(0, 3);
        Color facialHairColor = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));

        characterAppearance.SetFacialHair(hasFacialHair);
        characterAppearance.SetFacialHairStyle(facialHairStyle);
        characterAppearance.SetFacialHairColor(facialHairColor);
    }

    private void GenerateHeight()
    {
        float height = Random.Range(0.8f, 1.2f);

        characterAppearance.SetHeight(height);
    }

    private void GenerateBodyType()
    {
        float bodyType = Random.Range(0.0f, 1.0f);

        characterAppearance.SetBodyType(bodyType);
    }

    private void GenerateSize()
    {
        float size = Random.Range(0.8f, 1.2f);

        characterAppearance.SetSize(size);
    }

    private void GenerateRace()
    {
        int raceIndex = Random.Range(0, System.Enum.GetValues(typeof(RaceType)).Length);
        RaceType race = (RaceType)raceIndex;

        characterAppearance.SetRace(race);
    }

    private void GenerateBreasts()
    {
        float breastSize = Random.Range(0.3f, 0.7f);

        characterAppearance.SetBreastSize(breastSize);
    }

    private void ApplyAppearance()
    {
        // Apply the character appearance to the visual elements of the character
        // Implement your own logic here to update the character's visuals based on the appearance data
        Camera.main.transform.LookAt(cameraTarget);

    }

    public void SetFacialFeature(FacialFeatureType featureType, float value)
    {
        characterAppearance.SetFacialFeature(featureType, value);
        ApplyAppearance();
    }

    public void SetHairStyle(int styleIndex)
    {
        characterAppearance.SetHairStyle(styleIndex);
        ApplyAppearance();
    }

    public void SetHairColor(Color color)
    {
        characterAppearance.SetHairColor(color);
        ApplyAppearance();
    }

    public void SetFacialHair(bool hasFacialHair)
    {
        characterAppearance.SetFacialHair(hasFacialHair);
        ApplyAppearance();
    }

    public void SetFacialHairStyle(int styleIndex)
    {
        characterAppearance.SetFacialHairStyle(styleIndex);
        ApplyAppearance();
    }

    public void SetFacialHairColor(Color color)
    {
        characterAppearance.SetFacialHairColor(color);
        ApplyAppearance();
    }

    public void SetHeight(float value)
    {
        characterAppearance.SetHeight(value);
        ApplyAppearance();
    }

    public void SetBodyType(float value)
    {
        characterAppearance.SetBodyType(value);
        ApplyAppearance();
    }

    public void SetSize(float value)
    {
        characterAppearance.SetSize(value);
        ApplyAppearance();
    }

    public void SetRace(RaceType race)
    {
        characterAppearance.SetRace(race);
        ApplyAppearance();
    }

    private void FocusCameraOnCharacter()
    {
        // Update the camera's position and rotation to focus on the character
        Camera.main.transform.position = cameraTarget.position - Camera.main.transform.forward * 5f;
        Camera.main.transform.LookAt(cameraTarget);
    }

    public void SetBreastSize(float value)
    {
        characterAppearance.SetBreastSize(value);
        ApplyAppearance();
    }
}