Example #1
0
    public void UnloadAsset()
    {
        if (CanUnload() == false)
        {
            return;
        }

        _baseDir = AssetLoader.GetLive2dDirById(_modelId) + "/";

        IPlatformManager pm = Live2DFramework.GetPlatformManager();

        pm.UnloadBytes(AssetLoader.GetLive2dModelJsonById(_modelId));

        // Live2D Model
        if (modelSetting.GetModelFile() != null)
        {
            pm.UnloadBytes(_baseDir + modelSetting.GetModelFile());

            var len = modelSetting.GetTextureNum();
            for (int i = 0; i < len; i++)
            {
                pm.UnloadTexture(_baseDir + modelSetting.GetTextureFile(i));
            }
        }

        // Expression
        if (modelSetting.GetExpressionNum() != 0)
        {
            var len = modelSetting.GetExpressionNum();
            for (int i = 0; i < len; i++)
            {
                pm.UnloadBytes(_baseDir + modelSetting.GetExpressionFile(i));
            }
        }

        // Physics
        if (modelSetting.GetPhysicsFile() != null)
        {
            pm.UnloadBytes(_baseDir + modelSetting.GetPhysicsFile());
        }

        // Pose
        if (modelSetting.GetPoseFile() != null)
        {
            pm.UnloadBytes(_baseDir + modelSetting.GetPoseFile());
        }


        string[] motionGroup = modelSetting.GetMotionGroupNames();

        for (int i = 0; i < motionGroup.Length; i++)
        {
            int num = modelSetting.GetMotionNum(motionGroup[i]);
            if (num != 0)
            {
                for (int j = 0; j < num; j++)
                {
                    pm.UnloadBytes(_baseDir + modelSetting.GetMotionFile(motionGroup[i], j));
                }
            }
        }

        _modelId = null;
    }