using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using VRTK;
public class SZRVRHelper : MonoBehaviour
{
#region GetAllTransform
public List<Transform> child = new List<Transform>();
static Bounds maxBound;
/// <summary>
/// 得到当前服务体全部子物体功能
/// </summary>
/// <param name="transPrant">要查询的父物体</param>
public void FindAllTransform(Transform transPrant)
{
if (transPrant.childCount > 0)
{
for (int i = 0; i < transPrant.childCount; i++)
{
FindAllTransform(transPrant.GetChild(i));
}
}
if (!child.Contains(transPrant))
{
child.Add(transPrant);
}
else
{
Debug.LogError(transPrant.name + "-名称重复!!");
}
}
#endregion
#region GetCenter
/// <summary>
/// 获取加载模型的中心点
/// </summary>
/// <param name="tans"></param>
/// <returns></returns>
public static Vector3 GetCenter(Transform tans)
{
maxBound = new Bounds();
if (tans.childCount > 0 )
{
if (tans.GetChild(0).childCount > 0)
{
if (tans.GetChild(0).GetChild(0).GetComponent<Renderer>() != null)
{
maxBound = tans.GetChild(0).GetChild(0).GetComponent<Renderer>().bounds;
for (int i = 1; i < tans.childCount; i++)
{
Transform child = tans.GetChild(i);
if (child.childCount > 0)
{
Renderer render = child.GetChild(0).GetComponent<Renderer>();
maxBound.Encapsulate(render.bounds);
}
}
}
}
}
return maxBound.center;
}
/// <summary>
/// 获取自身中心点
/// </summary>
/// <param name="transform"></param>
/// <returns></returns>
public static Vector3 GetTransSelfCenter(Transform transform)
{
Vector3 center = transform.GetComponent<Renderer>().bounds.center;
return center;
}
/// <summary>
/// 关闭手柄射线
/// </summary>
/// <param name="handTrans"></param>
/// <param name="isClose"></param>
public virtual void CloseLineRender(Transform handTrans,bool isClose)
{
//handTrans.GetComponent<VRTK_StraightPointerRenderer>().enabled = isClose;
//handTrans.Find("MainControllerTooltips").gameObject.SetActive(isClose);
//handTrans.GetComponent<VRTK_UIPointer>().enabled = isClose;
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using System.Text;
public class ModlesFunction : SZRVRHelper
{
static Bounds maxBound;
public bool iszdfl=false;
public bool isrs=false;
public static ModlesFunction InstadateModleFunction;
//private static Dictionary<string, Color> getCurrLoadModelColor = new Dictionary<string, Color>();
Vector3 center;
private void Awake()
{
InstadateModleFunction = this;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
/// <summary>
/// 自动分离
/// </summary>
public void OpenZdfl(Transform transform = null)
{
if (transform == null)
{
transform = this.transform;
}
if (transform.childCount > 0)
{
center = GetCenter(transform);
iszdfl = !iszdfl;
if (iszdfl)
{
foreach (Transform item in transform)
{
Vector3 childCenter = GetTransSelfCenter(item.GetChild(0));
Vector3 direction = childCenter - center;
direction = direction.normalized;
//位置、旋转清零
//item.GetChild(0).position = Vector3.zero;
//item.GetChild(0).rotation = Quaternion.identity;
if (item.childCount > 0)
{
item.GetChild(0).DOMove(item.GetChild(0).position + direction * 0.1f, 0.5f).SetEase(Ease.OutBack);
}
}
}
else
{
foreach (Transform item in transform)
{
item.GetChild(0).DOLocalMove(Vector3.zero, 0.5f);
item.GetChild(0).localRotation = Quaternion.identity;
}
}
}
}
/// <summary>
/// 染色
/// </summary>
public void OpenRs(Transform transform=null)
{
if (transform == null)
{
transform = this.transform;
}
if (transform.childCount > 0)
{
//center = GetCenter(sceneManger);
isrs = !isrs;
StringBuilder str = new StringBuilder();
const string splitChar = ",";
str.Append(isrs.ToString());
if (isrs)
{
str.Append(splitChar);
foreach (Transform item in transform)
{
Color newColor = new Color(UnityEngine.Random.Range(0.0f, 1.0f),
UnityEngine.Random.Range(0.0f, 1.0f),
UnityEngine.Random.Range(0.0f, 1.0f));
item.GetChild(0).GetComponent<MeshRenderer>().material.color = newColor;
//
str.Append(item.name);
str.Append(splitChar);
str.Append(newColor.r.ToString());
str.Append(splitChar);
str.Append(newColor.g.ToString());
str.Append(splitChar);
str.Append(newColor.b.ToString());
str.Append(splitChar);
}
str.Remove(str.Length - 1, 1);
}
else
{
foreach (Transform item in transform)
{
item.GetChild(0).GetComponent<MeshRenderer>().material.color =ModlesLode.getCurrLoadModelColor[item.name];
}
}
}
}
}