我是 Unity 和一般游戲開發的新手。我想做一個基于文本的游戲。我正在尋找重現即時通訊工具(如 messenger 或 whatapp)的行為。
我選擇將 Unity UI 系統用于矩形滾動等預制組件。但是這個選擇讓我遇到了以下問題:
我有對話框的“氣泡”,它必須能夠隨著文本的大小在寬度和高度上增長。圖。1
- 我立即嘗試使用VectorGraphics匯入 .svg,以在運行時移動我的 Beziers 曲線的點。但我沒有找到如何訪問這些點并在運行時編輯它們。
- 然后我找到了“Sprite 形狀”,但它們不是“UI”的一部分,所以如果我采用這樣的解決方案,我將不得不重新實作滾動、按鈕等......
- 我想把我的語音氣泡分成 7 個部分Fig.2并根據文本大小對其進行縮放。但我有一種感覺,這很沉重。
- 最后,我想知道混合解決方案是否不是最好的,使用 UI 進行滾動,獲取轉換并將它們注入到形狀精靈中(在畫布之外)。
如果可以做到 1. 然后我將非常感謝一個例子。如果不是 2. 3. 4. 似乎可行,我想聽聽您對 3. 中最相關的意見。
提前致謝。
uj5u.com熱心網友回復:
There is a simpler and quite elegant solution to your problem that uses nothing but the sprite itself (or rather the design of the sprite).
Take a look at 9-slicing Sprites from the official unity documentation.
With the Sprite Editor you can create borders around the "core" of your speech bubble. Since these speech bubbles are usually colored in a single color and contain nothing else, the ImageType: Sliced would be the perfect solution for what you have in mind. I've created a small Example Sprite to explain in more detail how to approach this:
The sprite itself is 512 pixels wide and 512 pixels high. Each of the cubes missing from the edges is 8x8 pixels, so the top, bottom, and left borders are 3x8=24 pixels deep. The right side has an extra 16 pixels of space to represent a small "tail" on the bubble (bottom right corner). So, we have 4 borders: top=24, bottom=24, left=24 and right=40 pixels. After importing such a sprite, we just have to set its MeshType to FullRect, click Apply and set the 4 borders using the Sprite Editor (don't forget to Apply them too). The last thing to do is to use the sprite in an Image Component on the Canvas and set the ImageType of this Component to Sliced. Now you can scale/warp the Image隨心所欲 - 邊框將始終保持其原始大小而不會變形。而且由于您的氣泡有一個堅實的“核心”,該Sliced選項會在不注意的情況下拉伸這個核心。
編輯:縮放時,Image您必須使用它的WidthandHeight而不是基于 (1,1,1) 的Scale,因為它Scale可能仍然會扭曲您的Image. 此外,這是另一個螢屏截圖,顯示了不同大小的結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/512413.html
上一篇:Haskell參考串列元素的串列
