public virtual void Load(string bodyShapeId, Transform parent, Action <WearableController> onSuccess, Action <WearableController> onFail)
    {
        if (isReady)
        {
            return;
        }

        boneRetargetingDirty = true;

        var representation = wearable.GetRepresentation(bodyShapeId);

        if (representation == null)
        {
            onFail?.Invoke(this);
            return;
        }

        var provider = wearable.GetContentProvider(bodyShapeId);

        loader = new RendereableAssetLoadHelper(provider, wearable.baseUrlBundles);

        loader.settings.forceNewInstance     = false;
        loader.settings.initialLocalPosition = Vector3.up * 0.75f;
        loader.settings.cachingFlags         = MaterialCachingHelper.Mode.CACHE_SHADERS;
        loader.settings.visibleFlags         = AssetPromiseSettings_Rendering.VisibleFlags.INVISIBLE;
        loader.settings.parent = parent;

        assetRenderers = null;

        void OnSuccessWrapper(GameObject gameObject)
        {
            if (loader != null)
            {
                loader.OnSuccessEvent -= OnSuccessWrapper;
            }
            assetRenderers = gameObject.GetComponentsInChildren <Renderer>();
            PrepareWearable(gameObject);
            onSuccess?.Invoke(this);
        }

        loader.OnSuccessEvent += OnSuccessWrapper;

        void OnFailEventWrapper()
        {
            if (loader != null)
            {
                loader.OnFailEvent -= OnFailEventWrapper;
                loader.ClearEvents();
                lastMainFileLoaded = null;
                loader             = null;
            }
            onFail?.Invoke(this);
        }

        loader.OnFailEvent += OnFailEventWrapper;

        lastMainFileLoaded = representation.mainFile;
        loader.Load(representation.mainFile);
    }
Пример #2
0
    public void CleanUp()
    {
        UnloadMaterials();
        RestoreOriginalMaterials();
        assetRenderers = null;

        if (loader != null)
        {
            loader.ClearEvents();
            loader.Unload();
            loader = null;
        }
    }