unity发布WebGL遇到的坑(持续更新)

1、unity默认字体在网页中不会显示

解决方法:自己新导入一个字体,使用导入的字体

2、之前打过包并运行过,后面又在unity中进行了修改,重新打包,运行发现还是修改之前的效果,虽然是新包,

解决方法:这是因为网页中有缓存, 点击浏览器右边的三个点,选择设置--隐私、搜索与服务--清除浏览数据,清除后重新运行

3、如果unity 里使用了ILRintime热更新,和DoTween插件,在热更里使用了DoTween,运行WebGL时运行到Do处代码会报错。

Cannot find Type:DG.Tweening.ShortcutExtensions

at ILRuntime.Runtime.Enviorment.AppDomain.GetType (System.Object token, ILRuntime.CLR.TypeSystem.IType contextType, ILRuntime.CLR.Method.IMethod contextMethod) [0x00000] in <00000000000000000000000000000000>:0

解决方法:在unity里把Do的功能重新封装一下,然后在热更里掉用封装好的类

csharp 复制代码
using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DoTweenTool 
{
    private static DoTweenTool _instance;
    public static DoTweenTool Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new DoTweenTool();
            }
            return _instance;
        }
    }
    Dictionary<string, Tween> tweenDic = new Dictionary<string, Tween>();

    public void DoColor( Image target,Color endValue,float duration)
    {
        Tween tween= target.DOColor( endValue, duration);
        if(!tweenDic.ContainsKey(target.name))
        {
            tweenDic.TryAdd(target.name, tween);

        }
    }

    public void DOAnchorPosX(RectTransform target,float endValue,float duration)
    {
        Tween tween= target.DOAnchorPosX(endValue, duration);
        if (!tweenDic.ContainsKey(target.name))
        {
            tweenDic.TryAdd(target.name, tween);

        }
    }

    public void DOText(Text target,string content,float duration,Action action)
    {
        Tween tween=  target.DOText(content, duration).SetEase(Ease.Linear).OnUpdate(()=> { action?.Invoke(); });
        if (!tweenDic.ContainsKey(target.name))
        {
            tweenDic.TryAdd(target.name, tween);

        }
    }

    public void DOLocalMoveX(Transform target,float endValue,float duration)
    {
        Tween tween = target.DOLocalMoveX(endValue, duration);
        if (!tweenDic.ContainsKey(target.name))
        {
            tweenDic.TryAdd(target.name, tween);

        }
    }

    public void Kill(string name)
    {
        if (tweenDic.ContainsKey(name))
        {
            tweenDic.Remove(name);

        }
    }
}
相关推荐
jtymyxmz4 小时前
《Unity Shader》8.4 透明度混合
unity·游戏引擎
世洋Blog5 小时前
利用<<左移运算符优雅的设计游戏能力的任意组合和判断
游戏·unity·c#
GISer_Jing8 小时前
3D Cesium渲染架剖析
javascript·3d·webgl
Swift社区12 小时前
用 Chrome DevTools 深度分析 Vue WebGL 内存泄漏(进阶篇)
vue.js·webgl·chrome devtools
毛甘木16 小时前
Unity MonoPInvokeCallback 使用教程
c++·unity
心疼你的一切17 小时前
Unity开发Rokid应用之离线语音指令交互模型
android·开发语言·unity·游戏引擎·交互·lucene
Sator120 小时前
Unity使用OpenXR时,初始化失败的问题
unity·游戏引擎·vr
雨泽‎1 天前
Unity在URP中开启后处理导致RenderTexture存在背景
unity·游戏引擎·图形渲染
冒泡P2 天前
【Unity】TextMeshPro富文本中使用精灵图集
ui·unity·c#·游戏引擎
世洋Blog2 天前
开发思想-(数据驱动+组合模式)VS 继承
unity·组合模式·数据驱动