using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///


/// Transform提供了 查找(父,根,子(索引/名称))变换组件功能, 改变位置,角度,大小功能
///

public class TransformDemo : MonoBehaviour
{
public Transform tf;
private void OnGUI()
{
//查找变换组件****
if (GUILayout .Button ("foreach - transform"))
{

        foreach (Transform  child in transform )
        {
            //child 为 每个子物体的组件
            print(child.name);
        }
    }
    if (GUILayout.Button("root"))
    {
        //获取根物体变换组件
        Transform rootTF = this.transform.root;
    }
    if (GUILayout.Button("parent"))
    {
        //获取父物体变换组件
        Transform parentTF = this.transform.parent ;
    }
    if (GUILayout.Button("Setparent"))
    {
        //设置父物体
        //当前物体视为WordPosition
        //this.transform.SetParent(tf,ture);

        //当前物体的位置视为localPosition
        this.transform.SetParent(tf,false );
    }
    if (GUILayout.Button("Find-child"))
    {
        //根据名称获取子物体
        //Transform childTF = this.transform.Find("子物体名称");
        Transform childTF = this.transform.Find("子物体名称/子物体名称");
    }
    if (GUILayout.Button("Find-child-indexl"))
    {
        int count = this.transform.childCount;
        //根据索引获取子物体
        for (int i = 0; i < count ; i++)
        {
            Transform childTF = this.transform.GetChild(i);
        }           
    }

    //**************改变位置 角度******************
    if (GUILayout.Button("pos/scale"))
    {
        //物体相对与世界坐标系原点的位置
        //this.transform .position 

        //物体相对于父物体轴心点的位置
        //this.transform .localPosition 

        //相对于父物体缩放比例
        //this.transform .localScale 

        //理解为:物体与模型缩放比例(自身缩放比例*父物体缩放比例)
        //this .transform .localScale 
        //如:父物体LocalScale为3 当前物体localScale为2
        //    localScale 则为6          
    }
    if (GUILayout.Button("Translate"))
    {
        //向 自身坐标系 Z轴移动1米
        //this.transform.Translate(0, 0, 1);

        //向 世界坐标系 Z轴移动1米
        this.transform.Translate(0, 0, 1,Space .World );
    }
    if (GUILayout.Button("Rotate"))
    {
        //向 自身坐标系 Yz轴旋转10度
        //this.transform.Rotate(0, 10, 0);

        //向 世界坐标系 Y轴旋转10度
        this.transform.Rotate (0, 10, 0, Space.World);
    }
    if (GUILayout.RepeatButton("RotateAround"))
    {
        this.transform.RotateAround(Vector3.zero, Vector3.forward , 1);
    }
}

}