public Audience CreateRandomMember(LOD lod, Vector3 pos, Quaternion rot) { switch (lod) { case LOD.FullSize_Bump_FullAnim: { throw new NotImplementedException(); } case LOD.FullSize_Diffuse_FullAnim: { int idx = _characterIdxShuffledList[(_nextCharacterIdx++) % characterNum]; GameObject adObj = new GameObject("Lv " + (int)lod + " agent", typeof(Audience)); Animator body = Instantiate(fullSizeBody[idx]) as Animator; body.transform.parent = adObj.transform; body.transform.localPosition = asseblingPos; body.transform.localRotation = asseblingRot; Audience ad = adObj.GetComponent <Audience>(); adObj.name += " " + ad.agentId; ad.headTransform = (from x in ad.transform.GetComponentsInChildren <Transform>() where x.gameObject.name == "Head_wrapper" || x.gameObject.name == "HeadWrapper" select x).FirstOrDefault(); ad.detailLevel = lod; adObj.AddComponent(typeof(AudienceAnimHandlerFull)); //template version will crash Unity... var handler = adObj.GetComponent <AudienceAnimHandlerFull>(); handler.controller = body; handler.LerpAnimLayerSpeed = 2f; handler.repeatPeriodBound = new Vector2(30f, 60f); handler.SwitchFollowDegSpeed = URandom.Range(80f, 120f); var icon = Instantiate <GameObject>(prefabEyeIcon) as GameObject; icon.SetActive(false); icon.transform.parent = ad.headTransform; icon.transform.localPosition = AudienceAnimHandlerBasic.eyeIconOffset; ad.GetComponent <AudienceAnimHandlerFull>().eyeIcon = icon; Material clothMat, skinMat; GetAudienceMat(false, idx, out clothMat, out skinMat); body.transform.Find("Body").GetComponent <SkinnedMeshRenderer>().material = skinMat; body.transform.Find("Shoes").GetComponent <SkinnedMeshRenderer>().material = clothMat; ad.transform.position = pos; ad.transform.rotation = rot; return(ad); } case LOD.FullSize_Diffuse_FollowAnim: { int idx = _characterIdxShuffledList[(_nextCharacterIdx++) % characterNum]; GameObject adObj = new GameObject("Lv " + (int)lod + " agent", typeof(Audience)); Animator body = Instantiate(fullSizeBody[idx]) as Animator; body.transform.parent = adObj.transform; body.transform.localPosition = asseblingPos; body.transform.localRotation = asseblingRot; Audience ad = adObj.GetComponent <Audience>(); adObj.name += " " + ad.agentId; ad.headTransform = (from x in ad.transform.GetComponentsInChildren <Transform>() where x.gameObject.name == "Head_wrapper" || x.gameObject.name == "HeadWrapper" select x).FirstOrDefault(); ad.detailLevel = lod; adObj.AddComponent(typeof(AudienceAnimHandlerFollow)); //template version will crash Unity... var handler = adObj.GetComponent <AudienceAnimHandlerFollow>(); handler.controller = body; handler.LerpAnimLayerSpeed = 2f; handler.SwitchFollowDegSpeed = URandom.Range(80f, 120f); var icon = Instantiate <GameObject>(prefabEyeIcon) as GameObject; icon.transform.parent = ad.headTransform; icon.SetActive(false); icon.transform.localPosition = AudienceAnimHandlerBasic.eyeIconOffset; ad.GetComponent <AudienceAnimHandlerFollow>().eyeIcon = icon; Material clothMat, skinMat; GetAudienceMat(false, idx, out clothMat, out skinMat); body.transform.Find("Body").GetComponent <SkinnedMeshRenderer>().material = skinMat; body.transform.Find("Shoes").GetComponent <SkinnedMeshRenderer>().material = clothMat; ad.transform.position = pos; ad.transform.rotation = rot; return(ad); } case LOD.FullSize_Diffuse_BasicAnim: { int idx = _characterIdxShuffledList[(_nextCharacterIdx++) % characterNum]; GameObject adObj = new GameObject("Lv " + (int)lod + " agent", typeof(Audience)); Animator body = Instantiate(fullSizeBody[idx]) as Animator; body.transform.parent = adObj.transform; body.transform.localPosition = asseblingPos; body.transform.localRotation = asseblingRot; Audience ad = adObj.GetComponent <Audience>(); adObj.name += " " + ad.agentId; ad.headTransform = (from x in ad.transform.GetComponentsInChildren <Transform>() where x.gameObject.name == "Head_wrapper" || x.gameObject.name == "HeadWrapper" select x).FirstOrDefault(); ad.detailLevel = lod; adObj.AddComponent(typeof(AudienceAnimHandlerBasic)); //template version will crash Unity... var handler = adObj.GetComponent <AudienceAnimHandlerBasic>(); handler.controller = body; var icon = Instantiate <GameObject>(prefabEyeIcon) as GameObject; icon.transform.parent = ad.headTransform; icon.SetActive(false); icon.transform.localPosition = AudienceAnimHandlerBasic.eyeIconOffset; ad.GetComponent <AudienceAnimHandlerBasic>().eyeIcon = icon; Material clothMat, skinMat; GetAudienceMat(false, idx, out clothMat, out skinMat); body.transform.Find("Body").GetComponent <SkinnedMeshRenderer>().material = skinMat; body.transform.Find("Shoes").GetComponent <SkinnedMeshRenderer>().material = clothMat; ad.transform.position = pos; ad.transform.rotation = rot; return(ad); } case LOD.HalfSize_Diffuse_BasicAnim: default: { int idx = _characterIdxShuffledList[(_nextCharacterIdx++) % characterNum]; GameObject adObj = new GameObject("Lv " + (int)lod + " agent", typeof(Audience)); Animator body = Instantiate(halfSizeBody[idx]) as Animator; body.transform.parent = adObj.transform; body.transform.localPosition = asseblingPos; body.transform.localRotation = asseblingRot; Audience ad = adObj.GetComponent <Audience>(); adObj.name += " " + ad.agentId; ad.headTransform = (from x in ad.transform.GetComponentsInChildren <Transform>() where x.gameObject.name == "Head_wrapper" || x.gameObject.name == "HeadWrapper" select x).FirstOrDefault(); ad.detailLevel = lod; adObj.AddComponent(typeof(AudienceAnimHandlerBasic)); //template version will crash Unity... var handler = adObj.GetComponent <AudienceAnimHandlerBasic>(); handler.controller = body; var icon = Instantiate <GameObject>(prefabEyeIcon) as GameObject; icon.SetActive(false); icon.transform.parent = ad.headTransform; icon.transform.localPosition = AudienceAnimHandlerBasic.eyeIconOffset; ad.GetComponent <AudienceAnimHandlerBasic>().eyeIcon = icon; Material clothMat, skinMat; GetAudienceMat(false, idx, out clothMat, out skinMat); body.transform.Find("Body").GetComponent <SkinnedMeshRenderer>().material = skinMat; body.transform.Find("Shoes").GetComponent <SkinnedMeshRenderer>().material = clothMat; ad.transform.position = pos; ad.transform.rotation = rot; return(ad); } } }