Exemple #1
0
    // Token: 0x0600577D RID: 22397 RVA: 0x001E2CD8 File Offset: 0x001E10D8
    private GameObject CreateAvatarClone(string name, AvatarCloneType type)
    {
        GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.currentAvatar);

        AvatarValidation.RemoveIllegalComponents(name, gameObject, true);
        gameObject.name               = name;
        gameObject.transform.parent   = this.currentAvatar.transform.parent;
        gameObject.transform.position = this.currentAvatar.transform.position;
        gameObject.transform.rotation = this.currentAvatar.transform.rotation;
        AvatarClone avatarClone = gameObject.AddComponent <AvatarClone>();

        avatarClone.OriginalAvatar = this.currentAvatar;
        avatarClone.CloneType      = type;
        avatarClone.StripComponents();
        Tools.SetLayerRecursively(gameObject, (type != AvatarCloneType.Mirror) ? LayerMask.NameToLayer("PlayerLocal") : LayerMask.NameToLayer("MirrorReflection"), -1);
        return(gameObject);
    }
Exemple #2
0
    // Token: 0x0600577B RID: 22395 RVA: 0x001E2320 File Offset: 0x001E0720
    private void AttachAvatarInternal(UnityEngine.Object Prefab, string Name, float Scale = 1f)
    {
        this.WasMeasured = false;
        if (this == null || base.gameObject == null || base.GetComponent <Transform>() == null)
        {
            Debug.LogError("AttachAvatarInternal: VRCAvatarManager was destroyed, could not attach avatar: " + Name);
            return;
        }
        GameObject gameObject = AssetManagement.Instantiate <GameObject>(Prefab);

        if (gameObject == null || gameObject.GetComponent <Transform>() == null)
        {
            Debug.LogError("Could not instantiate avatar " + Name);
            return;
        }
        AvatarValidation.RemoveIllegalComponents(Name, gameObject, true);
        AvatarValidation.EnforceAudioSourceLimits(gameObject);
        if (!this.localPlayer)
        {
            foreach (Camera camera in gameObject.GetComponentsInChildren <Camera>())
            {
                Debug.LogWarning("Removing camera from " + camera.gameObject.name);
                UnityEngine.Object.Destroy(camera);
            }
        }
        int num = 2;

        VRC.Network.AssignNetworkIDsToObject(gameObject, false, VRC.Network.GetOwnerId(base.gameObject).Value, ref num);
        VRC.Network.IsObjectReady(gameObject);
        base.transform.localPosition       = Vector3.zero;
        base.transform.localRotation       = Quaternion.identity;
        gameObject.transform.parent        = base.transform;
        gameObject.transform.localPosition = new Vector3(0f, 0f, 0f);
        gameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 1f);
        gameObject.transform.localScale   *= Scale;
        VRC_AvatarDescriptor component = gameObject.GetComponent <VRC_AvatarDescriptor>();

        if (component == null)
        {
            Debug.LogError("Avatar Missing Descriptor");
            Analytics.Send(ApiAnalyticEvent.EventType.error, "Avatar Missing Descriptor: " + Name, null, null);
            UnityEngine.Object.Destroy(gameObject);
            return;
        }
        if (gameObject.GetComponent <Animator>() == null)
        {
            Debug.Log("Avatar Missing Animator");
            if (base.transform.parent != null)
            {
                Debug.Log("Avatar player object name=" + base.transform.parent.name);
            }
            Analytics.Send(ApiAnalyticEvent.EventType.error, "Avatar Missing Animator: " + Name, null, null);
        }
        if (this._avatarMirrorClone != null)
        {
            this.DestroyAvatarRenderClone();
        }
        if (this.currentAvatar != null)
        {
            VRC_EventHandler[] componentsInChildren2 = this.currentAvatar.GetComponentsInChildren <VRC_EventHandler>();
            foreach (VRC_EventHandler vrc_EventHandler in componentsInChildren2)
            {
                vrc_EventHandler.Unregister();
            }
            if (this.currentAvatar.GetComponent <Transform>() != null)
            {
                this.currentAvatar.GetComponent <Transform>().parent = null;
            }
            UnityEngine.Object.Destroy(this.currentAvatar);
        }
        this.currentAvatar           = gameObject;
        this.currentAvatarDescriptor = component;
        AudioListener[] componentsInChildren3 = gameObject.GetComponentsInChildren <AudioListener>();
        foreach (AudioListener audioListener in componentsInChildren3)
        {
            audioListener.enabled = false;
        }
        if (!this.localPlayer)
        {
            Camera[] componentsInChildren4 = gameObject.GetComponentsInChildren <Camera>();
            foreach (Camera camera2 in componentsInChildren4)
            {
                camera2.enabled = false;
            }
        }
        AudioListener[] componentsInChildren5 = gameObject.GetComponentsInChildren <AudioListener>();
        foreach (AudioListener audioListener2 in componentsInChildren5)
        {
            audioListener2.enabled = false;
        }
        SkinnedMeshRenderer[] componentsInChildren6 = this.currentAvatar.GetComponentsInChildren <SkinnedMeshRenderer>();
        foreach (SkinnedMeshRenderer skinnedMeshRenderer in componentsInChildren6)
        {
            skinnedMeshRenderer.updateWhenOffscreen = true;
        }
        this.visibleElements      = gameObject.GetComponentsInChildren <Renderer>(true);
        this.visibleElementEnable = new bool[this.visibleElements.Length];
        for (int num2 = 0; num2 < this.visibleElements.Length; num2++)
        {
            this.visibleElementEnable[num2] = this.visibleElements[num2].enabled;
        }
        List <IVRCCullable> list = new List <IVRCCullable>();

        foreach (DynamicBone item in gameObject.GetComponentsInChildren <DynamicBone>(true))
        {
            list.Add(item);
        }
        this.cullableElements   = list.ToArray();
        this._laserSelectRegion = null;
        if (!this.localPlayer && this._vrcPlayer != null)
        {
            Transform transform = this._vrcPlayer.transform.Find("SelectRegion");
            if (transform != null)
            {
                this._laserSelectRegion = transform.gameObject.GetComponent <PlayerSelector>();
            }
        }
        Animator component2 = this.currentAvatar.GetComponent <Animator>();

        if (component2 != null && component2.avatar != null)
        {
            if (component2.isHuman)
            {
                this._nonHuman = false;
                this.currentAvatar.GetOrAddComponent <VRIK>();
                this.currentAvatar.GetOrAddComponent <FullBodyBipedIK>();
                this.currentAvatar.GetOrAddComponent <global::LimbIK>();
                component2.runtimeAnimatorController = null;
                if (component.Animations == VRC_AvatarDescriptor.AnimationSet.Female)
                {
                    this._useFemaleAnims = true;
                }
                else
                {
                    this._useFemaleAnims = false;
                }
                AnimatorOverrideController defaults = this.animatorControllerMale;
                if (this._useFemaleAnims)
                {
                    defaults = this.animatorControllerFemale;
                }
                AnimatorOverrideController defaults2 = this.animatorControllerMaleSitting;
                if (this._useFemaleAnims)
                {
                    defaults2 = this.animatorControllerFemaleSitting;
                }
                this.currentStandingAnims            = this.MergeAnims("CustomStanding", defaults, component.CustomStandingAnims);
                this.currentSittingAnims             = this.MergeAnims("CustomSitting", defaults2, component.CustomSittingAnims);
                component2.runtimeAnimatorController = this.currentStandingAnims;
                component2.updateMode = AnimatorUpdateMode.Normal;
                if (this.currentStandingAnims == null)
                {
                    Debug.LogError(((!(this._vrcPlayer != null)) ? base.gameObject.name : this._vrcPlayer.name) + " has human avatar with broken standing animations.", this);
                    this.currentStandingAnims = this.animatorControllerMale;
                }
                else if (this.currentSittingAnims == null)
                {
                    Debug.LogError(((!(this._vrcPlayer != null)) ? base.gameObject.name : this._vrcPlayer.name) + " has human avatar with broken sitting animations.", this);
                    this.currentSittingAnims = this.animatorControllerMaleSitting;
                }
            }
            else
            {
                this._nonHuman = true;
                if (this.localPlayer)
                {
                    VRCTrackingManager.SetAvatarViewPoint(this.currentAvatarDescriptor.ViewPosition, Vector3.zero);
                }
                this.currentAvatarArmLength = VRCTracking.DefaultArmLength;
                this.currentAvatarEyeHeight = this.currentAvatarDescriptor.ViewPosition.y;
                if (this.localPlayer)
                {
                    VRCTrackingManager.AdjustViewPositionToAvatar();
                }
            }
            if (this.localPlayer)
            {
                component2.cullingMode = AnimatorCullingMode.AlwaysAnimate;
            }
            else
            {
                component2.cullingMode = AnimatorCullingMode.CullUpdateTransforms;
            }
            component2.applyRootMotion = false;
        }
        else
        {
            this._nonHuman = true;
            if (this.localPlayer)
            {
                VRCTrackingManager.SetAvatarViewPoint(this.currentAvatarDescriptor.ViewPosition, Vector3.zero);
            }
            this.currentAvatarArmLength = VRCTracking.DefaultArmLength;
            this.currentAvatarEyeHeight = this.currentAvatarDescriptor.ViewPosition.y;
            if (this.localPlayer)
            {
                VRCTrackingManager.AdjustViewPositionToAvatar();
            }
        }
        Transform transform2 = base.transform.Find("../CameraMount");

        if (transform2 != null && base.transform.parent != null)
        {
            transform2.position = base.transform.parent.TransformPoint(new Vector3(this.currentAvatarDescriptor.ViewPosition.x / base.transform.parent.localScale.x, this.currentAvatarDescriptor.ViewPosition.y / base.transform.parent.localScale.y, 0f));
        }
        MeshRenderer[] componentsInChildren8 = this.currentAvatar.GetComponentsInChildren <MeshRenderer>();
        foreach (MeshRenderer meshRenderer in componentsInChildren8)
        {
            meshRenderer.lightProbeUsage = this.useLightProbes;
        }
        SkinnedMeshRenderer[] componentsInChildren9 = this.currentAvatar.GetComponentsInChildren <SkinnedMeshRenderer>();
        foreach (SkinnedMeshRenderer skinnedMeshRenderer2 in componentsInChildren9)
        {
            skinnedMeshRenderer2.lightProbeUsage     = this.useLightProbes;
            skinnedMeshRenderer2.updateWhenOffscreen = this.localPlayer;
        }
        Vector3 localPosition = new Vector3(0f, this.currentAvatarDescriptor.ViewPosition.y + 0.5f, 0f);

        if (this.profile != null)
        {
            this.profile.localPosition = localPosition;
        }
        if (this.old_profile != null)
        {
            this.old_profile.localPosition = localPosition;
        }
        if (this.localPlayer)
        {
            Tools.SetLayerRecursively(gameObject, LayerMask.NameToLayer("PlayerLocal"), LayerMask.NameToLayer("UiMenu"));
        }
        else
        {
            Tools.SetLayerRecursively(gameObject, LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("UiMenu"));
        }
        if (this.localPlayer)
        {
            this.InitAvatarRenderClone();
        }
        this._isAttached           = true;
        this.localAvatarVisibility = VRCAvatarManager.LocalAvatarVisibility.Visible;
        this.RefreshLocalAvatarVisibility();
        if (this.OnAvatarCreated != null)
        {
            this.OnAvatarCreated(this.currentAvatar, this.currentAvatarDescriptor, false);
        }
    }