Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This method grabs the prefab of a model, and returns it as a GameObject.
- private GameObject returnPrefabFromPath(string path)
- {
- return Resources.Load(path) as GameObject;
- }
- //This method instantiates a prefab with the GameObject as an argument. It returns the GameObject. It has an overloaded method without rotation and position.
- private GameObject instantiatePrefabFromGameObject(Vector3 position, Quaternion rotation, GameObject objectToInstantiate)
- {
- return ((GameObject)Instantiate(objectToInstantiate, position, rotation));
- }
- private GameObject instantiatePrefabFromGameObject(GameObject objectToInstantiate)
- {
- return ((GameObject)Instantiate(objectToInstantiate));
- }
- // This method instantiates a game object from a path argument. It returns the GameObject. It has an overloaded method without rotation and position.
- private GameObject instantiatePrefabFromPath(Vector3 position, Quaternion rotation, string path)
- {
- return instantiatePrefabFromGameObject(position ,rotation, returnPrefabFromPath(path));
- }
- private GameObject instantiatePrefabFromPath(string path)
- {
- return instantiatePrefabFromGameObject(returnPrefabFromPath(path));
- }
- //This method grabs a material from a path and returns it.
- private Material returnMaterialFromPath(string path)
- {
- return Resources.Load<Material>(path);
- }
- //This method adds a material to a specific game object, with an overloaded method grabbing the material directly using a path.
- private void addMaterialToGameObject(Material material, GameObject gameObject)
- {
- gameObject.GetComponent<Renderer>().sharedMaterial = material;
- }
- private void addMaterialToGameObject(string materialPath, GameObject gameObject)
- {
- gameObject.GetComponent<Renderer>().sharedMaterial = returnMaterialFromPath(materialPath);
- }
- //This method creates a parent-child relationship between two gameobjects
- private void setGameObjectParent(GameObject parent, GameObject child)
- {
- child.transform.parent = parent.transform;
- }
- //This method grabs the material from path, grabs the GameObject from path, and instantiates the object and returns its instance id.
- private GameObject setupActorModel(string materialPath, string gameObjectPath, Vector3 position, Quaternion rotation, GameObject parent)
- {
- GameObject cur_prefab = instantiatePrefabFromGameObject(position, rotation, returnPrefabFromPath(gameObjectPath));
- addMaterialToGameObject(materialPath, cur_prefab);
- setGameObjectParent(cur_prefab, parent);
- return cur_prefab;
- }
Advertisement
Add Comment
Please, Sign In to add comment