Ramaraunt1

Untitled

Dec 22nd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. //This method grabs the prefab of a model, and returns it as a GameObject.
  2. private GameObject returnPrefabFromPath(string path)
  3. {
  4. return Resources.Load(path) as GameObject;
  5. }
  6.  
  7. //This method instantiates a prefab with the GameObject as an argument. It returns the GameObject. It has an overloaded method without rotation and position.
  8. private GameObject instantiatePrefabFromGameObject(Vector3 position, Quaternion rotation, GameObject objectToInstantiate)
  9. {
  10. return ((GameObject)Instantiate(objectToInstantiate, position, rotation));
  11. }
  12.  
  13. private GameObject instantiatePrefabFromGameObject(GameObject objectToInstantiate)
  14. {
  15. return ((GameObject)Instantiate(objectToInstantiate));
  16. }
  17.  
  18. // This method instantiates a game object from a path argument. It returns the GameObject. It has an overloaded method without rotation and position.
  19. private GameObject instantiatePrefabFromPath(Vector3 position, Quaternion rotation, string path)
  20. {
  21. return instantiatePrefabFromGameObject(position ,rotation, returnPrefabFromPath(path));
  22. }
  23.  
  24. private GameObject instantiatePrefabFromPath(string path)
  25. {
  26. return instantiatePrefabFromGameObject(returnPrefabFromPath(path));
  27. }
  28.  
  29. //This method grabs a material from a path and returns it.
  30. private Material returnMaterialFromPath(string path)
  31. {
  32. return Resources.Load<Material>(path);
  33. }
  34.  
  35. //This method adds a material to a specific game object, with an overloaded method grabbing the material directly using a path.
  36. private void addMaterialToGameObject(Material material, GameObject gameObject)
  37. {
  38. gameObject.GetComponent<Renderer>().sharedMaterial = material;
  39. }
  40.  
  41. private void addMaterialToGameObject(string materialPath, GameObject gameObject)
  42. {
  43. gameObject.GetComponent<Renderer>().sharedMaterial = returnMaterialFromPath(materialPath);
  44. }
  45.  
  46. //This method creates a parent-child relationship between two gameobjects
  47. private void setGameObjectParent(GameObject parent, GameObject child)
  48. {
  49. child.transform.parent = parent.transform;
  50. }
  51.  
  52. //This method grabs the material from path, grabs the GameObject from path, and instantiates the object and returns its instance id.
  53. private GameObject setupActorModel(string materialPath, string gameObjectPath, Vector3 position, Quaternion rotation, GameObject parent)
  54. {
  55. GameObject cur_prefab = instantiatePrefabFromGameObject(position, rotation, returnPrefabFromPath(gameObjectPath));
  56.  
  57. addMaterialToGameObject(materialPath, cur_prefab);
  58.  
  59. setGameObjectParent(cur_prefab, parent);
  60.  
  61. return cur_prefab;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment