private void CreateLeafModel(LeafIndex index, Vector3 position) { /* * 计算形态数据:长度和最大宽度 * 用于后续生成GameObject */ index.MorphologicalSim(); GameObject leafModel = (GameObject)GameObject.Instantiate(index.LeafMesh.Instance); //模型实例化 leafModel.name = index.LeafMesh.Name; leafModel.tag = "Organ"; SetTagInParent(leafModel.transform, "Organ"); /* * 设置空间信息 */ leafModel.transform.position = position; RotationGameObject(leafModel, position, index.Rotation); /* * 养分 */ List <Material> materials = GameObjectOperation.GetMaterials(leafModel); switch (EnvironmentParams.NutrientType) { case LightResponseType.N_LACK: //SetIllnessColor(materials, MaizeParams.lackN_Color); break; case LightResponseType.P_LACK: SetIllnessColor(materials, MaizeParams.lackP_Color); break; case LightResponseType.K_LACK: SetIllnessColor(materials, MaizeParams.lackK_Color); break; } /* * 设置形态信息 * 受病虫害影响后,叶面积变化较大 * 而整体比例影响较小 * 故采用未受到病虫害影响的叶面积计算比例 */ float scale = Mathf.Sqrt((float)(index.LeafArea_Uninsected / index.UniformLeafArea)); leafModel.transform.localScale = Vector3.one * scale; /* * 设置父节点 */ leafModel.transform.SetParent(BranchModel.transform); /* * 信息补齐 */ index.Belong = leafModel; m_listOrganModels.Add(leafModel); }