Esempio n. 1
0
    // Mount style mesh.
    private GameObject MountComponent(Transform mountingObject, string mountBoneName, string mountingMakerName)
    {
        // Find mount mountBone.
        var mountBone = ObjectUtility.FindChildObject(avatar.AvatarObject, mountBoneName);

        if (mountBone == null)
        {
#if ENABLE_AVATAR_COMPONENT_LOG
            Debug.LogWarning("Not found the mount bone on base object : " + mountBoneName);
#endif
            return(null);
        }

        // Find mount mountBone in first depth children.
        var mountingBone = ObjectUtility.FindChildObject(mountingObject, mountingMakerName, true);
        if (mountingBone == null)
        {
#if ENABLE_AVATAR_COMPONENT_LOG
            Debug.LogWarning("Not found the mount mountBone in usedComponent model: " + mountingObject.name + " " + mountingMakerName);
#endif
            return(null);
        }

        // Create one new object for this usedComponent.
        Transform mountingRoot = new GameObject(mountingObject.gameObject.name).transform;
        ObjectUtility.UnifyWorldTrans(mountingBone, mountingRoot);

        // Attach to mounting root
        ObjectUtility.AttachToParentAndKeepWorldTrans(mountingRoot, mountingObject);

        // Set to layer.
        ObjectUtility.SetObjectLayer(mountingRoot.gameObject, avatar.gameObject.layer);

        // Attach to mount bone.
        Transform avatarTrans = avatar.gameObject.transform;
        Vector3   oldScale    = avatarTrans.localScale;
        avatarTrans.localScale = Vector3.one;
        ObjectUtility.AttachToParentAndResetLocalPosAndRotation(mountBone, mountingRoot);
        avatarTrans.localScale = oldScale;

        return(mountingRoot.gameObject);
    }