Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.26 KB | None | 0 0
  1. using RootMotion.FinalIK;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System;
  6.  
  7. public class ModelObjReferances : MonoBehaviour
  8. {
  9. private PlayerObjReferances playerRefs;
  10.  
  11. [Header("(Manual fill)")]
  12. public Race race;
  13. public Gender gender;
  14. //[SerializeField] private string modelClothesLocation;
  15.  
  16. [Header("(Auto fill)")]
  17. public Photon.Pun.PhotonView pv;
  18.  
  19. public GameObject model;
  20. public RootMotion.BipedReferences referances;
  21.  
  22. private GameObject fingersParentLeft;
  23. private GameObject fingersParentRight;
  24.  
  25. public GameObject handPanelObj;
  26.  
  27. // For Clothes changing
  28. public Dictionary<string, Transform> boneMap { get; private set; }
  29.  
  30. // Storing finger colliders
  31. [SerializeField] private List<CapsuleCollider> fingerCollidersLeft;
  32. [SerializeField] private List<CapsuleCollider> fingerCollidersRight;
  33.  
  34. private WaitForSeconds delay0;
  35. private WaitForSeconds delay1;
  36.  
  37. #region Classes
  38. [System.Serializable]
  39. public class ModelRoot
  40. {
  41. public GameObject root;
  42.  
  43. public GameObject pelvis;
  44. public GameObject groundSeeker;
  45.  
  46. // down the spine
  47. public GameObject spine_01;
  48. public GameObject spine_02;
  49. public GameObject spine_03;
  50.  
  51. public GameObject clavicle_l;
  52. public GameObject upperarm_l;
  53. public GameObject lowerarm_l;
  54. public GameObject hand_l;
  55. public GameObject index_l;
  56.  
  57. public GameObject clavicle_r;
  58. public GameObject upperarm_r;
  59. public GameObject lowerarm_r;
  60. public GameObject hand_r;
  61. public GameObject index_r;
  62.  
  63. public GameObject neck_01;
  64. public GameObject head;
  65. public GameObject hairPlaceholder;
  66.  
  67. // down the thigh_l
  68. public GameObject thigh_l;
  69. public GameObject caif_l;
  70. public GameObject foot_l;
  71. public GameObject ball_l;
  72.  
  73. // down the thigh_r
  74. public GameObject thigh_r;
  75. public GameObject caif_r;
  76. public GameObject foot_r;
  77. public GameObject ball_r;
  78.  
  79. // fingers_03 the ones with colliders
  80. // left hand
  81. [Header("Finger tips. Left hand.")]
  82. public GameObject index_03_l;
  83. public GameObject middle_03_l;
  84. public GameObject pinky_03_l;
  85. public GameObject ring_03_l;
  86. public GameObject thumb_03_l;
  87.  
  88. // right hand
  89. [Header("Finger tips. Right hand.")]
  90. public GameObject index_03_r;
  91. public GameObject middle_03_r;
  92. public GameObject pinky_03_r;
  93. public GameObject ring_03_r;
  94. public GameObject thumb_03_r;
  95.  
  96. public ModelRoot(GameObject gRoot)
  97. {
  98. root = gRoot;
  99.  
  100. pelvis = root.transform.GetChild(0).gameObject;
  101. groundSeeker = root.transform.GetChild(1).gameObject;
  102.  
  103. // down the spine
  104. spine_01 = pelvis.transform.GetChild(0).gameObject;
  105. spine_02 = spine_01.transform.GetChild(0).gameObject;
  106. spine_03 = spine_02.transform.GetChild(0).gameObject;
  107.  
  108. clavicle_l = spine_03.transform.GetChild(2).gameObject;
  109. upperarm_l = clavicle_l.transform.GetChild(0).gameObject;
  110. lowerarm_l = upperarm_l.transform.GetChild(0).gameObject;
  111. hand_l = lowerarm_l.transform.GetChild(0).gameObject;
  112. index_l = hand_l.transform.GetChild(0).gameObject;
  113.  
  114. // finger tips - left
  115. index_03_l = hand_l.transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
  116. middle_03_l = hand_l.transform.GetChild(1).GetChild(0).GetChild(0).gameObject;
  117. pinky_03_l = hand_l.transform.GetChild(2).GetChild(0).GetChild(0).gameObject;
  118. ring_03_l = hand_l.transform.GetChild(3).GetChild(0).GetChild(0).gameObject;
  119. thumb_03_l = hand_l.transform.GetChild(4).GetChild(0).GetChild(0).gameObject;
  120.  
  121. clavicle_r = spine_03.transform.GetChild(3).gameObject;
  122. upperarm_r = clavicle_r.transform.GetChild(0).gameObject;
  123. lowerarm_r = upperarm_r.transform.GetChild(0).gameObject;
  124. hand_r = lowerarm_r.transform.GetChild(0).gameObject;
  125. index_r = hand_r.transform.GetChild(0).gameObject;
  126.  
  127. // finger tips - right
  128. index_03_r = hand_r.transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
  129. middle_03_r = hand_r.transform.GetChild(1).GetChild(0).GetChild(0).gameObject;
  130. pinky_03_r = hand_r.transform.GetChild(2).GetChild(0).GetChild(0).gameObject;
  131. ring_03_r = hand_r.transform.GetChild(3).GetChild(0).GetChild(0).gameObject;
  132. thumb_03_r = hand_r.transform.GetChild(4).GetChild(0).GetChild(0).gameObject;
  133.  
  134. neck_01 = spine_03.transform.GetChild(4).gameObject;
  135. head = neck_01.transform.GetChild(0).gameObject;
  136.  
  137. try { hairPlaceholder = head.transform.GetChild(1).gameObject; }
  138. catch (Exception e) { Debug.LogError("Could not find hairPlaceholder. Make sure that model has it in <...neck_01/head/ >. ");}
  139.  
  140. // down the thigh_l
  141. thigh_l = pelvis.transform.GetChild(1).gameObject;
  142. caif_l = thigh_l.transform.GetChild(0).gameObject;
  143. foot_l = caif_l.transform.GetChild(1).gameObject;
  144. ball_l = foot_l.transform.GetChild(0).gameObject;
  145.  
  146. // down the thigh_r
  147. thigh_r = pelvis.transform.GetChild(2).gameObject;
  148. caif_r = thigh_r.transform.GetChild(0).gameObject;
  149. foot_r = caif_r.transform.GetChild(1).gameObject;
  150. ball_r = foot_r.transform.GetChild(0).gameObject;
  151. }
  152. }
  153.  
  154. [System.Serializable]
  155. public class ModelGrounder
  156. {
  157. public GameObject grounder;
  158.  
  159. public GameObject leftLegIK;
  160. public GameObject rightLegIK;
  161. public GameObject raycastPoint;
  162.  
  163. public ModelGrounder(GameObject gGrounder)
  164. {
  165. grounder = gGrounder;
  166. leftLegIK = grounder.transform.GetChild(0).gameObject;
  167. rightLegIK = grounder.transform.GetChild(1).gameObject;
  168. raycastPoint = grounder.transform.GetChild(2).gameObject;
  169. }
  170. }
  171.  
  172. [System.Serializable]
  173. public class ModelOutfits
  174. {
  175. public List<GameObject> clothes;
  176.  
  177. public ModelOutfits(string location)
  178. {
  179. clothes = new List<GameObject>();
  180.  
  181. try
  182. {
  183. foreach (GameObject g in Resources.LoadAll(location, typeof(GameObject)))
  184. clothes.Add(g);
  185. }
  186. catch (Exception e)
  187. { Debug.LogError("ModelObjRef:: class modelOutfits could not load all outfits and/or is empty. Error: " + e); }
  188. }
  189. public GameObject GetClothesByName(string name)
  190. {
  191. foreach (GameObject g in clothes)
  192. if (g.name.Equals(name))
  193. return g;
  194.  
  195. return null;
  196. }
  197. }
  198.  
  199. public ModelRoot root;
  200. public ModelGrounder grounder;
  201. //public ModelOutfits modelOutfits;
  202. #endregion
  203.  
  204. private void Awake()
  205. {
  206. playerRefs = transform.root.GetComponent<PlayerObjReferances>();
  207.  
  208. model = gameObject;
  209.  
  210. pv = GetComponent<Photon.Pun.PhotonView>();
  211.  
  212. //GetComponent<VRIK>().gameObject.SetActive(true);
  213.  
  214. for (int i = 0; i < gameObject.transform.childCount; i++)
  215. {
  216. if (gameObject.transform.GetChild(i).transform.name == "root")
  217. root = new ModelRoot(gameObject.transform.GetChild(i).gameObject);
  218. if (gameObject.transform.GetChild(i).transform.name == "Grounder")
  219. grounder = new ModelGrounder(gameObject.transform.GetChild(i).gameObject);
  220. }
  221.  
  222. fingerCollidersLeft = new List<CapsuleCollider>();
  223. fingerCollidersRight = new List<CapsuleCollider>();
  224.  
  225. //
  226. AddComponents();
  227.  
  228. SetHandTags();
  229.  
  230. SetRefsVRIK(GetComponent<VRIK>().references);
  231. //SetSolverRefsVRIK(GetComponent<VRIK>()); // set from playerObjRefs
  232.  
  233. SetRefsBiped(referances);
  234. GetComponent<FullBodyBipedIK>().SetReferences(referances, root.spine_01.transform);
  235.  
  236. SetRefsAnimMan(GetComponent<AnimationManager>());
  237.  
  238. SetRefsIKOrder(GetComponent<IKExecutionOrder>());
  239.  
  240. //GetComponent<VRIK>().gameObject.SetActive(true);
  241. SetRefsCharSettings(GetComponent<CharSettings>());
  242.  
  243. SetRefsGrounder(grounder.grounder.GetComponent<GrounderIK>());
  244.  
  245. // Model clothes load
  246. /*
  247. if (modelClothesLocation != "")
  248. modelOutfits = new ModelOutfits(modelClothesLocation);
  249. else
  250. Debug.LogError("ModelObjRef:: modelTorsoLocation not selected. Model clothes did not load...");
  251. */
  252.  
  253. // For Clothes changing
  254. SkinnedMeshRenderer targetMeshRendererHead = transform.Find("CC_Base_Head").GetComponent<SkinnedMeshRenderer>();
  255. SkinnedMeshRenderer targetMeshRenderer = transform.Find("CC_Base_Body").GetComponent<SkinnedMeshRenderer>();
  256. boneMap = new Dictionary<string, Transform>();
  257.  
  258. if (targetMeshRendererHead)
  259. {
  260. foreach (Transform bone in targetMeshRendererHead.bones)
  261. boneMap[bone.gameObject.name] = bone;
  262. }
  263. if (targetMeshRenderer)
  264. {
  265. foreach (Transform bone in targetMeshRenderer.bones)
  266. boneMap[bone.gameObject.name] = bone;
  267. }
  268.  
  269. AddingToCulledLayer();
  270.  
  271. delay0 = new WaitForSeconds(0f);
  272. delay1 = new WaitForSeconds(0.5f);
  273. }
  274. private void Start()
  275. {
  276. //SetSolverRefsVRIK(GetComponent<VRIK>());
  277. //SetRefsAnimMan(GetComponent<AnimationManager>());
  278.  
  279. model.AddComponent<SyncPositions>().enabled = false;
  280. }
  281.  
  282. void SetRefsVRIK(VRIK.References refs)
  283. {
  284. refs.root = model.transform; // model ref
  285. refs.pelvis = root.pelvis.transform;
  286. refs.spine = root.spine_01.transform;
  287. refs.chest = root.spine_02.transform;
  288. refs.neck = root.neck_01.transform;
  289. refs.head = root.head.transform;
  290.  
  291. refs.leftShoulder = root.clavicle_l.transform;
  292. refs.leftUpperArm = root.upperarm_l.transform;
  293. refs.leftForearm = root.lowerarm_l.transform;
  294. refs.leftHand = root.hand_l.transform;
  295.  
  296. refs.rightShoulder = root.clavicle_r.transform;
  297. refs.rightUpperArm = root.upperarm_r.transform;
  298. refs.rightForearm = root.lowerarm_r.transform;
  299. refs.rightHand = root.hand_r.transform;
  300.  
  301. refs.leftThigh = root.thigh_l.transform;
  302. refs.leftCalf = root.caif_l.transform;
  303. refs.leftFoot = root.foot_l.transform;
  304. refs.leftToes = root.ball_l.transform;
  305.  
  306. refs.rightThigh = root.thigh_r.transform;
  307. refs.rightCalf = root.caif_r.transform;
  308. refs.rightFoot = root.foot_r.transform;
  309. refs.rightToes = root.ball_r.transform;
  310. }
  311. void SetSolverRefsVRIK(VRIK ik)
  312. {
  313. ik.solver.spine.headTarget = playerRefs.rigSpineHeadTarget.transform;
  314. ik.solver.leftArm.target = playerRefs.rigLeftHandTarget.transform;
  315. ik.solver.rightArm.target = playerRefs.rigRightHandTarget.transform;
  316.  
  317. ik.enabled = true;
  318. }
  319. void SetRefsBiped(RootMotion.BipedReferences refs)
  320. {
  321. refs.root = model.transform;
  322. refs.pelvis = root.pelvis.transform;
  323.  
  324. refs.leftThigh = root.thigh_l.transform;
  325. refs.leftCalf = root.caif_l.transform;
  326. refs.leftFoot = root.foot_l.transform;
  327.  
  328. refs.rightThigh = root.thigh_r.transform;
  329. refs.rightCalf = root.caif_r.transform;
  330. refs.rightFoot = root.foot_r.transform;
  331.  
  332. refs.leftUpperArm = root.upperarm_l.transform;
  333. refs.leftForearm = root.lowerarm_l.transform;
  334. refs.leftHand = root.hand_l.transform;
  335.  
  336. refs.rightUpperArm = root.upperarm_r.transform;
  337. refs.rightForearm = root.lowerarm_r.transform;
  338. refs.rightHand = root.hand_r.transform;
  339.  
  340. refs.head = root.head.transform;
  341.  
  342. refs.spine = new Transform[2];
  343. refs.spine.SetValue(root.spine_01.transform, 0);
  344. refs.spine.SetValue(root.spine_02.transform, 1);
  345. }
  346. void SetRefsAnimMan(AnimationManager anim)
  347. {
  348. // setting from playerObjRefs
  349. //anim.SetHandTransforms(playerRefs.rigLeftHandTransforms, playerRefs.rigRightHandTransforms);
  350.  
  351. anim.SetAnim(model);
  352. anim.SetEffectors();
  353. }
  354. void SetRefsIKOrder(IKExecutionOrder ike)
  355. {
  356. ike.IKComponents = new RootMotion.FinalIK.IK[3];
  357. ike.IKComponents[0] = GetComponent<VRIK>();
  358. ike.IKComponents[1] = grounder.leftLegIK.GetComponent<LimbIK>();
  359. ike.IKComponents[2] = grounder.rightLegIK.GetComponent<LimbIK>();
  360.  
  361. ike.animator = GetComponent<Animator>();
  362. }
  363. void SetRefsCharSettings(CharSettings charSettings)
  364. {
  365. charSettings.SetRefs(grounder.raycastPoint, root.groundSeeker, root.root, model);
  366. }
  367. void SetRefsGrounder(GrounderIK grik)
  368. {
  369. //grik.legs = new IK[2];
  370. //grik.legs[0] = grounder.leftLegIK.GetComponent<LimbIK>();
  371. //grik.legs[1] = grounder.rightLegIK.GetComponent<LimbIK>();
  372.  
  373. //grik.pelvis = root.pelvis.transform;
  374. //grik.characterRoot = model.transform;
  375. }
  376.  
  377. void SetHandTags()
  378. {
  379. root.hand_l.transform.tag = "LeftHand";
  380. root.index_l.transform.tag = "LeftHand";
  381. root.hand_r.transform.tag = "RightHand";
  382. root.index_r.transform.tag = "RightHand";
  383. }
  384. void AddComponents() // adding rigidbody and box colliders to hands and index fingers
  385. {
  386. //
  387. //model.AddComponent<SyncPositions>().enabled = false;
  388.  
  389. //
  390.  
  391. // left hand
  392. if (root.hand_l.GetComponent<HandPoser>() == null)
  393. root.hand_l.AddComponent<HandPoser>();
  394.  
  395. // index
  396. if (root.index_l.GetComponent<Rigidbody>() == null)
  397. {
  398. Rigidbody rbL = root.index_l.AddComponent<Rigidbody>();
  399. rbL.mass = 1f;
  400. rbL.angularDrag = 0.05f;
  401. rbL.useGravity = false;
  402. rbL.isKinematic = true;
  403. }
  404. if (root.index_l.GetComponent<BoxCollider>() == null)
  405. {
  406. BoxCollider boxL = root.index_l.AddComponent<BoxCollider>();
  407. boxL.isTrigger = true;
  408. boxL.center = new Vector3(-0.047f, 0.01f, 0.033f);
  409. boxL.size = new Vector3(0.14f, 0.05f, 0.088f);
  410. }
  411.  
  412. // right hand
  413. if (root.hand_r.GetComponent<HandPoser>() == null)
  414. root.hand_r.AddComponent<HandPoser>();
  415.  
  416. // index
  417. if (root.index_r.GetComponent<Rigidbody>() == null)
  418. {
  419. Rigidbody rbR = root.index_r.AddComponent<Rigidbody>();
  420. rbR.mass = 1f;
  421. rbR.angularDrag = 0.05f;
  422. rbR.useGravity = false;
  423. rbR.isKinematic = true;
  424. }
  425. if (root.index_r.GetComponent<BoxCollider>() == null)
  426. {
  427. BoxCollider boxR = root.index_r.AddComponent<BoxCollider>();
  428. boxR.isTrigger = true;
  429. boxR.center = new Vector3(0.0485f, -0.01f, -0.033f);
  430. boxR.size = new Vector3(0.144f, 0.05f, 0.092f);
  431. }
  432.  
  433. // Adding hand colliders
  434. //AddLeftHandCollider(root.hand_l);
  435. //AddRightHandCollider(root.hand_r);
  436.  
  437. // Adding parent for finger colliders
  438. if (!fingersParentLeft)
  439. {
  440. fingersParentLeft = new GameObject("FingersParentLeft");
  441. fingersParentLeft.transform.parent = root.hand_l.transform.parent;
  442. }
  443. if (!fingersParentRight)
  444. {
  445. fingersParentRight = new GameObject("FingersParentRight");
  446. fingersParentRight.transform.parent = root.hand_r.transform.parent;
  447. }
  448.  
  449. fingerCollidersLeft.Clear();
  450. fingerCollidersRight.Clear();
  451. if (pv.IsMine)
  452. {
  453. // Adding finger colliders
  454. AddFingerCollider(root.index_03_l, true, 0);
  455. AddFingerCollider(root.middle_03_l, true, 0);
  456. AddFingerCollider(root.pinky_03_l, true, 0);
  457. AddFingerCollider(root.ring_03_l, true, 0);
  458. AddFingerCollider(root.thumb_03_l, true, 0);
  459.  
  460. AddFingerCollider(root.index_03_r, false, 0.02f);
  461. AddFingerCollider(root.middle_03_r, false, 0.02f);
  462. AddFingerCollider(root.pinky_03_r, false, 0.02f);
  463. AddFingerCollider(root.ring_03_r, false, 0.02f);
  464. AddFingerCollider(root.thumb_03_r, false, 0.02f);
  465.  
  466.  
  467. AddHandPanel(root.hand_l);
  468. }
  469. }
  470.  
  471. // TODO right hand settings a bit different
  472. void AddFingerCollider(GameObject finger, bool isLeftHand, float xOffset)
  473. {
  474. if (!finger.transform.GetComponentInChildren<CapsuleCollider>())
  475. {
  476. // Finger itself
  477. Rigidbody rb = finger.AddComponent<Rigidbody>();
  478. rb.mass = 100f;
  479. rb.drag = 1f;
  480. rb.angularDrag = 1f;
  481. rb.useGravity = false;
  482. rb.isKinematic = false;
  483.  
  484. // Fingers collider
  485. GameObject fingerColObj = new GameObject("FingerCollider");
  486.  
  487. //fingerColObj.transform.parent = finger.transform;
  488. if (isLeftHand)
  489. fingerColObj.transform.parent = fingersParentLeft.transform;
  490. else if (!isLeftHand)
  491. fingerColObj.transform.parent = fingersParentRight.transform;
  492.  
  493. fingerColObj.transform.localRotation = new Quaternion(0, 0, 0, 0);
  494. //fingerColObj.transform.localPosition = new Vector3(0, 0, 0);
  495. //fingerColObj.transform.position = finger.transform.position;
  496. fingerColObj.transform.position = new Vector3(finger.transform.position.x + xOffset,
  497. finger.transform.position.y,
  498. finger.transform.position.z);
  499.  
  500. fingerColObj.layer = 18;
  501.  
  502. VibrateOnTouch vot = fingerColObj.AddComponent<VibrateOnTouch>();
  503. vot.isLeft = isLeftHand;
  504.  
  505.  
  506. Rigidbody colRb = fingerColObj.AddComponent<Rigidbody>();
  507. colRb.mass = 5f;
  508. colRb.drag = 1f;
  509. colRb.angularDrag = 1f;
  510. colRb.useGravity = false;
  511. colRb.isKinematic = false;
  512.  
  513.  
  514. FixedJoint fj = finger.AddComponent<FixedJoint>();
  515. fj.connectedBody = colRb;
  516.  
  517.  
  518. CapsuleCollider capCol = fingerColObj.AddComponent<CapsuleCollider>();
  519. capCol.center = new Vector3(-0.01f, 0f, 0f);
  520. capCol.radius = 0.01f;
  521. capCol.direction = 0; // 0 - x axis, 1 - y axis...
  522. capCol.height = 0.03f;
  523.  
  524. if (isLeftHand)
  525. fingerCollidersLeft.Add(capCol);
  526. else if (!isLeftHand)
  527. fingerCollidersRight.Add(capCol);
  528. }
  529. }
  530. void AddLeftHandCollider(GameObject hand)
  531. {
  532. if (hand.transform.childCount < 6)
  533. {
  534. // Hand itself
  535. Rigidbody rb = hand.AddComponent<Rigidbody>();
  536. rb.mass = 1f;
  537. rb.useGravity = false;
  538. rb.isKinematic = true;
  539.  
  540. // Hand collider
  541. GameObject handColObj = new GameObject("HandCollider");
  542. handColObj.transform.parent = hand.transform;
  543. handColObj.transform.localRotation = new Quaternion(0, 0, 0, 0);
  544. handColObj.transform.localPosition = new Vector3(0, 0, 0);
  545.  
  546. Rigidbody colRb = handColObj.AddComponent<Rigidbody>();
  547. colRb.mass = 1f;
  548. colRb.angularDrag = 0f;
  549. colRb.useGravity = false;
  550.  
  551. FixedJoint fj = hand.AddComponent<FixedJoint>();
  552. fj.connectedBody = colRb;
  553.  
  554. BoxCollider boxCol = handColObj.AddComponent<BoxCollider>();
  555. boxCol.center = new Vector3(-0.078f, 0.009f, 0.00085f);
  556. boxCol.size = new Vector3(0.093f, 0.031f, 0.09f);
  557. }
  558. }
  559. void AddRightHandCollider(GameObject hand)
  560. {
  561. if (hand.transform.childCount < 6)
  562. {
  563. // Hand itself
  564. Rigidbody rb = hand.AddComponent<Rigidbody>();
  565. rb.mass = 1f;
  566. rb.useGravity = false;
  567. rb.isKinematic = true;
  568.  
  569. // Hand collider
  570. GameObject handColObj = new GameObject("HandCollider");
  571. handColObj.transform.parent = hand.transform;
  572. handColObj.transform.localRotation = new Quaternion(0, 0, 0, 0);
  573. handColObj.transform.localPosition = new Vector3(0, 0, 0);
  574.  
  575. Rigidbody colRb = handColObj.AddComponent<Rigidbody>();
  576. colRb.mass = 1f;
  577. colRb.angularDrag = 0f;
  578. colRb.useGravity = false;
  579.  
  580. FixedJoint fj = hand.AddComponent<FixedJoint>();
  581. fj.connectedBody = colRb;
  582.  
  583. BoxCollider boxCol = handColObj.AddComponent<BoxCollider>();
  584. boxCol.center = new Vector3(0.074f, -0.009f, 0.00085f);
  585. boxCol.size = new Vector3(0.108f, 0.0252f, 0.09f);
  586. }
  587. }
  588.  
  589. private void AddHandPanel(GameObject attachPart)
  590. {
  591. handPanelObj = Instantiate(Resources.Load("HandPanel") as GameObject);
  592. if (handPanelObj)
  593. {
  594. HandPanel handPanel = handPanelObj.GetComponent<HandPanel>();
  595. handPanel.targetTransform = attachPart.transform;
  596. handPanel.playerObjRefs = playerRefs;
  597. //handPanelObj.transform.parent = transform;
  598.  
  599. handPanelObj.transform.position = attachPart.transform.position;
  600. handPanelObj.transform.rotation = attachPart.transform.rotation;
  601. handPanelObj.transform.parent = attachPart.transform.parent;
  602. }
  603. else
  604. {
  605. Debug.LogError("Could not find HandPanel prefab.");
  606. }
  607. }
  608. private void AddingToCulledLayer() // Head render culling - Camera set to not render 'culled' layer
  609. {
  610. if (pv.IsMine)
  611. {
  612. //Debug.LogError("RUNNING...1");
  613.  
  614. GameObject culledObj0 = transform.Find("CC_Base_Head").gameObject;
  615. if (culledObj0)
  616. culledObj0.layer = 8;
  617. else
  618. Debug.LogError("ModelObjRefs:: Couldn't find <" + culledObj0.name + "> object.");
  619.  
  620. GameObject culledObj1 = transform.Find("CC_Game_Eye").gameObject;
  621. if (culledObj1)
  622. culledObj1.layer = 8;
  623. else
  624. Debug.LogError("ModelObjRefs:: Couldn't find <" + culledObj1.name + "> object.");
  625.  
  626. GameObject culledObj2 = transform.Find("CC_Base_Teeth").gameObject;
  627. if (culledObj2)
  628. culledObj2.layer = 8;
  629. else
  630. Debug.LogError("ModelObjRefs:: Couldn't find <" + culledObj2.name + "> object.");
  631.  
  632. GameObject culledObj3 = transform.Find("CC_Base_Tongue").gameObject;
  633. if (culledObj3)
  634. culledObj3.layer = 8;
  635. else
  636. Debug.LogError("ModelObjRefs:: Couldn't find <" + culledObj3.name + "> object.");
  637.  
  638. // For other models that have more parts that need culling
  639. var culledObj4 = transform.Find("ears");
  640. if (culledObj4)
  641. culledObj4.gameObject.layer = 8;
  642. }
  643. }
  644.  
  645. // Turn on and off hand colliders
  646. public void ToggleHandColliders(bool leftHand, bool toggle)
  647. {
  648. if (toggle == true)
  649. {
  650. StartCoroutine(ToggleHandCollidersDelay(leftHand, delay1));
  651. }
  652. else
  653. {
  654. if (leftHand)
  655. foreach (CapsuleCollider col in fingerCollidersLeft)
  656. col.enabled = false;
  657. else
  658. foreach (CapsuleCollider col in fingerCollidersRight)
  659. col.enabled = false;
  660. }
  661. }
  662.  
  663. private IEnumerator ToggleHandCollidersDelay(bool leftHand, WaitForSeconds delay)
  664. {
  665. yield return delay;
  666.  
  667. if (leftHand)
  668. foreach (CapsuleCollider col in fingerCollidersLeft)
  669. col.enabled = true;
  670. else
  671. foreach (CapsuleCollider col in fingerCollidersRight)
  672. col.enabled = true;
  673. }
  674. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement