private void AddCurObjects(GameObject _object) { foreach (GameObject _subObject in GameObjectOperation.GetGameObjects(_object)) { AddCurObject(_subObject); } }
/// <summary> /// 获取新生对象 /// </summary> /// <returns></returns> private GameObject GetNewGameObject(PairedIndex <OrganIndex> pairedOrganIndex) { GameObject cloneObject = GameObject.Instantiate(pairedOrganIndex.CurIndex.Belong); /* * 因枝干顶点已经调整完毕 * 故可用后一关键帧中枝干所指的顶点索引确定前一关键帧顶点的位置 */ Vector3 position = TreeModel.GetBranchTopCenter(m_PreGameObjects[0], pairedOrganIndex.CurIndex.From); foreach (GameObject _subObject in GameObjectOperation.GetGameObjects(cloneObject)) { if (!GameObjectValidate.HavaVertices(_subObject)) { continue; } Vector3[] vertices = GameObjectOperation.GetVertices(_subObject); //该对象所有顶点均为该位置 CopyVertices(_subObject.transform.InverseTransformPoint(position), vertices); GameObjectOperation.UpdateMeshInfo(_subObject, vertices); } //设置阈值为0 GameObjectOperation.SetThreshold(cloneObject, 0); return(cloneObject); }
private Bounds ViewportBounds() { /* * 获取当前植物的所有对象 * 逐个遍历 * 将对象的顶点坐标(世界坐标系下)转换成视窗坐标(viewport 以左下角为原点(0, 0), 右上角为(1, 1)的坐标系) * 根据视窗坐标最大最小值生成包围盒 * 用于确定当前对象在视窗中的位置,便于相机调整其自身位置 * 使视点合适 */ List <GameObject> objects = new List <GameObject>(); foreach (TreeModel treeModel in LScene.GetInstance().TreeModels) { objects.AddRange(GameObjectOperation.GetGameObjects(treeModel.TreeModelInstance)); } Vector3 max = Vector3.zero, min = Vector3.zero; /* * 判断是否初始化 max 和 min */ bool flag = true; foreach (GameObject _object in objects) { //无顶点 if (!GameObjectValidate.HavaVertices(_object)) { continue; } Vector3[] vertices = GameObjectOperation.GetVerticesInWorld(_object); foreach (Vector3 vertex in vertices) { Vector3 viewport = mainCamera.WorldToViewportPoint(vertex); if (flag) { max = viewport; min = viewport; flag = false; continue; } else { max = Vector3.Max(max, viewport); min = Vector3.Min(min, viewport); } } } Bounds bounds = new Bounds((max + min) / 2.0f, max - min); return(bounds); }
public void UpdateOutlines() { List <GameObject> objects = GameObjectOperation.GetGameObjects(gameObject); foreach (GameObject go in objects) { if (go.GetComponent <Renderer>() == null) { continue; } Outline outline = go.GetComponent <Outline>(); if (outline == null) { outline = go.AddComponent <Outline>(); m_outlines.Add(outline); } outline.defaultColor = DefaultColorID; outline.Unhighlight(); } }