<Unity> pinch test

The project needs to pinch the body to do a simple test, just to test the effect.
A new set of scale bones is added under the original bones in the body without formal use of maya, named "%s_skin"%old ​​bones.
insert image description here
Scale a set of limit values ​​according to each part of the body in maya to make a table.
insert image description here
Export the body skeleton FBX into unity and replace the previous prefab.
Simply create the required slider. Because there are fat and thin, the parameters are set to a minimum value of 0 and a maximum value of 2, V = 1

insert image description here
insert image description here
Then prepare the script

Take the hip bone as an example


```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class hips_Knead_test : MonoBehaviour
{
    public Slider Hips_Slider;
    [SerializeField]
    private Transform Hip_L_skin;
    public Transform Hip_L
    {
        get { return Hip_L_skin; }
    }
    [SerializeField]
    private Transform Hip_R_skin;
    public Transform Hip_R
    {
        get { return Hip_R_skin; }
    }

    [SerializeField]
    private Transform HipPart1_L_skin;
    public Transform HipPart1_L
    {
        get { return HipPart1_L_skin; }
    }
    [SerializeField]
    private Transform HipPart1_R_skin;
    public Transform HipPart1_R
    {
        get { return HipPart1_R_skin; }
    }
    [SerializeField]
    private Transform HipPart2_L_skin;
    public Transform HipPart2_L
    {
        get { return HipPart2_L_skin; }
    }
    [SerializeField]
    private Transform HipPart2_R_skin;
    public Transform HipPart2_R
    {
        get { return HipPart2_R_skin; }
    }
    [ContextMenu("自动添加绑定关系")]
    void SetParameters()
    {
        //Debug.Log(GameObject.Find("pre_Character 1"));
        Hip_L_skin = transform.Find("main/peopleFBX_rig/Main_M/Root_M/Hip_L/Hip_L_skin");
        Hip_R_skin = transform.Find("main/peopleFBX_rig/Main_M/Root_M/Hip_R/Hip_R_skin");

        HipPart1_L_skin = transform.Find("main/peopleFBX_rig/Main_M/Root_M/Hip_L/HipPart1_L/HipPart1_L_skin");
        HipPart1_R_skin = transform.Find("main/peopleFBX_rig/Main_M/Root_M/Hip_R/HipPart1_R/HipPart1_R_skin");

        HipPart2_L_skin = transform.Find("main/peopleFBX_rig/Main_M/Root_M/Hip_L/HipPart1_L/HipPart2_L/HipPart2_L_skin");
        HipPart2_R_skin = transform.Find("main/peopleFBX_rig/Main_M/Root_M/Hip_R/HipPart1_R/HipPart2_R/HipPart2_R_skin");
    }
    void Reset()
    {

        //Debug.Log(GameObject.Find("neck_Slider"));
        SetParameters();
    }

    void Start()
    {

    }
    void Update()
    {

    }

    public void HipsSliderChanged()
    {
        if (Hips_Slider.value == 1.0f)
        {
            //aa1_skin.transform.localScale(1, slider.value, 1);
            Hip_L_skin.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            Hip_R_skin.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            HipPart1_L_skin.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            HipPart1_R_skin.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            HipPart2_L_skin.localScale = new Vector3(1.0f, 1.0f, 1.0f);
            HipPart2_R_skin.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        }
        else if (Hips_Slider.value <= 1.0f)
        {
            //aa1_skin.transform.localScale(1, slider.value, 1);
            Hip_L_skin.localScale = new Vector3(1.0f, Hips_Slider.value * (1.0f - 0.3f) + 0.3f, Hips_Slider.value * (1.0f - 0.4f) + 0.4f);
            Hip_R_skin.localScale = new Vector3(1.0f, Hips_Slider.value * (1.0f - 0.3f) + 0.3f, Hips_Slider.value * (1.0f - 0.4f) + 0.4f);
            HipPart1_L_skin.localScale = new Vector3(1.0f, Hips_Slider.value * (1.0f - 0.3f) + 0.3f, Hips_Slider.value * (1.0f - 0.4f) + 0.4f);
            HipPart1_R_skin.localScale = new Vector3(1.0f, Hips_Slider.value * (1.0f - 0.3f) + 0.3f, Hips_Slider.value * (1.0f - 0.4f) + 0.4f);
            HipPart2_L_skin.localScale = new Vector3(1.0f, Hips_Slider.value * (1.0f - 0.4f) + 0.4f, Hips_Slider.value * (1.0f - 0.5f) + 0.5f);
            HipPart2_R_skin.localScale = new Vector3(1.0f, Hips_Slider.value * (1.0f - 0.4f) + 0.4f, Hips_Slider.value * (1.0f - 0.5f) + 0.5f);
        }
        else if (Hips_Slider.value >= 1.0f)
        {
            //aa1_skin.transform.localScale(1, slider.value, 1);
            Hip_L_skin.localScale = new Vector3(1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f);
            Hip_R_skin.localScale = new Vector3(1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f);
            HipPart1_L_skin.localScale = new Vector3(1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f, (Hips_Slider.value - 1) * (1.5f - 1.0f) + 1.0f);
            HipPart1_R_skin.localScale = new Vector3(1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f, (Hips_Slider.value - 1) * (1.5f - 1.0f) + 1.0f);
            HipPart2_L_skin.localScale = new Vector3(1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f, (Hips_Slider.value - 1) * (1.5f - 1.0f) + 1.0f);
            HipPart2_R_skin.localScale = new Vector3(1.0f, (Hips_Slider.value - 1) * (1.2f - 1.0f) + 1.0f, (Hips_Slider.value - 1) * (1.5f - 1.0f) + 1.0f);
        }


    }



}

Set the parameters of the slider to hang the prefab on the prefab of the character. In the script, find the execution script. Here it should be the HipsSliderChanged() script. Hang the corresponding bone position on the prefab (if the path is set correctly, right-click to automatically hang the bone) and then run the slide to see the changes
insert image description here
you
insert image description hereadjusted

Added a new hanging point test in the scene
insert image description here

Guess you like

Origin blog.csdn.net/sunGZ123456/article/details/123924067