Jkeeper 發佈的文章

今天用了animaiton編技能效果, 上次使用已經是 2013年的時候了, 測試了下就上手, 但奇怪的是 image.sprite 的更改一直無效, 可以看到 image.sprite 上面已經紀錄了不同 frame 下的 sprite, 但 run 起來就是無效
12683-tevouz8zewn.png

查了下發現不能用老版 animation 必須改用 animator, 因為 ugui.image 是在老版後面才出現的功能, unity 沒有回頭去更新 animation 功能, 下面我們就來新增新版本試試看

老版本跟新版本區別在創建流程不同跟添加 component 不一樣

老版本是在 GameObject 新增 Animation Component, 然後開啟 Windows -> Animation -> Animation, Create 新增 Animation Clip, 這樣就是使用 animation 運行
95395-9d3yoapblor.png

如果要搭配 animator, 則 GameObject 無須新增, 直接開啟 Windows -> Animation -> Animation, Create 新增 Animation Clip, 查看 unity 會新增 animation clip 跟 animation controller 兩個檔案並且 GameObject 是新增了 Animator Component, 在這個情況下去編輯 Image.Sprite 就正常
69384-15edr27eixv.png

測試某個插件導入到項目中出現問題, 一般這個問題是因為版本不匹配造成的, 因為直接比對了兩項目的 package 將差異 "com.unity.render-pipelines.universal": "10.6.0", 加入目前項目就出現這個問題
71182-71w3zzm3fdi.png

需要查詢 com.unity.render-pipelines.universal 對應 unity 版本, 在官網的插件中選擇版本下拉清單可以查看到對應 unity 版本
42430-b69irldze1.png

隨便改成了 12.0.0 版本, 目測服務器沒有這個版本
00751-06v7xt3j594u.png

查看 Package Manager 顯示是 not found
17397-j8bvfin3ytk.png

再切回去官網查目前最新 12.1.15, 但還是 not found
08571-n49kvo77s08.png

後來打開 Package Manager 查詢支持, 名字是 Universal RP, 版本 12.1.7 執行 import
73922-hnjxcthq92n.png

import 完成後出現錯誤, 場景變紫色

Shader error in Couldn't open include file 'Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl'. at line 59

68784-h0jk21jiwpf.png

這是URP升級造成的, 生成一個URP Asset如下
40719-jc9u8iplj6.png

開啟 Player Settingg -> Graphics, 將 URP Asset 拖拉近來, 再回到場景就好了
78969-krctobrgnjn.png

參考:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.1/manual/index.html
https://blog.csdn.net/q764424567/article/details/133927994

由於電腦轉換了編碼為 utf 發現 vs 打開後不少檔案出現轉換提示, 可能是原本開發時直接在 vs 中新增 .cs 文件的緣故, 因為不透過 unity 新增 .cs 文件估計是參考系統編碼, 所以不少文件編碼都是 ascii 格式, 為了解決這個問題弄了個批量轉換工具, 大致如下吧

需要先安裝 chardet 工具

$ pip install chardet 

代碼如下:

import os
import chardet

root_path = r"g:\OlgCase\bbm\source\Unity\Assets\Hotfix"
count = 0
for path, subdirs, files in os.walk(root_path):
for name in files:
    if not name.endswith('cs'):
        continue
    fn = os.path.join(path, name)

    print(fn)
    f = open(fn, mode='rb')
    content = f.read()
    f.close()
    result = chardet.detect(content)

    if result['encoding'] == None:
        print('error')
        continue

    print(result)
    if (result['encoding'] != 'UTF-8-SIG' and
     result['encoding'] != 'UTF-8' and 
     result['encoding'] != 'utf-8'):

        print('process, encoding:' + result['encoding'] + ", fn:" + fn)
        if result["encoding"] == "GB2312":
            result["encoding"] = "GBK"
        with open(fn, "w", encoding="UTF-8-SIG", newline='\n') as file:
            line = str(content, encoding = "GBK")
            print(line)
            file.write(line)
            count +=1
            file.close()

print("轉換檔案數",count)

測試編譯cocos2.3.3項目

gradle plugin version: 3.2.0

gradle version : 4.6

Sync Gradle 完成後顯示 gradle 4.6 不受 java11支持了
30796-w2riuoraff.png

查詢下 gradle 跟 gradle plugin 對應版本
17950-tuk2nvjdru8.png

gradle 選擇 7.2 , gradle plugin 選擇 7.1, 從 build.gradle 修改 gradle plugin 版本
63890-mjm9alvave7.png

選擇 File -> Project Structure, Gradle 版本選擇7.2
50183-so76jbeso8c.png

再執行 Sync Gradle 出錯,
A problem occurred evaluating project ':game'.

Plugin with id 'com.android.feature' not found.
22732-ft46qkhull.png

https://stackoverflow.com/questions/65452088/android-studio-plugin-with-id-com-android-feature-not-found

查詢得知 com.android.feature 在3.6.0後面就不再支持

由於編譯機器使用 java 17, 開啟老版本 as 會出現錯誤