Ramaraunt1

Untitled

Dec 22nd, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MissionTemplatesBase : MonoBehaviour {
  5.  
  6. //This region contains a series of utility methods, to be called up above and down bellow.
  7. #region Utilities
  8.  
  9. //This method grabs the prefab of a model, and returns it as a GameObject.
  10. private GameObject returnPrefabFromPath(string path)
  11. {
  12. return Resources.Load(path) as GameObject;
  13. }
  14.  
  15. //This method instantiates a prefab with the GameObject as an argument. It returns the GameObject. It has an overloaded method without rotation and position.
  16. private GameObject instantiatePrefabFromGameObject(Vector3 position, Quaternion rotation, GameObject objectToInstantiate)
  17. {
  18. return ((GameObject)Instantiate(objectToInstantiate, position, rotation));
  19. }
  20.  
  21. private GameObject instantiatePrefabFromGameObject(GameObject objectToInstantiate)
  22. {
  23. return ((GameObject)Instantiate(objectToInstantiate));
  24. }
  25.  
  26. // This method instantiates a game object from a path argument. It returns the GameObject. It has an overloaded method without rotation and position.
  27. private GameObject instantiatePrefabFromPath(Vector3 position, Quaternion rotation, string path)
  28. {
  29. return instantiatePrefabFromGameObject(position, rotation, returnPrefabFromPath(path));
  30. }
  31.  
  32. private GameObject instantiatePrefabFromPath(string path)
  33. {
  34. return instantiatePrefabFromGameObject(returnPrefabFromPath(path));
  35. }
  36.  
  37. //This method grabs a material from a path and returns it.
  38. private Material returnMaterialFromPath(string path)
  39. {
  40. return Resources.Load<Material>(path);
  41. }
  42.  
  43. //This method adds a material to a specific game object, with an overloaded method grabbing the material directly using a path.
  44. private void addMaterialToGameObject(Material material, GameObject gameObject)
  45. {
  46. if (gameObject.GetComponent<Renderer>() == null)
  47. {
  48. gameObject.AddComponent<MeshRenderer>();
  49. gameObject.GetComponent<Renderer>().sharedMaterial = material;
  50. }
  51. else
  52. {
  53. gameObject.GetComponent<Renderer>().sharedMaterial = material;
  54. }
  55. }
  56.  
  57. private void addMaterialToGameObject(string materialPath, GameObject gameObject)
  58. {
  59. addMaterialToGameObject(returnMaterialFromPath(materialPath), gameObject);
  60. }
  61.  
  62. //This method creates a parent-child relationship between two gameobjects
  63. private void setGameObjectParent(GameObject parent, GameObject child)
  64. {
  65. child.transform.parent = parent.transform;
  66. }
  67.  
  68. //This method grabs the material from path, grabs the GameObject from path, and instantiates the object and returns its instance id.
  69. private GameObject setupActorModel(string materialPath, string gameObjectPath, Vector3 position, Quaternion rotation, GameObject parent)
  70. {
  71. GameObject cur_prefab = instantiatePrefabFromGameObject(position, rotation, returnPrefabFromPath(gameObjectPath));
  72.  
  73. addMaterialToGameObject(materialPath, cur_prefab);
  74.  
  75. setGameObjectParent(parent, cur_prefab);
  76.  
  77. return cur_prefab;
  78. }
  79.  
  80.  
  81. #endregion
  82.  
  83. //This region WILL contain stuff for AI calculations, but this isn't done yet!
  84. #region AI Stuffs
  85.  
  86. #endregion
  87.  
  88. //These methods are used for the actual creation of characters. Simply call these up above to make things happen!
  89. #region Actor Creation
  90.  
  91. //This method makes a naked person, using the default constructor of Actor, at the given spawn object. Mostly used for bugtesting.
  92. public bool makeNaked(GameObject spawn)
  93. {
  94. Actor person = new Actor();
  95.  
  96. if (person.getStatus())
  97. {
  98. //spawn the frame
  99. GameObject frame = instantiatePrefabFromGameObject(spawn.transform.position,spawn.transform.rotation, returnPrefabFromPath(BodyPart.bodyFrame()));
  100.  
  101. //build the body
  102. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Head(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  103. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Arms(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  104. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Ears(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  105. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Feet(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  106. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Legs(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  107. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Torso(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  108. setupActorModel(SkinMaterial.get(SkinColor.Caucasian()), BodyPart.Hands(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  109. setupActorModel(SkinMaterial.get(EyeColor.Brown()), BodyPart.Eyes(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  110. setupActorModel(TongueMaterial.get(), BodyPart.Tongue(Gender.Male()), spawn.transform.position, spawn.transform.rotation, frame);
  111.  
  112. //add components to frame
  113. frame.AddComponent<basicAIcontroller>();
  114. }
  115. else
  116. {
  117. Debug.Log("Creation of Naked Actor failed!");
  118. }
  119.  
  120. return person.getStatus();
  121.  
  122. }
  123. #endregion
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment