/// <summary> /// Conntects the child mount point to the parent /// </summary> /// <param name="rParent">String representing the parents mount point name</param> /// <param name="rChildItemPath">Resource path to the object we'll instanciate</param> /// <param name="rChildPointName">String representing the child's mount point name</param> /// <returns>GameObject that is the child that is instanciated</returns> public GameObject ConnectMountPoints(string rParentPoint, string rChildItemPath, string rChildPointName) { if (rChildItemPath.Length == 0) { return(null); } MountPoint lParentMP = GetMountPoint(rParentPoint); if (lParentMP == null) { return(null); } GameObject lChild = (GameObject)Instantiate(Resources.Load(rChildItemPath)); if (lChild == null) { return(null); } lChild.name = "Instanciated" + lChild.GetInstanceID(); MountPoint lChildMP = null; MountPoints lChildMPList = lChild.GetComponent <MountPoints>(); if (lChildMPList != null) { lChildMP = lChildMPList.GetMountPoint(rChildPointName); lChildMP.OwnerResourcePath = rChildItemPath; } else { Mount lChildMount = lChild.GetComponent <Mount>(); if (lChildMount != null) { lChildMP = lChildMount.Point; lChildMP.OwnerResourcePath = rChildItemPath; } } // If there is no mount point, get out if (lChildMP == null) { GameObject.DestroyObject(lChild); return(null); } // Finally, connect the objects ConnectMountPoints(lParentMP, lChildMP); // Return the newly created child return(lChild); }
/// <summary> /// Conntects the child mount point to the parent /// </summary> /// <param name="rParentPoint">String representing the parents mount point name</param> /// <param name="rChild">GameObject representing the child</param> /// <param name="rChildPointName">String representing the child mount point name</param> /// <returns>Boolean used to determine if the connection was made</returns> public bool ConnectMountPoints(string rParentPoint, GameObject rChild, string rChildPointName) { if (rChild == null) { return(false); } MountPoint lParentMP = GetMountPoint(rParentPoint); if (lParentMP == null) { return(false); } MountPoint lChildMP = null; MountPoints lChildMPList = rChild.GetComponent <MountPoints>(); if (lChildMPList != null) { lChildMP = lChildMPList.GetMountPoint(rChildPointName); } else { Mount lParentMount = rChild.GetComponent <Mount>(); if (lParentMount != null) { lChildMP = lParentMount.Point; } } // If there is no child, get out if (lChildMP == null) { return(false); } // Finally, connect the objects return(ConnectMountPoints(lParentMP, lChildMP)); }