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

public class SyncTest:MonoBehaviour
{
    public bool isME;
    public FunctionSync_Active active;
    public FunctionSync_Animator animator;
    public FunctionSync_Material material;
    public FunctionSync_Scale scale;
    public FunctionSync_PositionRoate PositionRoate;
    public FunctionSync_Parent parent;
    public FunctionSync_Parent transParent;
   
    int dir = 1;
    private void Start()
    {
        //InitDynamic(gameObject.name, isME);
    }
    bool isred;
    private void Update()
    {
        //if (isME)
        //{
        //    if (transform.position.y <= 3)
        //    {
        //        dir = 1;
        //    }
        //    else if (transform.position.y >= 30)
        //    {
        //        dir = -1;
        //    }
        //    transform.Translate(Vector3.up *3* dir * Time.deltaTime, Space.World);
        //    transform.Rotate(Vector3.up *3* Time.deltaTime);
        //}

        if(Input.GetKeyDown( KeyCode.Z))
        {
            //显隐
            if (!active.gameObject.activeInHierarchy)
            {
                active.ShowObject();
            }
            else
            {
                active.DisShowObject();
            }
        }
        else if(Input.GetKeyDown(KeyCode.X))
        {
            //材质
            if (isred)
            {
                isred = false;
                material.SetMaterial("Material/green");
            }
            else
            {
                isred = true;
                material.SetMaterial("Material/red");
            }
        }
        else if (Input.GetKey(KeyCode.C))
        {
            //缩放
            if(scale.transform.localScale.x>10)
            {
                dir = -1;
            }
            else if(scale.transform.localScale.x <0.3f)
            {
                dir = 1;
            }
            scale.transform.localScale += Vector3.one * dir * Time.deltaTime;
        }
        else if (Input.GetKeyDown(KeyCode.V))
        {
            //动画
            animator.SetAnimatorState("SyncTest");
        }
        else if(Input.GetKeyDown(KeyCode.B))
        {
            //获取移动权限
            PositionRoate.GetControl();
        }
        else if (Input.GetKeyDown(KeyCode.N))
        {
            //释放移动权限
            PositionRoate.ReleaseControl();
        }
        else if(Input.GetKeyDown(KeyCode.Space))
        {
            //生成物体
            Vector3 pos = new Vector3(Random.Range(-50f, 50f), Random.Range(-50f, 50f), Random.Range(-50f, 50f));
            Vector3 roate= new Vector3(Random.Range(-50f, 50f), Random.Range(-50f, 50f), Random.Range(-50f, 50f));
            Vector3 scale= new Vector3(Random.Range(1f, 5f), Random.Range(1f, 5f), Random.Range(1f, 5f));
            FunctionSync_CreateObejct.Instance.CreateObejct("Prefabs/Test/Cube", pos, roate, scale);
        }
        else if(Input.GetKeyDown(KeyCode.P))
        {
            transParent.SetParent(parent, new Vector3(10, 10, 10), new Vector3(30, 50, 90));
        }
    }

  
}