Ramaraunt1

Untitled

Dec 22nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5. // ABOUT //
  6. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  7. /*
  8. * This file is a MissionTemplate Template (of the reduntant department of redundancy :D). MissionTemplates can be spawned in to allow the spawning
  9. * of new actors in a certain way, and are the basis of any RPG level.
  10. *
  11. * When copying this file to create a new mission template, be sure to rename the class name AND the file name to the same name, and to change this description
  12. * to explain what is in the template!
  13. *
  14. * - Ramaraunt
  15. */
  16.  
  17. //This class extends Monobehavior, and contains the base methods of Unity.
  18. #region MissionTemplates Class
  19. public class MissionTemplates : MonoBehaviour {
  20.  
  21. //Initialize spawners here. Say, for instance:
  22. // public GameObject spawner;
  23. //Then drag and drop the correct object to the script within Unity IDE.
  24. #region init spawners here
  25.  
  26. #endregion
  27.  
  28. //This is the part you edit to make new MTs!
  29. #region Editable Region
  30. //This method automatically runs when the object that contains this script is created.
  31. void Awake ()
  32. {
  33.  
  34. }
  35.  
  36. //This method is called once per frame of the game.
  37. void Update ()
  38. {
  39. //if you want to make something that occurs after a certain amount of time, go like this:
  40. /*
  41. *
  42. * if (Time.time >= <enter time here>)
  43. * {
  44. * Do stuff here!
  45. * }
  46. *
  47. */
  48. }
  49.  
  50. /*
  51. //Use this method if you are interested in having actors spawn in after a trigger has been hit!
  52. void onTriggerEnter()
  53. {
  54.  
  55. }
  56. */
  57.  
  58. #endregion
  59.  
  60. //This region contains background methods which are important for MTs to run correctly. DONT TOUCH THESE (unless you know what your doing and you have a good reason).
  61. //Please, feel free to look around though. :D
  62. #region Other Stuffs (no touchy)
  63.  
  64. //This region contains a series of utility methods, to be called up above and down bellow.
  65. #region Utilities
  66.  
  67. //This method grabs the prefab of a model, and returns it as a GameObject.
  68. private GameObject returnPrefabFromPath(string path)
  69. {
  70. return Resources.Load(path) as GameObject;
  71. }
  72.  
  73. //This method instantiates a prefab with the GameObject as an argument. It returns the GameObject. It has an overloaded method without rotation and position.
  74. private GameObject instantiatePrefabFromGameObject(Vector3 position, Quaternion rotation, GameObject objectToInstantiate)
  75. {
  76. return ((GameObject)Instantiate(objectToInstantiate, position, rotation));
  77. }
  78.  
  79. private GameObject instantiatePrefabFromGameObject(GameObject objectToInstantiate)
  80. {
  81. return ((GameObject)Instantiate(objectToInstantiate));
  82. }
  83.  
  84. // This method instantiates a game object from a path argument. It returns the GameObject. It has an overloaded method without rotation and position.
  85. private GameObject instantiatePrefabFromPath(Vector3 position, Quaternion rotation, string path)
  86. {
  87. return instantiatePrefabFromGameObject(position ,rotation, returnPrefabFromPath(path));
  88. }
  89.  
  90. private GameObject instantiatePrefabFromPath(string path)
  91. {
  92. return instantiatePrefabFromGameObject(returnPrefabFromPath(path));
  93. }
  94.  
  95. //This method grabs a material from a path and returns it.
  96. private Material returnMaterialFromPath(string path)
  97. {
  98. return Resources.Load<Material>(path);
  99. }
  100.  
  101. //This method adds a material to a specific game object, with an overloaded method grabbing the material directly using a path.
  102. private void addMaterialToGameObject(Material material, GameObject gameObject)
  103. {
  104. gameObject.GetComponent<Renderer>().sharedMaterial = material;
  105. }
  106.  
  107. private void addMaterialToGameObject(string materialPath, GameObject gameObject)
  108. {
  109. gameObject.GetComponent<Renderer>().sharedMaterial = returnMaterialFromPath(materialPath);
  110. }
  111.  
  112. //This method creates a parent-child relationship between two gameobjects
  113. private void setGameObjectParent(GameObject parent, GameObject child)
  114. {
  115. child.transform.parent = parent.transform;
  116. }
  117.  
  118. //This method grabs the material from path, grabs the GameObject from path, and instantiates the object and returns its instance id.
  119. private GameObject setupActorModel(string materialPath, string gameObjectPath, Vector3 position, Quaternion rotation, GameObject parent)
  120. {
  121. GameObject cur_prefab = instantiatePrefabFromGameObject(position, rotation, returnPrefabFromPath(gameObjectPath));
  122.  
  123. addMaterialToGameObject(materialPath, cur_prefab);
  124.  
  125. setGameObjectParent(cur_prefab, parent);
  126.  
  127. return cur_prefab;
  128. }
  129.  
  130.  
  131. #endregion
  132.  
  133. //This region WILL contain stuff for AI calculations, but this isn't done yet!
  134. #region AI Stuffs
  135.  
  136. #endregion
  137.  
  138. //These methods are used for the actual creation of characters. Simply call these up above to make things happen!
  139. #region Actor Creation
  140.  
  141. //This method makes a naked person, using the default constructor of Actor, at the origin point of the scene. Mostly used for bugtesting.
  142. public bool makeNaked()
  143. {
  144. Actor person = new Actor();
  145.  
  146. if (person.getStatus())
  147. {
  148. //spawn the frame
  149.  
  150. }
  151. else
  152. {
  153. Debug.Log("Creation of Naked Actor failed!");
  154. }
  155.  
  156. return person.getStatus();
  157.  
  158. }
  159. #endregion
  160.  
  161. #endregion
  162. }
  163. #endregion
Add Comment
Please, Sign In to add comment