mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-27 01:48:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f540025b0 | ||
|
|
d52ef620a7 | ||
|
|
07039886ae | ||
|
|
401185a2cc | ||
|
|
9439c01107 | ||
|
|
bc7a68b979 | ||
|
|
2d0af700a2 | ||
|
|
373810692d | ||
|
|
ff13300bcd | ||
|
|
6590e58f0a | ||
|
|
b2517803b2 | ||
|
|
46efff5a02 | ||
|
|
941f1924ec | ||
|
|
0310a412f1 | ||
|
|
2ec6399303 | ||
|
|
1a1c177969 | ||
|
|
a2254ea709 | ||
|
|
c237ce7f0a | ||
|
|
b9445499e2 | ||
|
|
3350680b5c | ||
|
|
ee2d8bef6e | ||
|
|
d7ea45b595 | ||
|
|
22f24f499c | ||
|
|
23c1921c2c | ||
|
|
0ba0a01908 | ||
|
|
7acf5061e3 | ||
|
|
03c41461c1 | ||
|
|
7a87c4114c | ||
|
|
eb8233457a | ||
|
|
b08158fd5a | ||
|
|
bdc24381a7 | ||
|
|
60a8edf481 | ||
|
|
1e63b244ec | ||
|
|
9e4fdbb5f1 | ||
|
|
fb94533109 | ||
|
|
6d20996ccd | ||
|
|
112f4beb4a | ||
|
|
be733ccf8b | ||
|
|
6a5ac4d8e6 | ||
|
|
874a68d7c7 | ||
|
|
34286a8101 | ||
|
|
3f5755e553 | ||
|
|
1e938ee8f5 | ||
|
|
384c13c5ac | ||
|
|
6af384649a | ||
|
|
f22e037bb5 | ||
|
|
6bed3676a3 | ||
|
|
93af80f8a1 | ||
|
|
bccc36949c | ||
|
|
1a03ef926c | ||
|
|
73d2514176 | ||
|
|
3e6dff1ae8 | ||
|
|
bad8a177b7 | ||
|
|
6451f9cfd7 | ||
|
|
a2c2c71617 | ||
|
|
cbe8d90eec | ||
|
|
14c48b006f | ||
|
|
b854dc76ab | ||
|
|
066712e887 | ||
|
|
906a651140 | ||
|
|
9dad13af49 | ||
|
|
f4fd18ae5e | ||
|
|
94b0710933 | ||
|
|
8949ea9991 | ||
|
|
e34529e4b5 | ||
|
|
b4ac446eb5 | ||
|
|
9b306b8fdf | ||
|
|
7d2afad6cf | ||
|
|
7ba42aefdf | ||
|
|
80fbfb6448 | ||
|
|
c3feba43d2 | ||
|
|
367cd5004f | ||
|
|
1922aaac3f | ||
|
|
839d1736a5 | ||
|
|
c8af1231e0 | ||
|
|
5eedfcbbd5 | ||
|
|
872d0d69ef | ||
|
|
fce22f30fb | ||
|
|
bc09d55d42 | ||
|
|
e8b801fe1f | ||
|
|
6581d032ba | ||
|
|
6cefef4e22 | ||
|
|
7b62c6b4d9 | ||
|
|
44e2e1c0aa | ||
|
|
52b447ba7c | ||
|
|
9cce012684 | ||
|
|
41de45dce7 | ||
|
|
00275411e4 | ||
|
|
e4bca08f27 | ||
|
|
b5dfab6875 | ||
|
|
84226daca7 | ||
|
|
e2aee25f58 | ||
|
|
ed18f220f0 | ||
|
|
d6278f135e | ||
|
|
d7f08163aa | ||
|
|
ae9b524cf3 | ||
|
|
2cc59b540f | ||
|
|
e6e27b922c | ||
|
|
00f9911127 | ||
|
|
f271460fd1 | ||
|
|
ced2dac458 | ||
|
|
15acc159e8 | ||
|
|
7d75e8d3e1 | ||
|
|
a2a1dc0ec7 | ||
|
|
b354049b89 | ||
|
|
178bcb42a7 | ||
|
|
e0cc85ca7f | ||
|
|
8b232aeffd | ||
|
|
a937052472 | ||
|
|
8c58d13146 | ||
|
|
eb5c88da9a | ||
|
|
6926cd02cb | ||
|
|
2f257d3f95 | ||
|
|
67df0f51ca | ||
|
|
1e648cc3a1 | ||
|
|
ca8501fcdb | ||
|
|
b68a154497 | ||
|
|
e6792484af | ||
|
|
2d9d1d859c | ||
|
|
99459f6cf5 | ||
|
|
ecc6d48830 | ||
|
|
5f44ad2656 | ||
|
|
83418f3635 | ||
|
|
0b570221fc | ||
|
|
172fb32ac8 | ||
|
|
e8a00488b4 | ||
|
|
1392c41ccd | ||
|
|
373e9f7383 | ||
|
|
85aa452117 | ||
|
|
04af153741 | ||
|
|
febee04ea5 | ||
|
|
959631c340 | ||
|
|
292663f572 | ||
|
|
0604b8a341 | ||
|
|
6560b2882d | ||
|
|
755a79642e | ||
|
|
10d7ff65af | ||
|
|
5ae0dbbf3d | ||
|
|
86f48207b3 | ||
|
|
0bd0894547 | ||
|
|
e3540daa19 | ||
|
|
03bd7a962d | ||
|
|
bf6e8497d1 | ||
|
|
1cb60e6be1 | ||
|
|
ee59f14953 | ||
|
|
e293426c27 | ||
|
|
7238ad7cbb | ||
|
|
8938597acf | ||
|
|
b283516cd0 | ||
|
|
42ffc74421 | ||
|
|
4e2b031f05 | ||
|
|
3ce8c93dcb | ||
|
|
68c6a1b1a6 | ||
|
|
28b9b93146 | ||
|
|
ffd73d5e74 | ||
|
|
a83e863f58 | ||
|
|
ef4d9a7fdd | ||
|
|
642ead2f5a | ||
|
|
67e7184f5a | ||
|
|
84f0eccd5b | ||
|
|
f90537b9a5 | ||
|
|
d175fcb401 | ||
|
|
608276b484 | ||
|
|
3eeadc77fc | ||
|
|
003694d930 | ||
|
|
2cdb5b08a4 | ||
|
|
6ac412fad3 | ||
|
|
22323a65b5 | ||
|
|
14f5e6775d | ||
|
|
78678024d5 | ||
|
|
1f9e2b10f9 | ||
|
|
5944c664f1 | ||
|
|
72f77ff1a7 | ||
|
|
41efbdce8e | ||
|
|
d751d5ea2a | ||
|
|
12ef307fe6 | ||
|
|
bc672d6179 | ||
|
|
fbadf6766e | ||
|
|
41502ddefb | ||
|
|
61ca35b1b8 | ||
|
|
cbb4d5e575 | ||
|
|
b37ac428d2 | ||
|
|
f9d17a9896 |
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1 +1 @@
|
||||
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~·—‘’“”…、。《》【】一丁七万丈三上下不与丐丑专且世丘丙业丛东丝丢两严丧个丫中丰串临丸丹为主丽举乃久么义之乌乍乎乏乐乔乖乘乙九乞也习乡书乩买乱乳乾了予争事二于亏云互五井亚些亡交亥亦产亨亩享京亭亮亲人亿什仁仃仅仆仇今介仍从仑仓仔仕他仗付仙仞代令以仪们仰仲仵件价任份仿企伉伍伎伏伐休众优伙会伟传伤伦伪伯估伴伶伸伺似但位低住佐佑体何佘余佛作你佣佩佬佯佳佼使侄侈例侍供依侠侣侥侧侬侮侯侵便促俊俏俐俗保俞信俨俩俪俭修俯俱俸俺倍倏們倒倔倘候倚倜借倦倩倪债值倾假偌偏偕做停健偶偷偿傀傅傍傥储催傲傻像僧僵僻儒儡儿允元兄充兆先光克免兑兔党兢入全八公六兮兰共关兴兵其具典兹养兼兽冀内冈册再冒冕写军农冠冢冤冥冬冯冰冲决况冶冷冻净凄准凉凋凌减凑凛凝几凡凤凭凰凶出击函凿刀刁刃分切刎刑划列刘则刚创初判刨利别刮到制刹刺刻剁剂剃削剌前剐剑剔剖剥剧剩剪副割剿劈力劝办功加务劣动助努劫励劲劳劾势勇勉勘募勤勺勾勿匀包匆匕化北匙匠匪匹区医匾匿十千升午卉半华协卑卒卓单卖南博卜卞占卡卢卦卧卫卯印危即却卵卷卸卿厂厄厅历厉压厌厕厘厚原厢厥厨厮去县叁参又及友双反发叔取受变叛叟口古句另叨叩只叫召叮可台史右叵叶号司叹叽吁吃各吆合吉吊同名后吏吐向吓吕吖吗君吝吞吟否吧吩含听吭启吴吵吸吹吼吾呀呃呆呈告呐呔呕呗员呜呢呦周呱味呵呶呸呻呼命咄咋和咎咏咐咒咔咕咙咦咧咪咬咱咳咶咸咻咽咿哀品哄哇哈哉响哎哑哗哟哥哦哨哩哪哭哮哲哼唆唇唉唐唔唠唤唧唬售唯唱唾啃商啊啥啦啧啬啰啸啼啾喀喂喃善喉喊喋喏喔喘喙喜喝喧喳喵喷喻喽嗅嗓嗔嗖嗜嗟嗤嗦嗨嗬嗯嗳嗽嘀嘉嘎嘘嘛嘞嘟嘱嘲嘴嘻嘿噎噗噜噢噤器噩噪噬噱嚎嚏嚣嚷嚼囊囔囚四回因团园困围固国图圃圆圈土圣在地场圾均坊坍坎坏坐坑块坚坛坝坟坠坡坤坦坪坷垂垃型垒垢垣垫垮埃埋城域埠埤培基堂堆堇堕堡堤堪堰堵塌塑塔塘塞填塾境墓墙墚增墟墨壁壑壤士壬壮声壳壶壹处备复夏夕外夙多夜够大天太夫夭央失头夷夸夹夺奇奈奉奋奎奏契奔奖套奠奢奥女奴奶奸她好如妃妄妆妇妈妍妒妓妖妙妞妥妨妹妻妾姊始姐姑姓委姗姚姜姥姨姬姻姿威娃娄娇娘娜娟娥娲娴娶娼婆婉婕婚婢婪婴婵婶婷婿媒媚媳媵嫁嫂嫉嫌嫔嫖嫡嫣嫦嫩嬉嬷子孑孓孔孕字存孙孚孝孟季孤学孩孪孬孰孵孺孽宁它宅宇守安宋完宏宗官宙定宜宝实宠客宣室宦宫宰害宴宵家容宽宾宿寂寄寅密寇富寐寒寝寞察寡寤寨寰寸对寺寻导寿封射将尊小少尔尖尘尚尝尤尬就尴尸尹尺尼尽尾尿局屁层居屈屋屎屏屐屑展属屠屡山屹岁岂岄岌岑岔岖岗岚岛岩岭岱岳岸峙峡峨峭峰峻崇崎崔崖崩崽嵯嶂巍川州巡巢工左巧巨巫差己已巳巴巷巽巾币市布帅师希帐帔帕帖帚帜帝带席帮帷常帼帽幄幅幌幕幢干平年并幸幺幻幼幽广庄庆庇床序庐库应底店庙庚府庞废度座庭庶康庸廉廊廖延廷建廻廿开异弃弄弊式弑弓引弛弟张弥弦弭弯弱弹强归当录彝形彤彦彩彪彭彰影役彻彼往征径待徇很律徐徒徕得徙御循微德心必忆忌忍忒志忘忙忠忡忧快念忽怀态怄怅怎怒怕怖怜思怠急怦性怨怪怯总恃恋恍恐恒恕恙恢恤恨恩恭息恰恳恶恻恼悄悉悍悔悟悠患悦您悬悯悲悴情惆惊惋惑惕惚惜惟惠惦惧惨惩惬惭惮惯想惶惹惺愁愈意愚感愣愤愧愫愿慈慌慎慑慕慢慧慨慰慷憎憾懂懈懒懦懵戈戊戌戎戏成我戒或战戚戟截戮戴户戾房所扁扇扈扉手才扎扑扒打扔托扛扣执扩扫扬扭扮扯扰扳扶批找承技抄把抑抓投抖抗折抚抛抟抢护报披抬抱抵抹押抽拂担拆拈拉拋拍拎拐拒拓拔拖拘拙招拜拟拢拣拥拦拧拨择括拯拳拷拼拽拾拿持挂指按挑挖挟挠挡挣挤挥挨挪挫振挺挽捅捆捉捌捎捏捐捕捞损捡换捣捧据捶捷掀掂授掉掌掏掐排掘掙掠探接控推掩措掳掷掺揉揍描提插揖握揣揪揭援搁搂搅搏搓搔搜搞搬搭携摄摆摇摈摊摔摘摧摩摸撇撑撒撕撞撤播撰擂擅操擎擒擦攀攒攫支收攸改攻放政故效敌敏救教敛敝敞敢散敬数敲整敷文斋斐斑斗料斛斜斟斤斥斧斩断斯新方於施旁旅旋族旗无既日旦旧旨早旬旭旱时旷旺昂昆昊昌明昏易昔昕昙星映春昧昨昭是昴昼显晃晋晌晒晓晕晖晚晦晧晨普景晰晴晶智晾暂暄暇暑暖暗暮暴曜曦曰曲曳更曹曾替最月有朋服朔朗望朝期木未末本术朱朴朵机朽杀杂权杆杈杉李杏材村杖杜杞束杠条来杨杭杯杰杳杵松板极构枉枕林枚果枝枢枣枪枫枯架枷柄柏某Line truncated
|
||||
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~·—‘’“”…、。《》【】!(),:;?~+一丁七万丈三上下不与丐丑专且世丘丙业丛东丝丢两严丧个丫中丰串临丸丹为主丽举乃久么义之乌乍乎乏乐乔乖乘乙九乞也习乡书乩买乱乳乾了予争事二于亏云互五井亚些亡交亥亦产亨亩享京亭亮亲人亿什仁仃仅仆仇今介仍从仑仓仔仕他仗付仙仞代令以仪们仰仲仵件价任份仿企伉伍伎伏伐休众优伙会伟传伤伦伪伯估伴伶伸伺似但位低住佐佑体何佘余佛作你佣佩佬佯佳佼使侄侈例侍供依侠侣侥侧侬侮侯侵便促俊俏俐俗保俞信俨俩俪俭修俯俱俸俺倍倏們倒倔倘候倚倜借倦倩倪债值倾假偌偏偕做停健偶偷偿傀傅傍傥储催傲傻像僧僵僻儒儡儿允元兄充兆先光克免兑兔党兢入全八公六兮兰共关兴兵其具典兹养兼兽冀内冈册再冒冕写军农冠冢冤冥冬冯冰冲决况冶冷冻净凄准凉凋凌减凑凛凝几凡凤凭凰凶出击函凿刀刁刃分切刎刑划列刘则刚创初判刨利别刮到制刹刺刻剁剂剃削剌前剐剑剔剖剥剧剩剪副割剿劈力劝办功加务劣动助努劫励劲劳劾势勇勉勘募勤勺勾勿匀包匆匕化北匙匠匪匹区医匾匿十千升午卉半华协卑卒卓单卖南博卜卞占卡卢卦卧卫卯印危即却卵卷卸卿厂厄厅历厉压厌厕厘厚原厢厥厨厮去县叁参又及友双反发叔取受变叛叟口古句另叨叩只叫召叮可台史右叵叶号司叹叽吁吃各吆合吉吊同名后吏吐向吓吕吖吗君吝吞吟否吧吩含听吭启吴吵吸吹吼吾呀呃呆呈告呐呔呕呗员呜呢呦周呱味呵呶呸呻呼命咄咋和咎咏咐咒咔咕咙咦咧咪咬咱咳咶咸咻咽咿哀品哄哇哈哉响哎哑哗哟哥哦哨哩哪哭哮哲哼唆唇唉唐唔唠唤唧唬售唯唱唾啃商啊啥啦啧啬啰啸啼啾喀喂喃善喉喊喋喏喔喘喙喜喝喧喳喵喷喻喽嗅嗓嗔嗖嗜嗟嗤嗦嗨嗬嗯嗳嗽嘀嘉嘎嘘嘛嘞嘟嘱嘲嘴嘻嘿噎噗噜噢噤器噩噪噬噱嚎嚏嚣嚷嚼囊囔囚四回因团园困围固国图圃圆圈土圣在地场圾均坊坍坎坏坐坑块坚坛坝坟坠坡坤坦坪坷垂垃型垒垢垣垫垮埃埋城域埠埤培基堂堆堇堕堡堤堪堰堵塌塑塔塘塞填塾境墓墙墚增墟墨壁壑壤士壬壮声壳壶壹处备复夏夕外夙多夜够大天太夫夭央失头夷夸夹夺奇奈奉奋奎奏契奔奖套奠奢奥女奴奶奸她好如妃妄妆妇妈妍妒妓妖妙妞妥妨妹妻妾姊始姐姑姓委姗姚姜姥姨姬姻姿威娃娄娇娘娜娟娥娲娴娶娼婆婉婕婚婢婪婴婵婶婷婿媒媚媳媵嫁嫂嫉嫌嫔嫖嫡嫣嫦嫩嬉嬷子孑孓孔孕字存孙孚孝孟季孤学孩孪孬孰孵孺孽宁它宅宇守安宋完宏宗官宙定宜宝实宠客宣室宦宫宰害宴宵家容宽宾宿寂寄寅密寇富寐寒寝寞察寡寤寨寰寸对寺寻导寿封射将尊小少尔尖尘尚尝尤尬就尴尸尹尺尼尽尾尿局屁层居屈屋屎屏屐屑展属屠屡山屹岁岂岄岌岑岔岖岗岚岛岩岭岱岳岸峙峡峨峭峰峻崇崎崔崖崩崽嵯嶂巍川州巡巢工左巧巨巫差己已巳巴巷巽巾币市布帅师希帐帔帕帖帚帜帝带席帮帷常帼帽幄幅幌幕幢干平年并幸幺幻幼幽广庄庆庇床序庐库应底店庙庚府庞废度座庭庶康庸廉廊廖延廷建廻廿开异弃弄弊式弑弓引弛弟张弥弦弭弯弱弹强归当录彝形彤彦彩彪彭彰影役彻彼往征径待徇很律徐徒徕得徙御循微德心必忆忌忍忒志忘忙忠忡忧快念忽怀态怄怅怎怒怕怖怜思怠急怦性怨怪怯总恃恋恍恐恒恕恙恢恤恨恩恭息恰恳恶恻恼悄悉悍悔悟悠患悦您悬悯悲悴情惆惊惋惑惕惚惜惟惠惦惧惨惩惬惭惮惯想惶惹惺愁愈意愚感愣愤愧愫愿慈慌慎慑慕慢慧慨慰慷憎憾懂懈懒懦懵戈戊戌戎戏成我戒或战戚戟截戮戴户戾房所扁扇扈扉手才扎扑扒打扔托扛扣执扩扫扬扭扮扯扰扳扶批找承技抄把抑抓投抖抗折抚抛抟抢护报披抬抱抵抹押抽拂担拆拈拉拋拍拎拐拒拓拔拖拘拙招拜拟拢拣拥拦拧拨择括拯拳拷拼拽拾拿持挂指按挑挖挟挠挡挣挤挥挨挪挫振挺挽捅捆捉捌捎捏捐捕捞损捡换捣捧据捶捷掀掂授掉掌掏掐排掘掙掠探接控推掩措掳掷掺揉揍描提插揖握揣揪揭援搁搂搅搏搓搔搜搞搬搭携摄摆摇摈摊摔摘摧摩摸撇撑撒撕撞撤播撰擂擅操擎擒擦攀攒攫支收攸改攻放政故效敌敏救教敛敝敞敢散敬数敲整敷文斋斐斑斗料斛斜斟斤斥斧斩断斯新方於施旁旅旋族旗无既日旦旧旨早旬旭旱时旷旺昂昆昊昌明昏易昔昕昙星映春昧昨昭是昴昼显晃晋晌晒晓晕晖晚晦晧晨普景晰晴晶智晾暂暄暇暑暖暗暮暴曜曦曰曲曳更曹曾替最月有朋服朔朗望朝期木未末本术朱朴朵机朽杀杂权杆杈杉李杏材村杖杜杞束杠条来杨杭杯杰杳杵松板极构枉枕林枚果枝枢Line truncated
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: c1cb7e9e120078f43bce4f0b1be547a7, type: 3}
|
||||
m_Name: AmbientOcclusion
|
||||
m_EditorClassIdentifier:
|
||||
active: 1
|
||||
active: 0
|
||||
enabled:
|
||||
overrideState: 1
|
||||
value: 1
|
||||
@@ -1484,7 +1484,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 48a79b01ea5641d4aa6daa2e23605641, type: 3}
|
||||
m_Name: Bloom
|
||||
m_EditorClassIdentifier:
|
||||
active: 1
|
||||
active: 0
|
||||
enabled:
|
||||
overrideState: 1
|
||||
value: 1
|
||||
|
||||
@@ -203,9 +203,17 @@ Camera:
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_Iso: 200
|
||||
m_ShutterSpeed: 0.005
|
||||
m_Aperture: 16
|
||||
m_FocusDistance: 10
|
||||
m_FocalLength: 50
|
||||
m_BladeCount: 5
|
||||
m_Curvature: {x: 2, y: 11}
|
||||
m_BarrelClipping: 0.25
|
||||
m_Anamorphism: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
@@ -395,7 +403,9 @@ MonoBehaviour:
|
||||
breakBeforeColorGrading: 0
|
||||
m_BeforeTransparentBundles: []
|
||||
m_BeforeStackBundles: []
|
||||
m_AfterStackBundles: []
|
||||
m_AfterStackBundles:
|
||||
- assemblyQualifiedName: Pal3.Effect.PostProcessing.Distortion, Pal3, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
--- !u!1 &768200630232143376
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -457,6 +467,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 0
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 9999
|
||||
m_TargetDisplay: 0
|
||||
@@ -951,7 +962,7 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 160, y: 160}
|
||||
m_AnchoredPosition: {x: 180, y: 160}
|
||||
m_SizeDelta: {x: 160, y: 160}
|
||||
m_Pivot: {x: 0, y: 0}
|
||||
--- !u!222 &1806521128227818516
|
||||
@@ -1005,7 +1016,28 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_MovementRange: 90
|
||||
m_DynamicOriginRange: 100
|
||||
m_ControlPath: <Joystick>/stick
|
||||
m_Behaviour: 0
|
||||
m_UseIsolatedInputActions: 0
|
||||
m_PointerDownAction:
|
||||
m_Name:
|
||||
m_Type: 0
|
||||
m_ExpectedControlType:
|
||||
m_Id:
|
||||
m_Processors:
|
||||
m_Interactions:
|
||||
m_SingletonActionBindings: []
|
||||
m_Flags: 0
|
||||
m_PointerMoveAction:
|
||||
m_Name:
|
||||
m_Type: 0
|
||||
m_ExpectedControlType:
|
||||
m_Id:
|
||||
m_Processors:
|
||||
m_Interactions:
|
||||
m_SingletonActionBindings: []
|
||||
m_Flags: 0
|
||||
--- !u!1 &1497448014832900950
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1223,6 +1255,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 0
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
@@ -1611,6 +1644,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 0
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
@@ -1714,6 +1748,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 999
|
||||
m_TargetDisplay: 0
|
||||
@@ -1828,6 +1863,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 1000
|
||||
m_TargetDisplay: 0
|
||||
@@ -1956,6 +1992,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 1000
|
||||
m_TargetDisplay: 0
|
||||
@@ -2314,6 +2351,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
@@ -3225,6 +3263,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 0
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 10001
|
||||
m_TargetDisplay: 0
|
||||
@@ -3422,6 +3461,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 1000
|
||||
m_TargetDisplay: 0
|
||||
@@ -3557,6 +3597,7 @@ VideoPlayer:
|
||||
m_RenderMode: 2
|
||||
m_AspectRatio: 2
|
||||
m_DataSource: 0
|
||||
m_TimeUpdateMode: 2
|
||||
m_PlaybackSpeed: 1
|
||||
m_AudioOutputMode: 2
|
||||
m_TargetAudioSources:
|
||||
@@ -3635,6 +3676,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 10000
|
||||
m_TargetDisplay: 0
|
||||
@@ -3736,6 +3778,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
@@ -3836,6 +3879,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
@@ -4305,6 +4349,7 @@ Canvas:
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
@@ -4313,6 +4358,7 @@ PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 8627381932629902483}
|
||||
m_Modifications:
|
||||
- target: {fileID: 2675203688159455099, guid: 3ef1d32c83f86744286e2067bc5f73e4, type: 3}
|
||||
@@ -4592,6 +4638,9 @@ PrefabInstance:
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 3ef1d32c83f86744286e2067bc5f73e4, type: 3}
|
||||
--- !u!224 &9166793672834059380 stripped
|
||||
RectTransform:
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
297 => 紫萱施法召唤水灵特效
|
||||
337 => 古藤精风系法术特效
|
||||
341 => 邪剑仙给镇妖剑施法特效
|
||||
368 => 龙葵雷击单体施法特效
|
||||
369 => 龙葵雷击范围施法特效
|
||||
368 => 雷击单体施法特效
|
||||
369 => 雷击范围施法特效
|
||||
376 => 紫萱的土系法术特效
|
||||
389 => 紫萱给江姑娘施法特效
|
||||
452 => 花楹治疗他人特效
|
||||
|
||||
@@ -1,4 +1,67 @@
|
||||
因为当前特效的实现方式使用了第三方插件和素材,所以此文件夹内的所有prefab均添加进了gitignore里。
|
||||
请联系作者了解插件获取方式和特效prefab的获取方式。
|
||||
|
||||
0 => 传送法阵特效
|
||||
0 => 传送法阵特效
|
||||
9 => 茅山道士封印法术特效
|
||||
40 => 单体风咒特效
|
||||
50 => 单体雷咒特效
|
||||
91 => 封印法术特效
|
||||
157 => 角色传送出现特效
|
||||
164 => 南宫煌变身狼形态时的特效
|
||||
170 => 王蓬絮变身特效
|
||||
171 => 人物施法特效
|
||||
172 => 人物受到法术作用时候的特效
|
||||
173 => 人物受到法术作用时候的特效
|
||||
174 => 治疗特效
|
||||
175 => 茅山术士打乱三杯盏特效
|
||||
176 => 南宫煌打乱三杯盏特效
|
||||
177 => 角色传送消失时的特效
|
||||
178 => 南宫煌使关桃子的笼子消失的特效
|
||||
179 => 南宫煌变出法桌的特效
|
||||
181 => 南宫煌变出小东西的特效
|
||||
182 => 南宫煌变出大东西的特效
|
||||
186 => 大石块砸下后的尘土特效
|
||||
189 => 地脉石门封印打开时的特效
|
||||
198 => 南宫煌变出东西的特效
|
||||
201 => 魁妖变小特效
|
||||
205 => 照妖镜发光的特效
|
||||
209 => 五灵轮特效
|
||||
211 => 洒金笺特效
|
||||
230 => 重楼施法消灭怪物的特效
|
||||
254 => 重楼传送特效
|
||||
257 => 隔空取物特效
|
||||
258 => 迴魂传送特效
|
||||
259 => 大型传送法施法前奏特效
|
||||
260 => 大型传送法阵特效收尾
|
||||
261 => 大型传送法阵特效开始
|
||||
281 => 角色传送消失时的特效
|
||||
282 => 雷咒特效
|
||||
283 => 物品消失时的特效
|
||||
285 => 南宫煌施法特效
|
||||
287 => 土灵珠特效
|
||||
289 => 血魂姬施法特效
|
||||
290 => 回复法阵特效
|
||||
292 => 五灵轮发光特效
|
||||
299 => 重楼传送众人特效
|
||||
314 => 倾国银弹波特效
|
||||
315 => 南宫煌切换为人形态特效
|
||||
316 => 魔物出现特效
|
||||
318 => 千凝魔艮特效
|
||||
320 => 幽娘变身特效
|
||||
322 => 幽娘吸收怨气特效
|
||||
323 => 幽娘收集怨气特效
|
||||
325 => 陆北亭变身特效
|
||||
328 => 风雅颂开心的特效
|
||||
333 => 感月出现特效
|
||||
355 => 王蓬絮治疗特效
|
||||
359 => 蝎魃消失特效
|
||||
360 => 星璇给南宫煌输入内力时的特效
|
||||
367 => 五毒珠治疗特效
|
||||
388 => 迴魂传送特效
|
||||
389 => 迴魂传送特效
|
||||
397 => 燎日变身特效
|
||||
401 => 魔尊帮星璇灵肉合一的特效
|
||||
404 => 思堂消失特效
|
||||
408 => 星璇燎日变换时特效
|
||||
424 => 王蓬絮对南宫煌施法特效
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ RenderTexture:
|
||||
m_Height: 448
|
||||
m_AntiAliasing: 1
|
||||
m_MipCount: -1
|
||||
m_DepthStencilFormat: 94
|
||||
m_DepthStencilFormat: 90
|
||||
m_ColorFormat: 8
|
||||
m_MipMap: 0
|
||||
m_GenerateMips: 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Build.Editor
|
||||
#elif PAL3A
|
||||
string plistPath = pathToBuiltProject + "/PAL3A/Info.plist";
|
||||
#endif
|
||||
|
||||
|
||||
PlistDocument plist = new PlistDocument();
|
||||
plist.ReadFromString(File.ReadAllText(plistPath));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -282,8 +282,8 @@ namespace Core.Algorithm.PathFinding
|
||||
int x1 = end.X;
|
||||
int y1 = end.Y;
|
||||
|
||||
int dx = Math.Abs(x1 - x0);
|
||||
int dy = Math.Abs(y1 - y0);
|
||||
int dx = Mathf.Abs(x1 - x0);
|
||||
int dy = Mathf.Abs(y1 - y0);
|
||||
int sx = x0 < x1 ? 1 : -1;
|
||||
int sy = y0 < y1 ? 1 : -1;
|
||||
int err = dx - dy;
|
||||
|
||||
@@ -339,7 +339,7 @@
|
||||
public TItem First => _nodes[1];
|
||||
|
||||
/// <summary>
|
||||
/// This method must be called on a node every time its priority changes while it is in the queue.
|
||||
/// This method must be called on a node every time its priority changes while it is in the queue.
|
||||
/// <b>Forgetting to call this method will result in a corrupted queue!</b>
|
||||
/// Calling this method on a node not in the queue results in undefined behavior
|
||||
/// O(log n)
|
||||
@@ -369,7 +369,7 @@
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a node from the queue. The node does not need to be the head of the queue.
|
||||
/// Removes a node from the queue. The node does not need to be the head of the queue.
|
||||
/// If the node is not in the queue, the result is undefined. If unsure, check Contains() first
|
||||
/// O(log n)
|
||||
/// </summary>
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
bool Contains(TItem node);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a node from the queue. The node does not need to be the head of the queue.
|
||||
/// Removes a node from the queue. The node does not need to be the head of the queue.
|
||||
/// </summary>
|
||||
void Remove(TItem node);
|
||||
|
||||
/// <summary>
|
||||
/// Call this method to change the priority of a node.
|
||||
/// Call this method to change the priority of a node.
|
||||
/// </summary>
|
||||
void UpdatePriority(TItem node, TPriority priority);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
public SimplePriorityQueue(Comparison<TPriority> priorityComparer) : this(priorityComparer, EqualityComparer<TItem>.Default) { }
|
||||
|
||||
/// <summary>
|
||||
/// Instantiate a new Priority Queue
|
||||
/// Instantiate a new Priority Queue
|
||||
/// </summary>
|
||||
/// <param name="itemEquality">The equality comparison function to use to compare TItem values</param>
|
||||
public SimplePriorityQueue(IEqualityComparer<TItem> itemEquality) : this(Comparer<TPriority>.Default, itemEquality) { }
|
||||
@@ -309,9 +309,9 @@
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an item from the queue. The item does not need to be the head of the queue.
|
||||
/// Removes an item from the queue. The item does not need to be the head of the queue.
|
||||
/// If the item is not in the queue, an exception is thrown. If unsure, check Contains() first.
|
||||
/// If multiple copies of the item are enqueued, only the first one is removed.
|
||||
/// If multiple copies of the item are enqueued, only the first one is removed.
|
||||
/// O(log n)
|
||||
/// </summary>
|
||||
public void Remove(TItem item)
|
||||
@@ -432,16 +432,16 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
first = default(TItem);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to remove an item from the queue. The item does not need to be the head of the queue.
|
||||
/// Attempts to remove an item from the queue. The item does not need to be the head of the queue.
|
||||
/// Useful for multi-threading, where the queue may become empty between calls to Contains() and Remove()
|
||||
/// Returns true if the item was successfully removed, false if it wasn't in the queue.
|
||||
/// If multiple copies of the item are enqueued, only the first one is removed.
|
||||
/// If multiple copies of the item are enqueued, only the first one is removed.
|
||||
/// O(log n)
|
||||
/// </summary>
|
||||
public bool TryRemove(TItem item)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Core.Animation
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerator EnumerateValue(float from,
|
||||
public static IEnumerator EnumerateValueAsync(float from,
|
||||
float to,
|
||||
float duration,
|
||||
AnimationCurveType curveType,
|
||||
@@ -57,12 +57,12 @@ namespace Core.Animation
|
||||
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
onValueChanged?.Invoke(to);
|
||||
onValueChanged?.Invoke(to);
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public static IEnumerator MoveTransform(Transform target,
|
||||
public static IEnumerator MoveTransformAsync(Transform target,
|
||||
Vector3 toPosition,
|
||||
float duration,
|
||||
AnimationCurveType curveType = AnimationCurveType.Linear,
|
||||
@@ -83,7 +83,7 @@ namespace Core.Animation
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public static IEnumerator ShakeTransform(Transform target,
|
||||
public static IEnumerator ShakeTransformAsync(Transform target,
|
||||
float duration,
|
||||
float amplitude,
|
||||
bool shakeOnXAxis,
|
||||
@@ -107,7 +107,7 @@ namespace Core.Animation
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public static IEnumerator OrbitTransformAroundCenterPoint(Transform target,
|
||||
public static IEnumerator OrbitTransformAroundCenterPointAsync(Transform target,
|
||||
Quaternion toRotation,
|
||||
Vector3 centerPoint,
|
||||
float duration,
|
||||
@@ -139,11 +139,11 @@ namespace Core.Animation
|
||||
target.rotation = toRotation;
|
||||
target.position = centerPoint + (toRotation * Vector3.forward).normalized * -(distance + distanceDelta);
|
||||
}
|
||||
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public static IEnumerator RotateTransform(Transform target,
|
||||
public static IEnumerator RotateTransformAsync(Transform target,
|
||||
Quaternion toRotation,
|
||||
float duration,
|
||||
AnimationCurveType curveType,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -17,9 +17,10 @@ namespace Core.DataLoader
|
||||
/// </summary>
|
||||
/// <param name="filePath">Audio file path</param>
|
||||
/// <param name="audioType">Audio type</param>
|
||||
/// <param name="streamAudio">Create streaming AudioClip</param>
|
||||
/// <param name="callback">AudioClip callback invoker</param>
|
||||
/// <returns>IEnumerator</returns>
|
||||
public static IEnumerator LoadAudioClip(string filePath, AudioType audioType, Action<AudioClip> callback)
|
||||
public static IEnumerator LoadAudioClipAsync(string filePath, AudioType audioType, bool streamAudio, Action<AudioClip> callback)
|
||||
{
|
||||
if (filePath.StartsWith("/")) filePath = filePath[1..];
|
||||
|
||||
@@ -36,6 +37,10 @@ namespace Core.DataLoader
|
||||
{
|
||||
try
|
||||
{
|
||||
// Stream audio to avoid loading the entire AudioClip into memory at once,
|
||||
// which can cause frame drops and stuttering during gameplay.
|
||||
((DownloadHandlerAudioClip) request.downloadHandler).streamAudio = streamAudio;
|
||||
|
||||
AudioClip audioClip = DownloadHandlerAudioClip.GetContent(request);
|
||||
callback?.Invoke(audioClip);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace Core.DataLoader
|
||||
public interface ITextureResourceProvider
|
||||
{
|
||||
string GetTexturePath(string name);
|
||||
|
||||
|
||||
Texture2D GetTexture(string name);
|
||||
|
||||
|
||||
Texture2D GetTexture(string name, out bool hasAlphaChannel);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Core.DataReader.Cpk
|
||||
private readonly Dictionary<uint, byte[]> _fileNameMap = new ();
|
||||
private readonly Dictionary<uint, uint> _crcToTableIndexMap = new ();
|
||||
private readonly Dictionary<uint, HashSet<uint>> _fatherCrcToChildCrcTableIndexMap = new ();
|
||||
|
||||
|
||||
private bool _archiveInMemory;
|
||||
private byte[] _archiveData;
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Core.DataReader.Cpk
|
||||
{
|
||||
ExtractToInternal(outputFolder, GetRootEntries());
|
||||
}
|
||||
|
||||
|
||||
private void ExtractToInternal(string outputFolder, IEnumerable<CpkEntry> nodes)
|
||||
{
|
||||
foreach (CpkEntry node in nodes)
|
||||
@@ -121,7 +121,7 @@ namespace Core.DataReader.Cpk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if file exists inside the archive.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -25,17 +25,11 @@ namespace Core.DataReader.Cpk
|
||||
for (uint i = 0; i < CRC_TABLE_MAX; i++)
|
||||
{
|
||||
var crcAccum = i << 24;
|
||||
|
||||
for (var j = 0; j < 8; j++)
|
||||
{
|
||||
if ((crcAccum & 0x80000000L) != 0)
|
||||
{
|
||||
crcAccum = (crcAccum << 1) ^ POLYNOMIAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
crcAccum = (crcAccum << 1);
|
||||
}
|
||||
crcAccum = (crcAccum & 0x80000000L) != 0 ?
|
||||
(crcAccum << 1) ^ POLYNOMIAL :
|
||||
crcAccum << 1;
|
||||
}
|
||||
CrcTable[i] = crcAccum;
|
||||
}
|
||||
@@ -51,35 +45,29 @@ namespace Core.DataReader.Cpk
|
||||
|
||||
private unsafe uint ComputeCrc32HashInternal(byte[] data)
|
||||
{
|
||||
if (!_initialized) throw new Exception("CrcHash not initialized yet.");
|
||||
if (!_initialized) throw new InvalidOperationException("CrcHash not initialized yet.");
|
||||
|
||||
var length = data.Length;
|
||||
if (length == 0 || data[0] == 0) return 0;
|
||||
|
||||
var index = 0;
|
||||
fixed (byte* srcStart = &data[0])
|
||||
if (data == null || data.Length == 0 || data[0] == 0)
|
||||
{
|
||||
var p = srcStart;
|
||||
uint result = (uint)(*(p + index++) << 24);
|
||||
if (index < length && *(p + index) != 0)
|
||||
{
|
||||
result |= (uint)(*(p + index++) << 16);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(index < length && *(p + index) != 0)
|
||||
{
|
||||
result |= (uint)(*(p + index++) << 8);
|
||||
if (index < length && *(p + index) != 0)
|
||||
{
|
||||
result |= *(p + index++);
|
||||
}
|
||||
}
|
||||
fixed (byte* srcStart = data)
|
||||
{
|
||||
byte* ptr = srcStart;
|
||||
uint result = (uint)(*ptr++ << 24);
|
||||
|
||||
for (int i = 1; i < 4 && i < data.Length; i++)
|
||||
{
|
||||
if (*ptr == 0) break;
|
||||
result |= (uint)(*ptr++ << (24 - 8 * i));
|
||||
}
|
||||
|
||||
result = ~result;
|
||||
|
||||
while (index < length && *(p + index) != 0)
|
||||
for (int i = 4; i < data.Length && *ptr != 0; i++, ptr++)
|
||||
{
|
||||
result = (result << 8 | *(p + index)) ^ CrcTable[result >> 24];
|
||||
index++;
|
||||
result = (result << 8 | *ptr) ^ CrcTable[result >> 24];
|
||||
}
|
||||
|
||||
return ~result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -362,6 +362,9 @@ namespace Core.DataReader.Cvd
|
||||
Vector3 normal = GameBoxInterpreter.ToUnityNormal(reader.ReadVector3());
|
||||
Vector3 position = GameBoxInterpreter.CvdPositionToUnityPosition(reader.ReadVector3());
|
||||
|
||||
// Quick fix for the missing/wrong normals
|
||||
if (normal == Vector3.zero) normal = Vector3.up;
|
||||
|
||||
vertices[j] = new CvdVertex()
|
||||
{
|
||||
Normal = normal,
|
||||
@@ -419,12 +422,12 @@ namespace Core.DataReader.Cvd
|
||||
|
||||
var numberOfIndices = reader.ReadInt32();
|
||||
|
||||
var indices = new (short x, short y, short z)[numberOfIndices];
|
||||
var indices = new (ushort x, ushort y, ushort z)[numberOfIndices];
|
||||
for (var i = 0; i < numberOfIndices; i++)
|
||||
{
|
||||
var x = reader.ReadInt16();
|
||||
var y = reader.ReadInt16();
|
||||
var z = reader.ReadInt16();
|
||||
var x = reader.ReadUInt16();
|
||||
var y = reader.ReadUInt16();
|
||||
var z = reader.ReadUInt16();
|
||||
indices[i] = (x, y, z);
|
||||
}
|
||||
|
||||
@@ -455,12 +458,11 @@ namespace Core.DataReader.Cvd
|
||||
}
|
||||
|
||||
var frameVertices = new CvdVertex[allFrameVertices.Length][];
|
||||
List<int> triangles;
|
||||
List<int> indexBuffer;
|
||||
|
||||
(triangles, indexBuffer) = CalculateTriangles(indices);
|
||||
(List<int> triangles, List<int> indexBuffer) = CalculateTriangles(indices);
|
||||
|
||||
GameBoxInterpreter.ToUnityTriangles(triangles);
|
||||
|
||||
|
||||
for (var i = 0; i < allFrameVertices.Length; i++)
|
||||
{
|
||||
var verts = new CvdVertex[indexBuffer.Count];
|
||||
@@ -487,11 +489,11 @@ namespace Core.DataReader.Cvd
|
||||
}
|
||||
|
||||
private static (List<int> triangles, List<int> indexBuffer) CalculateTriangles(
|
||||
(short x, short y, short z)[] allIndices)
|
||||
(ushort x, ushort y, ushort z)[] allIndices)
|
||||
{
|
||||
var indexBuffer = new List<int>();
|
||||
var triangles = new List<int>();
|
||||
var indexMap = new Dictionary<int, int>();
|
||||
var index = 0;
|
||||
|
||||
for (var j = 0; j < allIndices.Length; j++)
|
||||
{
|
||||
@@ -504,17 +506,8 @@ namespace Core.DataReader.Cvd
|
||||
|
||||
for (var k = 0; k < 3; k++)
|
||||
{
|
||||
if (indexMap.ContainsKey(indices[k]))
|
||||
{
|
||||
triangles.Add(indexMap[indices[k]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var index = indexBuffer.Count;
|
||||
indexBuffer.Add(indices[k]);
|
||||
indexMap[indices[k]] = index;
|
||||
triangles.Add(index);
|
||||
}
|
||||
indexBuffer.Add(indices[k]);
|
||||
triangles.Add(index++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -7,19 +7,19 @@ namespace Core.DataReader.Data
|
||||
{
|
||||
//using System.Runtime.InteropServices;
|
||||
|
||||
//[StructLayout(LayoutKind.Explicit)]
|
||||
//[StructLayout(LayoutKind.Explicit)]
|
||||
public struct EffectDefinition
|
||||
{
|
||||
//[FieldOffset(0)]
|
||||
public uint ClassNameCrc;
|
||||
|
||||
|
||||
//[FieldOffset(4)]
|
||||
//[MarshalAs (UnmanagedType.ByValArray, SizeConst = 30)]
|
||||
public string TypeName;
|
||||
|
||||
|
||||
//[FieldOffset(36)]
|
||||
public uint TypeNameCrc;
|
||||
|
||||
|
||||
//[FieldOffset(40)]
|
||||
//[MarshalAs (UnmanagedType.ByValArray, SizeConst = 128)]
|
||||
// Union
|
||||
@@ -30,22 +30,22 @@ namespace Core.DataReader.Data
|
||||
|
||||
//[FieldOffset(168)]
|
||||
public int FramesPerRow;
|
||||
|
||||
|
||||
//[FieldOffset(172)]
|
||||
public int FramesPerColumn;
|
||||
|
||||
|
||||
//[FieldOffset(176)]
|
||||
public int FrameCount;
|
||||
|
||||
|
||||
//[FieldOffset(180)]
|
||||
public float FramePerSecond;
|
||||
|
||||
|
||||
//[FieldOffset(184)]
|
||||
public float InitXPosition;
|
||||
|
||||
|
||||
//[FieldOffset(188)]
|
||||
public float InitYPosition;
|
||||
|
||||
|
||||
//[FieldOffset(192)]
|
||||
public float InitZPosition;
|
||||
|
||||
@@ -53,75 +53,75 @@ namespace Core.DataReader.Data
|
||||
// Union
|
||||
public float InitYRotation;
|
||||
public float InitAngle;
|
||||
|
||||
|
||||
//[FieldOffset(200)]
|
||||
public int InitSize;
|
||||
|
||||
|
||||
//[FieldOffset(204)]
|
||||
public uint InitColor;
|
||||
|
||||
public uint InitColor;
|
||||
|
||||
//[FieldOffset(208)]
|
||||
public int MaxQuadCount;
|
||||
|
||||
|
||||
//[FieldOffset(212)]
|
||||
public bool IsValid;
|
||||
|
||||
|
||||
//[FieldOffset(213)]
|
||||
public bool IsAdditiveBlend;
|
||||
|
||||
|
||||
//[FieldOffset(214)]
|
||||
public bool IsBillboard;
|
||||
|
||||
|
||||
//[FieldOffset(215)]
|
||||
public bool IsZTestIgnored;
|
||||
|
||||
|
||||
//[FieldOffset(216)]
|
||||
public float InitXRotation;
|
||||
|
||||
|
||||
//[FieldOffset(220)]
|
||||
public float InitZRotation;
|
||||
|
||||
|
||||
//[FieldOffset(224)]
|
||||
public float RotationAngle;
|
||||
|
||||
|
||||
//[FieldOffset(228)]
|
||||
public float Width;
|
||||
|
||||
|
||||
//[FieldOffset(232)]
|
||||
public float DivisionCount;
|
||||
|
||||
|
||||
//[FieldOffset(236)]
|
||||
public float TopShrink;
|
||||
|
||||
|
||||
//[FieldOffset(240)]
|
||||
public float BottomShrink;
|
||||
|
||||
|
||||
//[FieldOffset(244)]
|
||||
public float TopRadius;
|
||||
|
||||
|
||||
//[FieldOffset(248)]
|
||||
public float BottomRadius;
|
||||
|
||||
|
||||
//[FieldOffset(252)]
|
||||
public float TopRadiusIncreaseSpeed;
|
||||
|
||||
|
||||
//[FieldOffset(256)]
|
||||
public float BottomRadiusIncreaseSpeed;
|
||||
|
||||
|
||||
//[FieldOffset(260)]
|
||||
public float TopRiseSpeed;
|
||||
|
||||
|
||||
//[FieldOffset(264)]
|
||||
public float BottomRiseSpeed;
|
||||
|
||||
|
||||
//[FieldOffset(268)]
|
||||
public float TextureRepeat;
|
||||
|
||||
|
||||
//[FieldOffset(272)]
|
||||
//[MarshalAs (UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
public float[] Param;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EffectDefinitionFile
|
||||
{
|
||||
public EffectDefinition[] EffectDefinitions;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -10,11 +10,11 @@ namespace Core.DataReader.Data
|
||||
using System.IO;
|
||||
using Extensions;
|
||||
using Utils;
|
||||
|
||||
|
||||
public static class EffectDefinitionFileReader
|
||||
{
|
||||
private const int NUM_OF_EFFECTS = 1324;
|
||||
|
||||
|
||||
public static void Read(byte[] data, int codepage)
|
||||
{
|
||||
#if USE_UNSAFE_BINARY_READER
|
||||
@@ -50,14 +50,14 @@ namespace Core.DataReader.Data
|
||||
effectDefinition.TextureName = unionStr;
|
||||
effectDefinition.ParticleFileName = unionStr;
|
||||
effectDefinition.SfxFileNamePrefix = unionStr;
|
||||
effectDefinition.VideoFileNamePrefix = unionStr;
|
||||
effectDefinition.VideoFileNamePrefix = unionStr;
|
||||
}
|
||||
|
||||
effectDefinition.FramesPerRow = reader.ReadInt32();
|
||||
effectDefinition.FramesPerColumn = reader.ReadInt32();
|
||||
effectDefinition.FrameCount = reader.ReadInt32();
|
||||
effectDefinition.FramePerSecond = reader.ReadSingle();
|
||||
|
||||
|
||||
effectDefinition.InitXPosition = reader.ReadSingle();
|
||||
effectDefinition.InitYPosition = reader.ReadSingle();
|
||||
effectDefinition.InitZPosition = reader.ReadSingle();
|
||||
@@ -72,15 +72,15 @@ namespace Core.DataReader.Data
|
||||
effectDefinition.InitSize = reader.ReadInt32();
|
||||
effectDefinition.InitColor = reader.ReadUInt32();
|
||||
effectDefinition.MaxQuadCount = reader.ReadInt32();
|
||||
|
||||
|
||||
effectDefinition.IsValid = reader.ReadBoolean();
|
||||
effectDefinition.IsAdditiveBlend = reader.ReadBoolean();
|
||||
effectDefinition.IsBillboard = reader.ReadBoolean();
|
||||
effectDefinition.IsZTestIgnored = reader.ReadBoolean();
|
||||
|
||||
|
||||
effectDefinition.InitXRotation = reader.ReadSingle();
|
||||
effectDefinition.InitZRotation = reader.ReadSingle();
|
||||
|
||||
|
||||
effectDefinition.RotationAngle = reader.ReadSingle();
|
||||
effectDefinition.Width = reader.ReadSingle();
|
||||
effectDefinition.DivisionCount = reader.ReadSingle();
|
||||
@@ -92,7 +92,7 @@ namespace Core.DataReader.Data
|
||||
effectDefinition.BottomRadiusIncreaseSpeed = reader.ReadSingle();
|
||||
effectDefinition.TopRiseSpeed = reader.ReadSingle();
|
||||
effectDefinition.BottomRiseSpeed = reader.ReadSingle();
|
||||
|
||||
|
||||
effectDefinition.TextureRepeat = reader.ReadSingle();
|
||||
|
||||
effectDefinition.Param = new[]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dd4c4efb70347a2ba8cc981e6ffc018
|
||||
timeCreated: 1668071055
|
||||
@@ -0,0 +1,154 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Core.DataReader.Gdb
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public enum WuLingType
|
||||
{
|
||||
Water, // 水
|
||||
Fire, // 火
|
||||
Wind, // 风
|
||||
Thunder, // 雷
|
||||
Earth, // 土
|
||||
}
|
||||
|
||||
public enum ItemType
|
||||
{
|
||||
None = 0,
|
||||
Healing, // 治疗
|
||||
Throwable, // 投掷
|
||||
Treasure, // 仙宝
|
||||
Antique, // 古董
|
||||
Ore, // 矿石
|
||||
Plot, // 剧情
|
||||
Cloth, // 衣服
|
||||
Hat, // 帽子
|
||||
Shoes, // 鞋子
|
||||
Wearable, // 饰品
|
||||
Weapon, // 武器
|
||||
Corpse, // 尸块
|
||||
Blueprint, // 蓝图(梦溪杂录,美食方)
|
||||
}
|
||||
|
||||
public enum WeaponType
|
||||
{
|
||||
None = 0,
|
||||
Spear, // 长矛
|
||||
Sword, // 剑
|
||||
Staff, // 杖
|
||||
Machete, // 刀
|
||||
Bow, // 弓
|
||||
Spine, // 刺
|
||||
Sickle, // 镰刀
|
||||
}
|
||||
|
||||
public enum SpecialType
|
||||
{
|
||||
None = 0,
|
||||
Poison, // 随机中毒
|
||||
Flee, // 100%逃跑
|
||||
Navigation, // 引路蜂类
|
||||
LevelUp, // 升级类(等级提高1)
|
||||
}
|
||||
|
||||
public enum TargetRangeType
|
||||
{
|
||||
None = 0,
|
||||
FirstParty, // 我方单体
|
||||
FirstPartyAll, // 我方全体
|
||||
EnemyParty, // 敌方单体
|
||||
EnemyPartyAll, // 敌方全体
|
||||
}
|
||||
|
||||
public enum PlaceOfUseType
|
||||
{
|
||||
None = 0,
|
||||
Combat, // 战斗中
|
||||
OutOfCombat, // 非战斗中
|
||||
Anywhere, // 任何地方
|
||||
}
|
||||
|
||||
public enum ActorAttributeType
|
||||
{
|
||||
Hp, // 精
|
||||
Qi, // 气
|
||||
Mp, // 神
|
||||
Attack, // 攻击
|
||||
Defense, // 防御
|
||||
Speed, // 速度
|
||||
Luck, // 幸运
|
||||
Water, // 水
|
||||
Fire, // 火
|
||||
Wind, // 风
|
||||
Thunder, // 雷
|
||||
Earth, // 土
|
||||
}
|
||||
|
||||
public struct GameItem
|
||||
{
|
||||
public uint Id; // 物品ID
|
||||
|
||||
public string Name; // 物品名称
|
||||
public string ModelName; // 物品模型名称
|
||||
public string IconName; // 物品图标名称
|
||||
public string Description; // 物品描述
|
||||
public int Price; // 物品价格
|
||||
|
||||
public ItemType Type; // 物品类型
|
||||
public WeaponType WeaponType; // 武器类型(只有物品为武器的时候有意义)
|
||||
|
||||
public byte[] MainActorCanUse; // 主角可使用信息
|
||||
public byte[] WuLing; // 五灵属性
|
||||
|
||||
public int AncientValue; // 古董价值
|
||||
|
||||
public SpecialType SpecialType; // 特殊类型
|
||||
public TargetRangeType TargetRangeType; // 目标范围类型
|
||||
public PlaceOfUseType PlaceOfUseType; // 使用地点类型
|
||||
|
||||
public byte[] AttributeImpactType; // 角色属性影响类型 (0绝对值,1百分比值,2恢复到上限,3增加上限值)
|
||||
|
||||
// Empty byte between the memory addresses to align the data in memory.
|
||||
// SpecialType, TargetRangeType and PlaceOfUseType take 3 bytes in memory, thus we need to add 1 byte here
|
||||
// to align the data in memory (4 bytes).
|
||||
// Note: The padding byte is added after AttributeImpactType instead of before based on observation.
|
||||
internal byte PaddingByte;
|
||||
|
||||
public short[] AttributeImpactValue; // 角色属性影响值
|
||||
|
||||
public byte[] FightStateImpactType; // 战斗状态影响类型(0不影响,1增加,2解除)
|
||||
public short[] FightStateImpactValue; // 战斗状态值
|
||||
|
||||
public int ComboCount; // 连击次数
|
||||
|
||||
// 装备属性
|
||||
public short QiSavingPercentage; // 气消耗减少百分比
|
||||
public short MpSavingPercentage; // 神消耗减少百分比
|
||||
public short CriticalAttackAmplifyPercentage; // 暴击伤害增加百分比
|
||||
public short SpecialSkillSuccessRate; // 特技成功率增加百分比
|
||||
|
||||
// 尸块属性
|
||||
public uint OreId; // 矿石ID
|
||||
public uint ProductId; // 炼制出的物品ID
|
||||
public int ProductPrice; // 炼制出的物品价格
|
||||
|
||||
// 合成属性
|
||||
public uint[] SynthesisMaterialIds; // 两种合成材料的ID
|
||||
public uint SynthesisProductId; // 合成出的物品ID
|
||||
}
|
||||
|
||||
// Pal3 Game Database file
|
||||
public class GdbFile
|
||||
{
|
||||
public Dictionary<int, GameItem> GameItems { get; } // Game item Id -> Game item
|
||||
|
||||
public GdbFile(Dictionary<int, GameItem> gameItems)
|
||||
{
|
||||
GameItems = gameItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f266e43f10ee4eb1b95cfd541c518a39
|
||||
timeCreated: 1668071064
|
||||
@@ -0,0 +1,80 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Core.DataReader.Gdb
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Extensions;
|
||||
|
||||
public static class GdbFileReader
|
||||
{
|
||||
public static GdbFile Read(byte[] data, int codepage)
|
||||
{
|
||||
using var stream = new MemoryStream(data);
|
||||
using var reader = new BinaryReader(stream);
|
||||
|
||||
_ = reader.ReadString(128, codepage); // header string
|
||||
|
||||
uint actorDataOffset = reader.ReadUInt32();
|
||||
int numOfActors = reader.ReadInt32();
|
||||
|
||||
uint skillDataOffset = reader.ReadUInt32();
|
||||
int numOfSkills = reader.ReadInt32();
|
||||
|
||||
uint itemDataOffset = reader.ReadUInt32();
|
||||
int numOfItems = reader.ReadInt32();
|
||||
|
||||
uint comboSkillDataOffset = reader.ReadUInt32();
|
||||
int numOfComboSkills = reader.ReadInt32();
|
||||
|
||||
reader.BaseStream.Seek(itemDataOffset, SeekOrigin.Begin);
|
||||
var gameItems = new Dictionary<int, GameItem>();
|
||||
for (var i = 0; i < numOfItems; i++)
|
||||
{
|
||||
GameItem item = ReadGameItem(reader, codepage);
|
||||
gameItems[(int) item.Id] = item;
|
||||
}
|
||||
|
||||
return new GdbFile(gameItems);
|
||||
}
|
||||
|
||||
private static GameItem ReadGameItem(BinaryReader reader, int codepage)
|
||||
{
|
||||
return new GameItem
|
||||
{
|
||||
Id = reader.ReadUInt32(),
|
||||
Name = reader.ReadString(32, codepage),
|
||||
ModelName = reader.ReadString(30, codepage),
|
||||
IconName = reader.ReadString(30, codepage),
|
||||
Description = reader.ReadString(512, codepage),
|
||||
Price = reader.ReadInt32(),
|
||||
Type = (ItemType) reader.ReadByte(),
|
||||
WeaponType = (WeaponType) reader.ReadByte(),
|
||||
MainActorCanUse = reader.ReadBytes(5),
|
||||
WuLing = reader.ReadBytes(5),
|
||||
AncientValue = reader.ReadInt32(),
|
||||
SpecialType = (SpecialType) reader.ReadByte(), // ----------------| 1
|
||||
TargetRangeType = (TargetRangeType) reader.ReadByte(), // --------| 2
|
||||
PlaceOfUseType = (PlaceOfUseType) reader.ReadByte(), // ----------| 3
|
||||
AttributeImpactType = reader.ReadBytes(12),
|
||||
PaddingByte = reader.ReadByte(), // ------------------------------| ^ to complete 4-byte alignment
|
||||
AttributeImpactValue = reader.ReadInt16Array(12),
|
||||
FightStateImpactType = reader.ReadBytes(32),
|
||||
FightStateImpactValue = reader.ReadInt16Array(32),
|
||||
ComboCount = reader.ReadInt32(),
|
||||
QiSavingPercentage = reader.ReadInt16(),
|
||||
MpSavingPercentage = reader.ReadInt16(),
|
||||
CriticalAttackAmplifyPercentage = reader.ReadInt16(),
|
||||
SpecialSkillSuccessRate = reader.ReadInt16(),
|
||||
OreId = reader.ReadUInt32(),
|
||||
ProductId = reader.ReadUInt32(),
|
||||
ProductPrice = reader.ReadInt32(),
|
||||
SynthesisMaterialIds = reader.ReadUInt32Array(2),
|
||||
SynthesisProductId = reader.ReadUInt32()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1575b1b777f8491b9b6fbc051b936b47
|
||||
timeCreated: 1668071081
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Core.DataReader.Lgt
|
||||
public struct LightNode
|
||||
{
|
||||
public Matrix4x4 WorldMatrix;
|
||||
|
||||
|
||||
public GameBoxLightType LightType;
|
||||
public Color LightColor;
|
||||
public Color AmbientColor;
|
||||
@@ -22,20 +22,20 @@ namespace Core.DataReader.Lgt
|
||||
public float NearEnd;
|
||||
public float FarStart;
|
||||
public float FarEnd;
|
||||
|
||||
|
||||
public GameBoxLightDecayType LightDecayType;
|
||||
public float DecayRadius;
|
||||
|
||||
|
||||
public GameBoxLightShapeType LightShapeType;
|
||||
public float Size;
|
||||
public float Falloff;
|
||||
public float AspectRatio;
|
||||
}
|
||||
|
||||
|
||||
public class LgtFile
|
||||
{
|
||||
public LightNode[] LightNodes { get; }
|
||||
|
||||
|
||||
public LgtFile(LightNode[] lightNodes)
|
||||
{
|
||||
LightNodes = lightNodes;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace Core.DataReader.Lgt
|
||||
using var stream = new MemoryStream(data);
|
||||
using var reader = new BinaryReader(stream);
|
||||
#endif
|
||||
|
||||
|
||||
var numOfLightNodes = reader.ReadInt32();
|
||||
var lightNodes = new List<LightNode>();
|
||||
|
||||
|
||||
for (var i = 0; i < numOfLightNodes; i++)
|
||||
{
|
||||
var lightNode = ReadLightNode(reader);
|
||||
|
||||
|
||||
if (Enum.IsDefined(typeof(GameBoxLightType), lightNode.LightType) &&
|
||||
Enum.IsDefined(typeof(GameBoxLightShapeType), lightNode.LightShapeType))
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace Core.DataReader.Lgt
|
||||
Tx = reader.ReadSingle(), Ty = reader.ReadSingle(), Tz = reader.ReadSingle(), Tw = reader.ReadSingle()
|
||||
};
|
||||
transformMatrix.Tw = 1f;
|
||||
|
||||
|
||||
var lightNode = new LightNode
|
||||
{
|
||||
WorldMatrix = GameBoxInterpreter.ToUnityMatrix4x4(transformMatrix),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -77,19 +77,18 @@ namespace Core.DataReader.Mv3
|
||||
public struct Mv3Mesh
|
||||
{
|
||||
public string Name; // 64 chars max
|
||||
public GameBoxAABBox BoundBox;
|
||||
public Bounds Bounds;
|
||||
public Mv3Attribute[] Attributes;
|
||||
public Mv3VertFrame[] Frames;
|
||||
public Vector2[] TexCoords;
|
||||
public Vector3[] Normals;
|
||||
public int[] Triangles;
|
||||
public Vector2[] Uvs;
|
||||
public VertexAnimationKeyFrame[] KeyFrames;
|
||||
}
|
||||
|
||||
public struct VertexAnimationKeyFrame
|
||||
{
|
||||
public uint Tick;
|
||||
public Vector3[] Vertices;
|
||||
public int[] Triangles;
|
||||
public Vector2[] Uv;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,15 +102,13 @@ namespace Core.DataReader.Mv3
|
||||
public Mv3TagNode[] TagNodes { get; }
|
||||
public Mv3Material[] Materials { get; }
|
||||
public Mv3Mesh[] Meshes { get; }
|
||||
public VertexAnimationKeyFrame[][] MeshKeyFrames { get; }
|
||||
|
||||
public Mv3File(int version,
|
||||
uint duration,
|
||||
Mv3AnimationEvent[] animationEvents,
|
||||
Mv3TagNode[] tagNodes,
|
||||
Mv3Material[] materials,
|
||||
Mv3Mesh[] meshes,
|
||||
VertexAnimationKeyFrame[][] meshKeyFrames)
|
||||
Mv3Mesh[] meshes)
|
||||
{
|
||||
Version = version;
|
||||
Duration = duration;
|
||||
@@ -119,7 +116,6 @@ namespace Core.DataReader.Mv3
|
||||
TagNodes = tagNodes;
|
||||
Materials = materials;
|
||||
Meshes = meshes;
|
||||
MeshKeyFrames = meshKeyFrames;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Core.DataReader.Mv3
|
||||
|
||||
var header = reader.ReadChars(4);
|
||||
var headerStr = new string(header[..^1]);
|
||||
|
||||
|
||||
if (headerStr != "MV3")
|
||||
{
|
||||
throw new InvalidDataException("Invalid MV3(.mv3) file: header != MV3");
|
||||
@@ -70,13 +70,9 @@ namespace Core.DataReader.Mv3
|
||||
}
|
||||
|
||||
var meshes = new Mv3Mesh[numberOfMeshes];
|
||||
var meshKeyFrames = new VertexAnimationKeyFrame[numberOfMeshes][];
|
||||
for (var i = 0; i < numberOfMeshes; i++)
|
||||
{
|
||||
Mv3Mesh mesh = ReadMesh(reader, codepage);
|
||||
meshKeyFrames[i] = CalculateKeyFrameVertices(mesh);
|
||||
mesh.Normals = Utility.CalculateNormals(meshKeyFrames[i][0].Vertices, meshKeyFrames[i][0].Triangles);
|
||||
meshes[i] = mesh;
|
||||
meshes[i] = ReadMesh(reader, codepage);
|
||||
}
|
||||
|
||||
return new Mv3File(version,
|
||||
@@ -84,8 +80,7 @@ namespace Core.DataReader.Mv3
|
||||
animationEvents,
|
||||
tagNodes,
|
||||
materials,
|
||||
meshes,
|
||||
meshKeyFrames);
|
||||
meshes);
|
||||
}
|
||||
|
||||
#if USE_UNSAFE_BINARY_READER
|
||||
@@ -96,11 +91,12 @@ namespace Core.DataReader.Mv3
|
||||
{
|
||||
var name = reader.ReadString(64, codepage);
|
||||
var numberOfVertices = reader.ReadInt32();
|
||||
var boundBox = new GameBoxAABBox()
|
||||
{
|
||||
Min = reader.ReadVector3(),
|
||||
Max = reader.ReadVector3()
|
||||
};
|
||||
|
||||
var bounds = new Bounds();
|
||||
bounds.SetMinMax(
|
||||
GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()),
|
||||
GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()));
|
||||
|
||||
var numberOfFrames = reader.ReadInt32();
|
||||
var frames = new Mv3VertFrame[numberOfFrames];
|
||||
for (var i = 0; i < numberOfFrames; i++)
|
||||
@@ -128,7 +124,7 @@ namespace Core.DataReader.Mv3
|
||||
Vector2[] texCoords;
|
||||
if (numberOfTexCoords == 0)
|
||||
{
|
||||
texCoords = new Vector2[] {new (0f, 0f)};
|
||||
texCoords = new Vector2[] { new (0f, 0f) };
|
||||
Debug.LogWarning("numberOfTexCoords == 0");
|
||||
}
|
||||
else
|
||||
@@ -172,60 +168,65 @@ namespace Core.DataReader.Mv3
|
||||
};
|
||||
}
|
||||
|
||||
return new Mv3Mesh()
|
||||
{
|
||||
Name = name,
|
||||
BoundBox = boundBox,
|
||||
Attributes = attributes,
|
||||
Frames = frames,
|
||||
TexCoords = texCoords,
|
||||
};
|
||||
return GetMv3Mesh(name, bounds, attributes, frames, texCoords);
|
||||
}
|
||||
|
||||
private static VertexAnimationKeyFrame[] CalculateKeyFrameVertices(Mv3Mesh mv3Mesh)
|
||||
private static Mv3Mesh GetMv3Mesh(string name,
|
||||
Bounds bounds,
|
||||
Mv3Attribute[] attributes,
|
||||
Mv3VertFrame[] vertFrames,
|
||||
Vector2[] texCoords)
|
||||
{
|
||||
var triangles = new List<int>();
|
||||
var texCoords = mv3Mesh.TexCoords;
|
||||
var keyFrameInfo = new List<(Vector3 vertex, Vector2 uv)>[mv3Mesh.Frames.Length]
|
||||
.Select(item=>new List<(Vector3 vertex, Vector2 uv)>()).ToArray();
|
||||
var triangles = new int[attributes[0].IndexBuffers.Length * 3];
|
||||
var keyFrameVertices = new List<Vector3>[vertFrames.Length]
|
||||
.Select(item=>new List<Vector3>()).ToArray();
|
||||
var uvs = new Vector2[attributes[0].IndexBuffers.Length * 3];
|
||||
|
||||
var triangleIndex = 0;
|
||||
|
||||
for (var i = 0; i < mv3Mesh.Attributes[0].IndexBuffers.Length; i++)
|
||||
|
||||
for (var i = 0; i < attributes[0].IndexBuffers.Length; i++)
|
||||
{
|
||||
Mv3IndexBuffer indexBuffer = mv3Mesh.Attributes[0].IndexBuffers[i];
|
||||
Mv3IndexBuffer indexBuffer = attributes[0].IndexBuffers[i];
|
||||
for (var j = 0; j < 3; j++)
|
||||
{
|
||||
for (var k = 0; k < mv3Mesh.Frames.Length; k++)
|
||||
for (var k = 0; k < vertFrames.Length; k++)
|
||||
{
|
||||
Mv3VertFrame frame = mv3Mesh.Frames[k];
|
||||
Mv3VertFrame frame = vertFrames[k];
|
||||
Mv3Vert vertex = frame.Vertices[indexBuffer.TriangleIndex[j]];
|
||||
|
||||
keyFrameInfo[k].Add((GameBoxInterpreter
|
||||
keyFrameVertices[k].Add((GameBoxInterpreter
|
||||
.ToUnityVertex(new Vector3(vertex.X, vertex.Y, vertex.Z),
|
||||
GameBoxInterpreter.GameBoxMv3UnitToUnityUnit),
|
||||
texCoords[indexBuffer.TexCoordIndex[j]]));
|
||||
GameBoxInterpreter.GameBoxMv3UnitToUnityUnit)));
|
||||
}
|
||||
|
||||
triangles.Add(triangleIndex++);
|
||||
uvs[triangleIndex] = texCoords[indexBuffer.TexCoordIndex[j]];
|
||||
triangles[triangleIndex] = triangleIndex;
|
||||
triangleIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
GameBoxInterpreter.ToUnityTriangles(triangles);
|
||||
|
||||
var animationKeyFrames = new VertexAnimationKeyFrame[mv3Mesh.Frames.Length];
|
||||
var animationKeyFrames = new VertexAnimationKeyFrame[vertFrames.Length];
|
||||
for (var i = 0; i < animationKeyFrames.Length; i++)
|
||||
{
|
||||
animationKeyFrames[i] = new VertexAnimationKeyFrame()
|
||||
{
|
||||
Tick = mv3Mesh.Frames[i].Tick,
|
||||
Vertices = keyFrameInfo[i].Select(f => f.vertex).ToArray(),
|
||||
Triangles = triangles.ToArray(),
|
||||
Uv = keyFrameInfo[i].Select(f => f.uv).ToArray(),
|
||||
Tick = vertFrames[i].Tick,
|
||||
Vertices = keyFrameVertices[i].ToArray(),
|
||||
};
|
||||
}
|
||||
|
||||
return animationKeyFrames;
|
||||
return new Mv3Mesh
|
||||
{
|
||||
Name = name,
|
||||
Bounds = bounds,
|
||||
Attributes = attributes,
|
||||
Triangles = triangles,
|
||||
Uvs = uvs,
|
||||
Normals = Utility.CalculateNormals(animationKeyFrames[0].Vertices, triangles),
|
||||
KeyFrames = animationKeyFrames,
|
||||
};
|
||||
}
|
||||
|
||||
#if USE_UNSAFE_BINARY_READER
|
||||
@@ -261,13 +262,13 @@ namespace Core.DataReader.Mv3
|
||||
var tick = reader.ReadUInt32();
|
||||
Vector3 position = GameBoxInterpreter.ToUnityPosition(reader.ReadVector3());
|
||||
|
||||
var rotation = new GameBoxQuaternion()
|
||||
var rotation = GameBoxInterpreter.Mv3QuaternionToUnityQuaternion(new GameBoxQuaternion()
|
||||
{
|
||||
X = reader.ReadSingle(),
|
||||
Y = reader.ReadSingle(),
|
||||
Z = reader.ReadSingle(),
|
||||
W = reader.ReadSingle(),
|
||||
};
|
||||
});
|
||||
|
||||
var scale = new []
|
||||
{
|
||||
@@ -280,7 +281,7 @@ namespace Core.DataReader.Mv3
|
||||
{
|
||||
Tick = tick,
|
||||
Position = position,
|
||||
Rotation = GameBoxInterpreter.Mv3QuaternionToUnityQuaternion(rotation),
|
||||
Rotation = rotation,
|
||||
Scale = scale,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -48,23 +48,25 @@ namespace Core.DataReader.Nav
|
||||
|
||||
public struct NavTile
|
||||
{
|
||||
public float Y; // 格子地板高度
|
||||
public ushort Distance; // 格子距离周边障碍物的距离 (0最小-7最大)
|
||||
public NavFloorKind FloorKind; // 格子地板类型:0~128索引普通地面属性(土草雪等),128~255索引机关序号
|
||||
public float GameBoxYPosition; // 格子地板高度(原GameBox引擎下的Y坐标单位)
|
||||
public byte DistanceToNearestObstacle; // 格子距离周边障碍物的距离 (0最小-7最大)
|
||||
public NavFloorKind FloorKind; // 格子地板类型:0~128索引普通地面属性(土草雪等),128~255索引机关序号
|
||||
|
||||
public bool IsObstacle; // 是否为障碍物
|
||||
|
||||
public bool IsWalkable()
|
||||
{
|
||||
return Distance > 0;
|
||||
return !IsObstacle && DistanceToNearestObstacle > 0 && FloorKind != NavFloorKind.Jumpable;
|
||||
}
|
||||
}
|
||||
|
||||
public struct NavLayerNode
|
||||
{
|
||||
public GameBoxAABBox BoundBox;
|
||||
public Vector3[] Triangles;
|
||||
public int Level; // 0: root, child level = parent level + 1
|
||||
public NavLayerNode[] Children; // 4
|
||||
}
|
||||
// public struct NavLayerNode
|
||||
// {
|
||||
// public GameBoxAABBox BoundBox;
|
||||
// public Vector3[] Triangles;
|
||||
// public int Level; // 0: root, child level = parent level + 1
|
||||
// public NavLayerNode[] Children; // 4
|
||||
// }
|
||||
|
||||
public struct NavTileLayer
|
||||
{
|
||||
@@ -80,7 +82,7 @@ namespace Core.DataReader.Nav
|
||||
{
|
||||
public Vector3[] Vertices;
|
||||
public int[] Triangles;
|
||||
public NavLayerNode[] Nodes;
|
||||
//public NavLayerNode[] Nodes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Core.DataReader.Nav
|
||||
var faceLayers = new NavFaceLayer[numberOfLayers];
|
||||
for (var i = 0; i < numberOfLayers; i++)
|
||||
{
|
||||
faceLayers[i] = ReadFaceLayer(reader, version);
|
||||
faceLayers[i] = ReadFaceLayer(reader);
|
||||
}
|
||||
|
||||
return new NavFile(tileLayers, faceLayers);
|
||||
@@ -52,6 +52,7 @@ namespace Core.DataReader.Nav
|
||||
private static NavTileLayer ReadTileLayer(BinaryReader reader, byte version)
|
||||
{
|
||||
var portals = Array.Empty<GameBoxRect>();
|
||||
|
||||
if (version == 2)
|
||||
{
|
||||
portals = new GameBoxRect[8];
|
||||
@@ -84,10 +85,11 @@ namespace Core.DataReader.Nav
|
||||
{
|
||||
tiles[i] = new NavTile
|
||||
{
|
||||
Y = reader.ReadSingle(),
|
||||
Distance = reader.ReadUInt16(),
|
||||
FloorKind = (NavFloorKind) reader.ReadUInt16()
|
||||
GameBoxYPosition = reader.ReadSingle(),
|
||||
DistanceToNearestObstacle = reader.ReadByte(), //---| 1
|
||||
FloorKind = (NavFloorKind) reader.ReadByte() //----| 2
|
||||
};
|
||||
_ = reader.ReadBytes(2); //-----------------------------| ^ to complete 4-byte alignment
|
||||
}
|
||||
|
||||
return new NavTileLayer()
|
||||
@@ -101,7 +103,7 @@ namespace Core.DataReader.Nav
|
||||
};
|
||||
}
|
||||
|
||||
private static NavFaceLayer ReadFaceLayer(BinaryReader reader, byte version)
|
||||
private static NavFaceLayer ReadFaceLayer(BinaryReader reader)
|
||||
{
|
||||
var numberOfVertices = reader.ReadUInt16();
|
||||
var numberOfFaces = reader.ReadUInt16();
|
||||
@@ -125,16 +127,18 @@ namespace Core.DataReader.Nav
|
||||
// make the mesh double sided, but that would cause some other issues (trust me).
|
||||
{
|
||||
Vector3[] normals = Utility.CalculateNormals(vertices, triangles);
|
||||
|
||||
|
||||
for (var i = 0; i < numberOfFaces; i++)
|
||||
{
|
||||
var index = i * 3;
|
||||
|
||||
// Determine if the face is pointing downwards.
|
||||
if (normals[triangles[index]].y +
|
||||
normals[triangles[index + 1]].y +
|
||||
normals[triangles[index + 2]].y < 0)
|
||||
{
|
||||
// Change the winding order of the face.
|
||||
(triangles[index], triangles[index + 1]) = (triangles[index + 1], triangles[index]);
|
||||
// Change the winding order of the face to make it point upwards.
|
||||
(triangles[index], triangles[index + 1]) = (triangles[index + 1], triangles[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Core.DataReader.Pol
|
||||
|
||||
public struct PolMesh
|
||||
{
|
||||
public GameBoxAABBox BoundBox;
|
||||
public Bounds Bounds;
|
||||
public uint VertexFvfFlag;
|
||||
public PolVertexInfo VertexInfo;
|
||||
public PolTexture[] Textures;
|
||||
@@ -43,11 +43,11 @@ namespace Core.DataReader.Pol
|
||||
|
||||
public struct PolTexture
|
||||
{
|
||||
public GameBoxBlendFlag BlendFlag; // 0--opaque, 1--alpha blend, 2--invert color blend, 3--add
|
||||
public GameBoxBlendFlag BlendFlag;
|
||||
public GameBoxMaterial Material;
|
||||
public string[] TextureNames;
|
||||
public int VertStart;
|
||||
public int VertEnd;
|
||||
public uint VertStart;
|
||||
public uint VertEnd;
|
||||
public int[] Triangles;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -121,11 +121,11 @@ namespace Core.DataReader.Pol
|
||||
private static PolMesh ReadMeshData(BinaryReader reader, int version, int codepage)
|
||||
#endif
|
||||
{
|
||||
var boundBox = new GameBoxAABBox()
|
||||
{
|
||||
Min = reader.ReadVector3(),
|
||||
Max = reader.ReadVector3(),
|
||||
};
|
||||
var bounds = new Bounds();
|
||||
bounds.SetMinMax(
|
||||
GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()),
|
||||
GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()));
|
||||
|
||||
var vertexTypeFlag = reader.ReadUInt32();
|
||||
var numberOfVertices = reader.ReadInt32();
|
||||
|
||||
@@ -196,8 +196,8 @@ namespace Core.DataReader.Pol
|
||||
var y = reader.ReadSingle();
|
||||
uvs[3][i] = new Vector2(x, y);
|
||||
}
|
||||
|
||||
// Quick fix for the missing normals
|
||||
|
||||
// Quick fix for the missing/wrong normals
|
||||
if (normals[i] == Vector3.zero) normals[i] = Vector3.up;
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Core.DataReader.Pol
|
||||
|
||||
return new PolMesh
|
||||
{
|
||||
BoundBox = boundBox,
|
||||
Bounds = bounds,
|
||||
VertexFvfFlag = vertexTypeFlag,
|
||||
VertexInfo = vertexInfo,
|
||||
Textures = textureInfos
|
||||
@@ -258,24 +258,22 @@ namespace Core.DataReader.Pol
|
||||
textureNames[i] = textureName;
|
||||
}
|
||||
|
||||
var indexBits = reader.ReadInt32();
|
||||
if (indexBits != 16) throw new Exception($"IndexBits is invalid: {indexBits}");
|
||||
|
||||
var vertStart = reader.ReadInt32();
|
||||
var vertEnd = reader.ReadInt32();
|
||||
_ = reader.ReadInt32();
|
||||
var vertStart = reader.ReadUInt32();
|
||||
var vertEnd = reader.ReadUInt32();
|
||||
var numberOfFaces = reader.ReadInt32();
|
||||
|
||||
var triangles = new int[numberOfFaces * 3];
|
||||
for (var i = 0; i < numberOfFaces; i++)
|
||||
{
|
||||
var index = i * 3;
|
||||
triangles[index] = reader.ReadInt16();
|
||||
triangles[index + 1] = reader.ReadInt16();
|
||||
triangles[index + 2] = reader.ReadInt16();
|
||||
triangles[index] = reader.ReadUInt16();
|
||||
triangles[index + 1] = reader.ReadUInt16();
|
||||
triangles[index + 2] = reader.ReadUInt16();
|
||||
}
|
||||
|
||||
GameBoxInterpreter.ToUnityTriangles(triangles);
|
||||
|
||||
|
||||
return new PolTexture()
|
||||
{
|
||||
BlendFlag = blendFlag,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace Core.DataReader.Scn
|
||||
[System.Serializable]
|
||||
public enum ScnSceneType
|
||||
{
|
||||
StoryA = 0, // 情节关城市村镇
|
||||
StoryB, // 情节关建筑内部
|
||||
Maze, // 战斗(迷宫)场景
|
||||
OutDoor = 0, // 情节关城市村镇
|
||||
InDoor, // 情节关建筑内部
|
||||
Maze, // 迷宫场景
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -52,65 +52,74 @@ namespace Core.DataReader.Scn
|
||||
{
|
||||
AutoTrigger = 0, // 自动触发点
|
||||
Shakeable = 1, // 碰到后摇晃的物品
|
||||
Knockdownable = 2, // 碰到后翻倒的物品
|
||||
Arrow = 3, // 飞箭类 (JG06霹雳堂总舵飞剑)
|
||||
#if PAL3
|
||||
Collidable = 2, // 碰到后翻倒的物品(仙三独有)
|
||||
#elif PAL3A
|
||||
WuLingSwitch = 2, // 五灵开关 (可触发其他机关,外传独有)
|
||||
#endif
|
||||
Arrow = 3, // 飞箭类 (霹雳堂总舵飞剑)
|
||||
FallableWeapon = 4, // 落下的伤害物体 (冰棱)
|
||||
MovableCarrier = 5, // 移动浮板 (固定速度和路线往复移动,可载人)
|
||||
Trap = 6, // 陷阱 (调用脚本切换场景)
|
||||
RotatingStoneBeam = 7, // 旋传石梁 (一字型)
|
||||
RotatingWall = 8, // 旋转墙 (折尺型,JG13)
|
||||
RotatingBridge = 7, // 旋传石梁 (仙三独有)
|
||||
Teapot = 8, // 茶壶 (外传独有)
|
||||
PreciseTrigger = 9, // 精确触发点
|
||||
WindBlower = 10, // 风口
|
||||
Pushable = 11, // 推箱子
|
||||
SpecialMechanism = 12, // 主角特技机关
|
||||
ImpulsiveMechanism = 13, // 冲撞
|
||||
Door = 14, // 门,场景切换点
|
||||
Pushable = 11, // 推箱子(仙三独有)
|
||||
SpecialSwitch = 12, // 主角特技机关(仙三独有)
|
||||
Impulsive = 13, // 冲撞类机关(仙三独有)
|
||||
Door = 14, // 门,场景切换点
|
||||
Climbable = 15, // 藤蔓或梯子 (可爬物)
|
||||
InvestigationTriggerObject = 16, // 调查触发物体
|
||||
InvestigationTrigger = 16, // 调查触发物体
|
||||
StaticOrAnimated = 17, // 死物体或者随机动画播放(通用参数[0]:对应的地面是否可通过)
|
||||
Billboard = 18, // 公告板
|
||||
SuspensionBridge = 19, // 吊桥 (壁山)
|
||||
SuspensionBridge = 19, // 吊桥 (仙三独有)
|
||||
VirtualInvestigationTrigger = 20, // 虚拟BOX调查触发
|
||||
EyeBall = 21, // 锁妖塔:眼球
|
||||
LiftingMechanism = 22, // 锁妖塔:升降铁链或平台
|
||||
EyeBall = 21, // 锁妖塔:眼球(仙三独有)
|
||||
LiftingPlatform = 22, // 锁妖塔:升降铁链或平台
|
||||
// 通用参数[0]:为升起后的高度,需要用其他开关间接触发
|
||||
// 通用参数[1]:升起后到高层
|
||||
// 通用参数[2]:平台上的其他物件编号
|
||||
// 通用参数[3]:初始为可通过?)
|
||||
Switch = 23, // 开关 (可触发其他机关)
|
||||
Switch = 23, // 普通开关 (可触发其他机关,仙三独有)
|
||||
Collectable = 24, // 可以拣起的道具 (通用参数[0]:得到物品的数据库ID)
|
||||
General = 25, // 普通物品
|
||||
RareChest = 26, // 迷宫大宝箱
|
||||
WishPool = 27, // 许愿池
|
||||
#if PAL3
|
||||
WishPool = 27, // 许愿池(仙三独有)
|
||||
#elif PAL3A
|
||||
ToggleSwitch = 27, // 普通开关的变种(可触发其他机关,外传独有)
|
||||
#endif
|
||||
ColdWeapon = 28, // (M24)剑或锤
|
||||
GravityTrigger = 29, // 重力机关
|
||||
ElevatorSwitch = 30, // 升降机关门
|
||||
WaterSurfaceMechanism = 31, // 水面机关
|
||||
GravitySwitch = 29, // 重力机关(乌龟,仙三独有)
|
||||
ElevatorDoor = 30, // 升降机关门(仙三独有)
|
||||
WaterSurfaceRoadBlocker = 31, // 水面机关/路障(仙三独有)
|
||||
PiranhaFlower = 32, // 食人花
|
||||
PedalSwitch = 33, // 踏板开关
|
||||
SwordBridge = 34, // (m24)剑桥(触发后向前伸)
|
||||
SwordBridge = 34, // 剑桥(触发后向前伸,仙三独有)
|
||||
SlideWay = 35, // 滑道
|
||||
FallableObstacle = 36, // 坠落的障碍物
|
||||
DivineTreeFlower = 37, // (神树)花
|
||||
DivineTreePortal = 38, // (神树)传送点
|
||||
Elevator = 39, // (神魔之井)电梯
|
||||
ElevatorPedal = 40, // 上下传送板
|
||||
FallableObstacle = 36, // 坠落的障碍物(仙三独有)
|
||||
DivineTreeFlower = 37, // 神树花(仙三独有)
|
||||
DivineTreePortal = 38, // 神树传送点
|
||||
Elevator = 39, // 神魔之井电梯(仙三独有)
|
||||
ElevatorPedal = 40, // 上下传送板(仙三独有)
|
||||
Chest = 41, // 小宝箱
|
||||
SavingPoint = 42, // 存盘点
|
||||
SceneSfx = 43, // 场景音效
|
||||
JumpableArea = 44, // 可跳跃区域
|
||||
|
||||
|
||||
// PAL3A new scene objects
|
||||
UnknownObj47 = 47, // PAL3A m19 8
|
||||
UnknownObj48 = 48, // PAL3A m19 8
|
||||
UnknownObj49 = 49, // PAL3A m05 3, m06 2, m17 2, m17 3, m17 4, m18 1, m18 2
|
||||
UnknownObj51 = 51, // PAL3A m10 2
|
||||
UnknownObj52 = 52, // PAL3A m01 1
|
||||
UnknownObj53 = 53, // PAL3A m17 1, m17 2, m17 3, m17 4
|
||||
UnknownObj54 = 54, // PAL3A m13 1, m13 2, m13 3, m13 4
|
||||
UnknownObj55 = 55, // PAL3A m13 1, m13 2, m13 3, m13 4
|
||||
UnknownObj56 = 56, // PAL3A m15 1
|
||||
UnknownObj59 = 59, // PAL3A m15 2
|
||||
// 以下所有均为仙三外传中新增的场景物件类型
|
||||
PaperweightDesk = 47, // 镇尺桌
|
||||
Paperweight = 48, // 镇尺
|
||||
RoadElevatorOrBlocker = 49, // 可升降路面或者是阻挡物
|
||||
RetractableBlocker = 51, // 可收回路障
|
||||
RotatingWall = 52, // T形旋转石门
|
||||
WaterSurface = 53, // 升降水面
|
||||
ThreePhaseBridge = 54, // 三相桥
|
||||
ThreePhaseSwitch = 55, // 三相开关
|
||||
MushroomBridge = 56, // 蘑菇桥
|
||||
SectorBridge = 59, // 扇型桥
|
||||
}
|
||||
|
||||
// SCN (.scn) file header
|
||||
@@ -128,16 +137,16 @@ namespace Core.DataReader.Scn
|
||||
public struct ScnPath
|
||||
{
|
||||
public int NumberOfWaypoints;
|
||||
public Vector3[] Waypoints; // Max of 16 waypoints
|
||||
public Vector3[] GameBoxWaypoints; // 原GameBox引擎坐标系下的路径点(X, Y, Z)数组。固定数组长度为16.
|
||||
}
|
||||
|
||||
public struct ScnSceneInfo
|
||||
{
|
||||
public string CityName; // char[32] 关名称
|
||||
public string Name; // char[32] 区块名称
|
||||
public string Model; // char[32]
|
||||
public string CityName; // char[32] 关卡/区块名称
|
||||
public string SceneName; // char[32] 场景名称
|
||||
public string Model; // char[32] 模型名称
|
||||
public ScnSceneType SceneType;
|
||||
public int LightMap; // 0日景灯光, 1夜景灯光, -1不知道是什么意思(比如M01)
|
||||
public int LightMap; // 0日景灯光, 1夜景灯光, -1无灯光?(比如M01)
|
||||
public uint SkyBox;
|
||||
public uint[] Reserved; // 6 DWORDs
|
||||
|
||||
@@ -162,16 +171,36 @@ namespace Core.DataReader.Scn
|
||||
if (modelBName.EndsWith("y", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modelBName = modelBName[..^1];
|
||||
|
||||
|
||||
}
|
||||
return string.Equals(CityName, sceneInfo.CityName, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.Equals(modelAName, modelBName, StringComparison.OrdinalIgnoreCase);
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool Is(string cityName, string sceneName)
|
||||
{
|
||||
return IsCity(cityName) && IsScene(sceneName);
|
||||
}
|
||||
|
||||
public bool IsCity(string cityName)
|
||||
{
|
||||
return string.Equals(CityName, cityName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool IsScene(string sceneName)
|
||||
{
|
||||
return string.Equals(SceneName, sceneName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{CityName.ToLower()}_{Name.ToLower()}_{LightMap}";
|
||||
return $"City: {CityName.ToLower()}, " +
|
||||
$"Scene: {SceneName.ToLower()}, " +
|
||||
$"Model: {Model.ToLower()}, " +
|
||||
$"Type: {SceneType}, " +
|
||||
$"LightMap: {LightMap}, " +
|
||||
$"SkyBox: {SkyBox}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,23 +221,18 @@ namespace Core.DataReader.Scn
|
||||
// char[32] Npc名字
|
||||
public string Name;
|
||||
|
||||
// char[32] 贴图编号
|
||||
// char[34] 贴图编号 (无用)
|
||||
public string Texture;
|
||||
|
||||
// 2 bytes unknown data
|
||||
public byte[] Unknown1;
|
||||
|
||||
// 人物初始朝向
|
||||
public float FacingDirection;
|
||||
|
||||
public byte OnLayer;
|
||||
// 初始地层
|
||||
public int LayerIndex;
|
||||
|
||||
// 3 bytes unknown data
|
||||
public byte[] Unknown2;
|
||||
|
||||
// 初始位置
|
||||
public float PositionX;
|
||||
public float PositionZ;
|
||||
// 原GameBox引擎下的初始位置(X,Z)
|
||||
public float GameBoxXPosition;
|
||||
public float GameBoxZPosition;
|
||||
|
||||
// 初始是否可见
|
||||
public int InitActive;
|
||||
@@ -220,8 +244,9 @@ namespace Core.DataReader.Scn
|
||||
public uint ScriptId;
|
||||
|
||||
// 初始Y坐标,只有在 InitBehaviour == Hold
|
||||
// 的时候 PositionY 和 InitAction 才有用
|
||||
public float PositionY;
|
||||
// 的时候 GameBoxYPosition 和 InitAction 才有用
|
||||
public float GameBoxYPosition; // 原GameBox引擎下的Y坐标
|
||||
|
||||
// chars[16] 初始动作
|
||||
public string InitAction;
|
||||
|
||||
@@ -248,29 +273,29 @@ namespace Core.DataReader.Scn
|
||||
// 一关中唯一的编号
|
||||
public byte Id;
|
||||
|
||||
// 是否激活 (不激活相当于没这个物体)
|
||||
public byte Active;
|
||||
// 初始是否激活 (不激活相当于没这个物体)
|
||||
public byte InitActive;
|
||||
|
||||
// 可触发次数 (0表示不可触发,0xFF表示无限触发)
|
||||
// 可触发次数 (0表示不可触发,1表示只能触发一次(收集类道具),0xFF表示无限触发)
|
||||
public byte Times;
|
||||
|
||||
// 开关状态 (0代表关, 1代表开)
|
||||
public byte Switch;
|
||||
public byte SwitchState;
|
||||
|
||||
// char[32] 物品名称,对应美术模型,带扩展名
|
||||
public string Name;
|
||||
|
||||
// 触发标志,0x01地砖自动触发,0x02模型OBB调查触发
|
||||
public ushort TriggerType;
|
||||
// 触发类型,1地砖自动触发,2模型调查触发
|
||||
public byte TriggerType;
|
||||
|
||||
// 是否产生阻挡
|
||||
public ushort NonBlocking;
|
||||
public byte IsNonBlocking;
|
||||
|
||||
// 模型位置
|
||||
public Vector3 Position;
|
||||
// 原GameBox引擎下的模型位置
|
||||
public Vector3 GameBoxPosition;
|
||||
|
||||
// 渲染模型的时候转动多少角度(绕Y轴)
|
||||
public float YRotation;
|
||||
public float GameBoxYRotation;
|
||||
|
||||
// 触发范围(TileMap区域)
|
||||
public GameBoxRect TileMapTriggerRect;
|
||||
@@ -282,9 +307,9 @@ namespace Core.DataReader.Scn
|
||||
public byte SaveState;
|
||||
|
||||
// 在哪个地层
|
||||
public byte OnLayer;
|
||||
public byte LayerIndex;
|
||||
|
||||
// 五灵属性,0~5代表,用于大宝箱
|
||||
// 五灵属性,0~5代表,用于大宝箱和三外中具有五灵属性的机关
|
||||
public byte WuLing;
|
||||
|
||||
/*
|
||||
@@ -304,44 +329,54 @@ namespace Core.DataReader.Scn
|
||||
24 以拣起的道具
|
||||
[0]:得到物品的数据库ID
|
||||
*/
|
||||
#if PAL3
|
||||
|
||||
public int[] Parameters;
|
||||
#elif PAL3A
|
||||
public float[] Parameters;
|
||||
|
||||
#if PAL3A
|
||||
public uint NotUsed; // always 0
|
||||
#endif
|
||||
|
||||
// 触发条件
|
||||
public ushort NeedSpecialAction; // 对应特殊行走技能,0xFF为无此条件
|
||||
public ushort NeedItem; // 需要物品,0xFF为无此条件
|
||||
public ushort NeedGold; // 需要金钱值
|
||||
public ushort NeedLv; // 需要等级数
|
||||
public ushort NeedWu; // 需要武力值 (如果无此限制,则设成最小值)
|
||||
public ushort NeedAllOpen; // 场景中所有需检测的机关都为开
|
||||
public string FailedMessage; // char[16] 失败提示字符串名称
|
||||
public byte RequireSpecialAction; // 对应特殊行走技能,0xFF为无此条件
|
||||
public ushort RequireItem; // 需要物品,0xFF为无此条件
|
||||
public ushort RequireMoney; // 需要金钱值
|
||||
public ushort RequireLevel; // 需要等级数
|
||||
public ushort RequireAttackValue; // 需要武力值 (如果无此限制,则设成最小值)
|
||||
public byte RequireAllMechanismsSolved; // 场景中所有需检测的机关都为开
|
||||
public string FailedMessage; // char[16] 失败提示字符串名称
|
||||
|
||||
#if PAL3A
|
||||
public uint Unknown; // TODO
|
||||
#endif
|
||||
|
||||
public uint ScriptId;
|
||||
|
||||
public ScnPath Path;
|
||||
|
||||
// 触发结果
|
||||
public ushort LinkedObject; // 触发其它机关的编号;
|
||||
public ushort LinkedObjectId; // 触发其它机关的编号;
|
||||
|
||||
// 与场景的某个开关相关
|
||||
public string DependentSceneName; // char[32]
|
||||
public ushort DependentId;
|
||||
public byte DependentObjectId;
|
||||
|
||||
public Bounds Bounds;
|
||||
public float GameBoxXRotation; // 绕X轴旋转
|
||||
#if PAL3A
|
||||
public float GameBoxZRotation; // 绕Z轴旋转
|
||||
#endif
|
||||
public string SfxName; // 音效文件名
|
||||
|
||||
public GameBoxAABBox BoundBox;
|
||||
public float XRotation; // 绕X轴旋转
|
||||
public float ZRotation; // 绕Z轴旋转
|
||||
public string SfxName; // char[8] 特效参数
|
||||
|
||||
public uint EffectModelType;
|
||||
|
||||
public uint ScriptChangeActive;
|
||||
public uint ScriptActivated;
|
||||
public uint ScriptMoved;
|
||||
public uint[] Reserved; // 52 DWORDs
|
||||
|
||||
public byte[] Unknown1;
|
||||
public byte[] Unknown2;
|
||||
#if PAL3A
|
||||
public uint CanOnlyBeTriggeredOnce;
|
||||
#endif
|
||||
|
||||
public uint[] Reserved; // PAL3: 52 DWORDs PAL3A: 44 DWORDs
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Core.DataReader.Scn
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Extensions;
|
||||
using GameBox;
|
||||
using UnityEngine;
|
||||
@@ -33,7 +35,7 @@ namespace Core.DataReader.Scn
|
||||
var sceneInfo = new ScnSceneInfo()
|
||||
{
|
||||
CityName = reader.ReadString(32, codepage),
|
||||
Name = reader.ReadString(32, codepage),
|
||||
SceneName = reader.ReadString(32, codepage),
|
||||
Model = reader.ReadString(32, codepage),
|
||||
SceneType = (ScnSceneType) reader.ReadInt32(),
|
||||
LightMap = reader.ReadInt32(),
|
||||
@@ -45,16 +47,7 @@ namespace Core.DataReader.Scn
|
||||
var npcInfos = new ScnNpcInfo[numberOfNpc];
|
||||
for (var i = 0; i < numberOfNpc; i++)
|
||||
{
|
||||
ScnNpcInfo npcInfo = ReadNpcInfo(reader, codepage);
|
||||
if (npcInfo.Unknown1[0] != 0 ||
|
||||
npcInfo.Unknown1[1] != 0 ||
|
||||
npcInfo.Unknown2[0] != 0 ||
|
||||
npcInfo.Unknown2[1] != 0 ||
|
||||
npcInfo.Unknown2[2] != 0)
|
||||
{
|
||||
Debug.LogError($"Unknown byte has value for ActorId: {npcInfo.Id} Name: {npcInfo.Name}");
|
||||
}
|
||||
npcInfos[i] = npcInfo;
|
||||
npcInfos[i] = ReadNpcInfo(reader, codepage);
|
||||
}
|
||||
|
||||
reader.BaseStream.Seek(objectDataOffset, SeekOrigin.Begin);
|
||||
@@ -75,17 +68,15 @@ namespace Core.DataReader.Scn
|
||||
Id = reader.ReadByte(),
|
||||
Kind = (ScnActorKind)reader.ReadByte(),
|
||||
Name = reader.ReadString(32, codepage),
|
||||
Texture = reader.ReadString(32, codepage),
|
||||
Unknown1 = reader.ReadBytes(2),
|
||||
Texture = reader.ReadString(34, codepage),
|
||||
FacingDirection = reader.ReadSingle(),
|
||||
OnLayer = reader.ReadByte(),
|
||||
Unknown2 = reader.ReadBytes(3),
|
||||
PositionX = reader.ReadSingle(),
|
||||
PositionZ = reader.ReadSingle(),
|
||||
LayerIndex = reader.ReadInt32(),
|
||||
GameBoxXPosition = reader.ReadSingle(),
|
||||
GameBoxZPosition = reader.ReadSingle(),
|
||||
InitActive = reader.ReadInt32(),
|
||||
InitBehaviour = (ScnActorBehaviour) reader.ReadInt32(),
|
||||
ScriptId = reader.ReadUInt32(),
|
||||
PositionY = reader.ReadSingle(),
|
||||
GameBoxYPosition = reader.ReadSingle(),
|
||||
InitAction = reader.ReadString(16, codepage),
|
||||
MonsterId = reader.ReadUInt32Array(3),
|
||||
MonsterNumber = reader.ReadUInt16(),
|
||||
@@ -93,7 +84,7 @@ namespace Core.DataReader.Scn
|
||||
Path = new ScnPath()
|
||||
{
|
||||
NumberOfWaypoints = reader.ReadInt32(),
|
||||
Waypoints = reader.ReadVector3Array(16)
|
||||
GameBoxWaypoints = reader.ReadVector3Array(16)
|
||||
},
|
||||
NoTurn = reader.ReadUInt32(),
|
||||
LoopAction = reader.ReadUInt32(),
|
||||
@@ -104,140 +95,168 @@ namespace Core.DataReader.Scn
|
||||
|
||||
private static ScnObjectInfo ReadObjectInfo(BinaryReader reader, int codepage)
|
||||
{
|
||||
var id = reader.ReadByte();
|
||||
var initActive = reader.ReadByte();
|
||||
var times = reader.ReadByte();
|
||||
var switchState = reader.ReadByte();
|
||||
|
||||
var name = reader.ReadString(32, codepage);
|
||||
|
||||
var triggerType = reader.ReadByte();
|
||||
var isNonBlocking = reader.ReadByte();
|
||||
_ = reader.ReadBytes(2); // Empty padding bytes to complete 4-byte alignment
|
||||
|
||||
var gameBoxPosition = reader.ReadVector3();
|
||||
var yRotation = reader.ReadSingle();
|
||||
|
||||
var tileMapTriggerRect = new GameBoxRect()
|
||||
{
|
||||
Left = reader.ReadInt32(),
|
||||
Top = reader.ReadInt32(),
|
||||
Right = reader.ReadInt32(),
|
||||
Bottom = reader.ReadInt32(),
|
||||
};
|
||||
|
||||
var type = (ScnSceneObjectType) reader.ReadByte();
|
||||
var saveState = reader.ReadByte();
|
||||
var layerIndex = reader.ReadByte();
|
||||
var wuLing = reader.ReadByte();
|
||||
|
||||
#if PAL3
|
||||
return new ScnObjectInfo()
|
||||
{
|
||||
Id = reader.ReadByte(),
|
||||
Active = reader.ReadByte(),
|
||||
Times = reader.ReadByte(),
|
||||
Switch = reader.ReadByte(),
|
||||
|
||||
Name = reader.ReadString(32, codepage),
|
||||
TriggerType = reader.ReadUInt16(),
|
||||
NonBlocking = reader.ReadUInt16(),
|
||||
|
||||
Position = reader.ReadVector3(),
|
||||
YRotation = reader.ReadSingle(),
|
||||
TileMapTriggerRect = new GameBoxRect()
|
||||
{
|
||||
Left = reader.ReadInt32(),
|
||||
Top = reader.ReadInt32(),
|
||||
Right = reader.ReadInt32(),
|
||||
Bottom = reader.ReadInt32(),
|
||||
},
|
||||
|
||||
Type = (ScnSceneObjectType) reader.ReadByte(),
|
||||
SaveState = reader.ReadByte(),
|
||||
OnLayer = reader.ReadByte(),
|
||||
WuLing = reader.ReadByte(),
|
||||
|
||||
Parameters = reader.ReadInt32Array(6),
|
||||
|
||||
NeedSpecialAction = reader.ReadUInt16(),
|
||||
NeedItem = reader.ReadUInt16(),
|
||||
NeedGold = reader.ReadUInt16(),
|
||||
NeedLv = reader.ReadUInt16(),
|
||||
NeedWu = reader.ReadUInt16(),
|
||||
NeedAllOpen = reader.ReadUInt16(),
|
||||
FailedMessage = reader.ReadString(16, codepage),
|
||||
|
||||
ScriptId = reader.ReadUInt32(),
|
||||
Path = new ScnPath()
|
||||
{
|
||||
NumberOfWaypoints = reader.ReadInt32(),
|
||||
Waypoints = reader.ReadVector3Array(16)
|
||||
},
|
||||
|
||||
LinkedObject = reader.ReadUInt16(),
|
||||
DependentSceneName = reader.ReadString(32, codepage),
|
||||
DependentId = reader.ReadUInt16(),
|
||||
|
||||
BoundBox = new GameBoxAABBox()
|
||||
{
|
||||
Min = reader.ReadVector3(),
|
||||
Max = reader.ReadVector3()
|
||||
},
|
||||
|
||||
XRotation = reader.ReadSingle(),
|
||||
SfxName = reader.ReadString(8, codepage),
|
||||
EffectModelType = reader.ReadUInt32(),
|
||||
|
||||
ScriptChangeActive = reader.ReadUInt32(),
|
||||
ScriptMoved = reader.ReadUInt32(),
|
||||
|
||||
Reserved = reader.ReadUInt32Array(52)
|
||||
};
|
||||
var parameters = reader.ReadInt32Array(6);
|
||||
#elif PAL3A
|
||||
var parameters = Array.ConvertAll(reader.ReadSingleArray(6), Convert.ToInt32);
|
||||
#endif
|
||||
|
||||
#if PAL3A
|
||||
var notUsed = reader.ReadUInt32();
|
||||
#endif
|
||||
|
||||
var requireSpecialAction = reader.ReadByte();
|
||||
var requireItem = reader.ReadUInt16();
|
||||
_ = reader.ReadByte(); // Empty padding byte to complete 4-byte alignment
|
||||
|
||||
var requireMoney = reader.ReadUInt16();
|
||||
var requireLevel = reader.ReadUInt16();
|
||||
|
||||
var requireAttackValue = reader.ReadUInt16();
|
||||
var requireAllMechanismsSolved = reader.ReadByte();
|
||||
var failedMessage = reader.ReadString(16, codepage);
|
||||
_ = reader.ReadByte(); // Empty padding byte to complete 4-byte alignment
|
||||
|
||||
#if PAL3A
|
||||
var unknown = reader.ReadUInt32(); // TODO
|
||||
#endif
|
||||
|
||||
var scriptId = reader.ReadUInt32();
|
||||
|
||||
var path = new ScnPath()
|
||||
{
|
||||
NumberOfWaypoints = reader.ReadInt32(),
|
||||
GameBoxWaypoints = reader.ReadVector3Array(16)
|
||||
};
|
||||
|
||||
var linkedObjectId = reader.ReadUInt16();
|
||||
var dependentSceneName = reader.ReadString(32, codepage);
|
||||
var dependentObjectId = reader.ReadByte();
|
||||
_ = reader.ReadByte(); // Empty padding byte to complete 4-byte alignment
|
||||
|
||||
var bounds = new Bounds();
|
||||
bounds.SetMinMax(
|
||||
GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()),
|
||||
GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()));
|
||||
|
||||
var xRotation = reader.ReadSingle();
|
||||
|
||||
#if PAL3A
|
||||
var zRotation = reader.ReadSingle();
|
||||
#endif
|
||||
|
||||
var sfxName = reader.ReadString(8, codepage);
|
||||
|
||||
var effectModelType = reader.ReadUInt32();
|
||||
|
||||
var scriptActivated = reader.ReadUInt32();
|
||||
var scriptMoved = reader.ReadUInt32();
|
||||
|
||||
#if PAL3A
|
||||
var canOnlyBeTriggeredOnce = reader.ReadUInt32();
|
||||
#endif
|
||||
|
||||
#if PAL3
|
||||
var reserved = reader.ReadUInt32Array(52);
|
||||
#elif PAL3A
|
||||
var reserved = reader.ReadUInt32Array(44);
|
||||
#endif
|
||||
|
||||
return new ScnObjectInfo()
|
||||
{
|
||||
Id = reader.ReadByte(),
|
||||
Active = reader.ReadByte(),
|
||||
Times = reader.ReadByte(),
|
||||
Switch = reader.ReadByte(),
|
||||
Id = id,
|
||||
InitActive = initActive,
|
||||
Times = times,
|
||||
SwitchState = switchState,
|
||||
|
||||
Name = reader.ReadString(32, codepage),
|
||||
TriggerType = reader.ReadUInt16(),
|
||||
NonBlocking = reader.ReadUInt16(),
|
||||
Name = name,
|
||||
|
||||
Position = reader.ReadVector3(),
|
||||
YRotation = reader.ReadSingle(),
|
||||
TileMapTriggerRect = new GameBoxRect()
|
||||
{
|
||||
Left = reader.ReadInt32(),
|
||||
Top = reader.ReadInt32(),
|
||||
Right = reader.ReadInt32(),
|
||||
Bottom = reader.ReadInt32(),
|
||||
},
|
||||
TriggerType = triggerType,
|
||||
IsNonBlocking = isNonBlocking,
|
||||
|
||||
Type = (ScnSceneObjectType) reader.ReadByte(),
|
||||
SaveState = reader.ReadByte(),
|
||||
OnLayer = reader.ReadByte(),
|
||||
WuLing = reader.ReadByte(),
|
||||
|
||||
Parameters = reader.ReadSingleArray(6),
|
||||
|
||||
// TODO
|
||||
Unknown1 = reader.ReadBytes(4),
|
||||
GameBoxPosition = gameBoxPosition,
|
||||
GameBoxYRotation = yRotation,
|
||||
TileMapTriggerRect = tileMapTriggerRect,
|
||||
|
||||
NeedSpecialAction = reader.ReadUInt16(),
|
||||
NeedItem = reader.ReadUInt16(),
|
||||
NeedGold = reader.ReadUInt16(),
|
||||
NeedLv = reader.ReadUInt16(),
|
||||
NeedWu = reader.ReadUInt16(),
|
||||
NeedAllOpen = reader.ReadUInt16(),
|
||||
FailedMessage = reader.ReadString(16, codepage),
|
||||
Type = type,
|
||||
SaveState = saveState,
|
||||
LayerIndex = layerIndex,
|
||||
WuLing = wuLing,
|
||||
|
||||
// TODO
|
||||
Unknown2 = reader.ReadBytes(4),
|
||||
ScriptId = reader.ReadUInt32(),
|
||||
Parameters = parameters,
|
||||
|
||||
Path = new ScnPath()
|
||||
{
|
||||
NumberOfWaypoints = reader.ReadInt32(),
|
||||
Waypoints = reader.ReadVector3Array(16)
|
||||
},
|
||||
#if PAL3A
|
||||
NotUsed = notUsed,
|
||||
#endif
|
||||
|
||||
LinkedObject = reader.ReadUInt16(),
|
||||
DependentSceneName = reader.ReadString(32, codepage),
|
||||
DependentId = reader.ReadUInt16(),
|
||||
RequireSpecialAction = requireSpecialAction,
|
||||
RequireItem = requireItem,
|
||||
RequireMoney = requireMoney,
|
||||
RequireLevel = requireLevel,
|
||||
RequireAttackValue = requireAttackValue,
|
||||
RequireAllMechanismsSolved = requireAllMechanismsSolved,
|
||||
|
||||
BoundBox = new GameBoxAABBox()
|
||||
{
|
||||
Min = reader.ReadVector3(),
|
||||
Max = reader.ReadVector3()
|
||||
},
|
||||
FailedMessage = failedMessage,
|
||||
|
||||
XRotation = reader.ReadSingle(),
|
||||
ZRotation = reader.ReadSingle(),
|
||||
SfxName = reader.ReadString(8, codepage),
|
||||
EffectModelType = reader.ReadUInt32(),
|
||||
#if PAL3A
|
||||
Unknown = unknown, // TODO
|
||||
#endif
|
||||
|
||||
ScriptChangeActive = reader.ReadUInt32(),
|
||||
ScriptMoved = reader.ReadUInt32(),
|
||||
ScriptId = scriptId,
|
||||
|
||||
Reserved = reader.ReadUInt32Array(45)
|
||||
Path = path,
|
||||
|
||||
LinkedObjectId = linkedObjectId,
|
||||
DependentSceneName = dependentSceneName,
|
||||
DependentObjectId = dependentObjectId,
|
||||
|
||||
Bounds = bounds,
|
||||
|
||||
GameBoxXRotation = xRotation,
|
||||
|
||||
#if PAL3A
|
||||
GameBoxZRotation = zRotation,
|
||||
#endif
|
||||
|
||||
SfxName = sfxName,
|
||||
EffectModelType = effectModelType,
|
||||
|
||||
ScriptActivated = scriptActivated,
|
||||
ScriptMoved = scriptMoved,
|
||||
|
||||
#if PAL3A
|
||||
CanOnlyBeTriggeredOnce = canOnlyBeTriggeredOnce,
|
||||
#endif
|
||||
|
||||
Reserved = reserved,
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -68,7 +68,17 @@ namespace Core.Extensions
|
||||
}
|
||||
return integers;
|
||||
}
|
||||
|
||||
|
||||
public static short[] ReadInt16Array(this BinaryReader binaryReader, int count)
|
||||
{
|
||||
var integers = new short[count];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
integers[i] = binaryReader.ReadInt16();
|
||||
}
|
||||
return integers;
|
||||
}
|
||||
|
||||
public static ushort[] ReadUInt16Array(this BinaryReader binaryReader, int count)
|
||||
{
|
||||
var integers = new ushort[count];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Core.FileSystem
|
||||
{
|
||||
rootPath = !string.IsNullOrEmpty(rootPath) ? rootPath : throw new ArgumentNullException(nameof(rootPath));
|
||||
crcHash = crcHash ?? throw new ArgumentNullException(nameof(crcHash));
|
||||
|
||||
|
||||
if (!rootPath.EndsWith(Path.DirectorySeparatorChar))
|
||||
{
|
||||
rootPath += Path.DirectorySeparatorChar;
|
||||
@@ -72,7 +72,7 @@ namespace Core.FileSystem
|
||||
cpkArchive.Init();
|
||||
_cpkArchives[cpkFileName] = cpkArchive;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if file exists in any of the segmented archives using virtual path.
|
||||
/// </summary>
|
||||
@@ -88,7 +88,7 @@ namespace Core.FileSystem
|
||||
segmentedArchiveName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Check if the file exists in any of the segmented cpk archives.
|
||||
foreach (var subCpkPath in _cpkArchives.Keys
|
||||
.Where(_ => _.StartsWith(cpkFileName[..^CpkConstants.FileExtension.Length] + '_', StringComparison.OrdinalIgnoreCase)))
|
||||
@@ -141,10 +141,10 @@ namespace Core.FileSystem
|
||||
public byte[] ReadAllBytes(string fileVirtualPath)
|
||||
{
|
||||
ParseFileVirtualPath(fileVirtualPath, out var cpkFileName, out var relativeVirtualPath);
|
||||
|
||||
|
||||
if (_cpkArchives.ContainsKey(cpkFileName))
|
||||
{
|
||||
return _cpkArchives[cpkFileName].ReadAllBytes(relativeVirtualPath);
|
||||
return _cpkArchives[cpkFileName].ReadAllBytes(relativeVirtualPath);
|
||||
}
|
||||
|
||||
// Find and read the file content in segmented cpk archives.
|
||||
@@ -154,7 +154,7 @@ namespace Core.FileSystem
|
||||
var relativePathInSubCpk = relativeVirtualPath.Replace(cpkFileName, subCpkPath);
|
||||
if (_cpkArchives[subCpkPath].FileExists(relativePathInSubCpk))
|
||||
{
|
||||
return _cpkArchives[subCpkPath].ReadAllBytes(relativePathInSubCpk);
|
||||
return _cpkArchives[subCpkPath].ReadAllBytes(relativePathInSubCpk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,17 +212,17 @@ namespace Core.FileSystem
|
||||
foreach ((string cpkFileName, CpkArchive cpkArchive) in _cpkArchives)
|
||||
{
|
||||
var outputDir = outputFolder + cpkFileName + Path.DirectorySeparatorChar;
|
||||
|
||||
|
||||
if (!Directory.Exists(outputDir))
|
||||
{
|
||||
Directory.CreateDirectory(outputDir);
|
||||
}
|
||||
|
||||
|
||||
cpkArchive.ExtractTo(outputDir);
|
||||
Debug.Log($"{cpkFileName} extracted to {outputDir}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Search files using keyword.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Core.FileSystem
|
||||
/// <param name="segmentedArchiveName">Name of the segmented archive if exists</param>
|
||||
/// <returns>True if file exists in segmented archive</returns>
|
||||
public bool FileExistsInSegmentedArchive(string fileVirtualPath, out string segmentedArchiveName);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if file exists in the archive using virtual path.
|
||||
/// </summary>
|
||||
@@ -68,7 +68,7 @@ namespace Core.FileSystem
|
||||
/// Extract all archives to the specified destination
|
||||
/// </summary>
|
||||
public void ExtractTo(string outputFolder);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Search files using keyword.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -10,17 +10,14 @@ namespace Core.GameBox
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Used to convert GameBox specific rendering related metadata to Unity standard.
|
||||
/// Interpreter/convertor to convert GameBox specific rendering related metrics to Unity standard units that fits
|
||||
/// well with the engine and editor.
|
||||
/// </summary>
|
||||
public static class GameBoxInterpreter
|
||||
{
|
||||
public const float GameBoxUnitToUnityUnit = 20f;
|
||||
public const float GameBoxCvdUnitToUnityUnit = 20f;
|
||||
public const float GameBoxMv3UnitToUnityUnit = 1270f;
|
||||
|
||||
// Since GameBox's rendering pipeline uses different internal axis system.
|
||||
// Here we are flipping the x here to minor it back to the Unity axis.
|
||||
// Also we want to scale it to proper unity unit.
|
||||
public static Vector3 ToUnityVertex(Vector3 vertex, float scale)
|
||||
{
|
||||
return ToUnityVector3(vertex, scale);
|
||||
@@ -31,6 +28,49 @@ namespace Core.GameBox
|
||||
return ToUnityVector3(position, scale);
|
||||
}
|
||||
|
||||
public static float ToUnityDistance(float gameBoxDistance)
|
||||
{
|
||||
return gameBoxDistance / GameBoxUnitToUnityUnit;
|
||||
}
|
||||
|
||||
public static float ToUnityXPosition(float gameBoxXPosition)
|
||||
{
|
||||
return -gameBoxXPosition / GameBoxUnitToUnityUnit;
|
||||
}
|
||||
|
||||
public static float ToUnityYPosition(float gameBoxYPosition)
|
||||
{
|
||||
return gameBoxYPosition / GameBoxUnitToUnityUnit;
|
||||
}
|
||||
|
||||
public static float ToUnityZPosition(float gameBoxZPosition)
|
||||
{
|
||||
return gameBoxZPosition / GameBoxUnitToUnityUnit;
|
||||
}
|
||||
|
||||
public static float ToGameBoxXRotation(float eulerAnglesX)
|
||||
{
|
||||
return eulerAnglesX;
|
||||
}
|
||||
|
||||
public static float ToGameBoxYRotation(float eulerAnglesY)
|
||||
{
|
||||
return -eulerAnglesY;
|
||||
}
|
||||
|
||||
public static float ToGameBoxZRotation(float eulerAnglesZ)
|
||||
{
|
||||
return eulerAnglesZ;
|
||||
}
|
||||
|
||||
public static Quaternion ToUnityRotation(Vector3 gameBoxEulerAngles)
|
||||
{
|
||||
return Quaternion.Euler(
|
||||
gameBoxEulerAngles.x,
|
||||
-gameBoxEulerAngles.y,
|
||||
gameBoxEulerAngles.z);
|
||||
}
|
||||
|
||||
public static Vector3 ToGameBoxPosition(Vector3 position, float scale = GameBoxUnitToUnityUnit)
|
||||
{
|
||||
return new Vector3(
|
||||
@@ -39,7 +79,7 @@ namespace Core.GameBox
|
||||
position.z * scale);
|
||||
}
|
||||
|
||||
public static Vector3 CvdPositionToUnityPosition(Vector3 cvdPosition, float scale = GameBoxCvdUnitToUnityUnit)
|
||||
public static Vector3 CvdPositionToUnityPosition(Vector3 cvdPosition, float scale = GameBoxUnitToUnityUnit)
|
||||
{
|
||||
return new Vector3(
|
||||
-cvdPosition.x / scale,
|
||||
@@ -62,7 +102,7 @@ namespace Core.GameBox
|
||||
normal.y,
|
||||
normal.z);
|
||||
}
|
||||
|
||||
|
||||
public static Quaternion CvdQuaternionToUnityQuaternion(GameBoxQuaternion quaternion)
|
||||
{
|
||||
return new Quaternion(-quaternion.X, quaternion.Z, -quaternion.Y, quaternion.W);
|
||||
@@ -72,7 +112,7 @@ namespace Core.GameBox
|
||||
{
|
||||
return new Quaternion(-quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
|
||||
}
|
||||
|
||||
|
||||
public static Quaternion LgtQuaternionToUnityQuaternion(GameBoxQuaternion quaternion)
|
||||
{
|
||||
var rotation = new Quaternion(quaternion.X, quaternion.Y, -quaternion.Z, quaternion.W);
|
||||
@@ -87,6 +127,9 @@ namespace Core.GameBox
|
||||
return Quaternion.Euler(pitch - 180, yaw, roll -180);
|
||||
}
|
||||
|
||||
// Since GameBox engine uses different internal axis system.
|
||||
// Here we are flipping the x here to minor it back to the Unity axis.
|
||||
// Also we want to scale it to proper unity unit.
|
||||
private static Vector3 ToUnityVector3(Vector3 vector3, float scale)
|
||||
{
|
||||
return new Vector3(
|
||||
@@ -94,7 +137,7 @@ namespace Core.GameBox
|
||||
vector3.y / scale,
|
||||
vector3.z / scale);
|
||||
}
|
||||
|
||||
|
||||
public static void ToUnityTriangles(List<int> triangles)
|
||||
{
|
||||
triangles.Reverse();
|
||||
@@ -105,12 +148,12 @@ namespace Core.GameBox
|
||||
Array.Reverse(triangles);
|
||||
}
|
||||
|
||||
public static bool IsPositionInsideRect(GameBoxRect rect, Vector2Int position)
|
||||
public static bool IsPointInsideRect(GameBoxRect rect, Vector2Int point)
|
||||
{
|
||||
return position.x >= rect.Left &&
|
||||
position.x <= rect.Right &&
|
||||
position.y >= rect.Top &&
|
||||
position.y <= rect.Bottom;
|
||||
return point.x >= rect.Left &&
|
||||
point.x <= rect.Right &&
|
||||
point.y >= rect.Top &&
|
||||
point.y <= rect.Bottom;
|
||||
}
|
||||
|
||||
public static Matrix4x4 ToUnityMatrix4x4(GameBoxMatrix4X4 matrix)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -39,14 +39,6 @@ namespace Core.GameBox
|
||||
public float W;
|
||||
}
|
||||
|
||||
// GameBox axis-aligned bounding box
|
||||
[System.Serializable]
|
||||
public struct GameBoxAABBox
|
||||
{
|
||||
public Vector3 Min;
|
||||
public Vector3 Max;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct GameBoxRect
|
||||
{
|
||||
@@ -54,6 +46,11 @@ namespace Core.GameBox
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
|
||||
public bool IsEmpty => Left == 0 &&
|
||||
Top == 0 &&
|
||||
Right == 0 &&
|
||||
Bottom == 0;
|
||||
}
|
||||
|
||||
public static class GameBoxVertexType
|
||||
@@ -79,14 +76,14 @@ namespace Core.GameBox
|
||||
InvertColorBlend, // srcAlpha, One , +
|
||||
AdditiveBlend, //
|
||||
}
|
||||
|
||||
|
||||
public enum GameBoxLightType
|
||||
{
|
||||
Omni, // point light
|
||||
Spot, // spot light
|
||||
Directional, // directional light
|
||||
}
|
||||
|
||||
|
||||
public enum GameBoxLightDecayType
|
||||
{
|
||||
None,
|
||||
@@ -99,7 +96,7 @@ namespace Core.GameBox
|
||||
Cone,
|
||||
Square,
|
||||
}
|
||||
|
||||
|
||||
public static class GameBoxVertex
|
||||
{
|
||||
public static int GetSize(uint vertexType)
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Core.Renderer
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimatedBillboardRenderer : MonoBehaviour
|
||||
{
|
||||
private Sprite[] _sprites;
|
||||
private WaitForSeconds _spriteAnimationFrameWaiter;
|
||||
private bool _initialized;
|
||||
|
||||
private StaticBillboardRenderer _billboardRenderer;
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
private bool _isPlaying;
|
||||
private CancellationTokenSource _animationCts = new ();
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
@@ -22,46 +27,77 @@ namespace Core.Renderer
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_isPlaying = false;
|
||||
_animationCts.Cancel();
|
||||
Destroy(_billboardRenderer);
|
||||
Destroy(_spriteRenderer);
|
||||
}
|
||||
|
||||
public IEnumerator PlaySpriteAnimation(Sprite[] sprites,
|
||||
public void Init(Sprite[] sprites,
|
||||
float fps,
|
||||
int loopCount,
|
||||
Material material = default)
|
||||
{
|
||||
_isPlaying = true;
|
||||
|
||||
_sprites = sprites;
|
||||
|
||||
if (material != default)
|
||||
{
|
||||
_spriteRenderer.material = material;
|
||||
}
|
||||
|
||||
_spriteAnimationFrameWaiter = new WaitForSeconds(1 / fps);
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
public void StartAnimation(int loopCount = -1)
|
||||
{
|
||||
StartCoroutine(PlayAnimationAsync(loopCount));
|
||||
}
|
||||
|
||||
public IEnumerator PlayAnimationAsync(int loopCount)
|
||||
{
|
||||
if (!_initialized) yield break;
|
||||
|
||||
_animationCts.Cancel();
|
||||
_animationCts = new CancellationTokenSource();
|
||||
var cancellationToken = _animationCts.Token;
|
||||
|
||||
_spriteRenderer.enabled = true;
|
||||
|
||||
if (loopCount == -1)
|
||||
{
|
||||
while (_isPlaying)
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
yield return PlaySpriteAnimationInternal(sprites, fps);
|
||||
yield return PlaySpriteAnimationInternalAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (--loopCount >= 0 && _isPlaying)
|
||||
while (--loopCount >= 0 && !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
yield return PlaySpriteAnimationInternal(sprites, fps);
|
||||
}
|
||||
yield return PlaySpriteAnimationInternalAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator PlaySpriteAnimationInternal(Sprite[] sprites, float fps)
|
||||
public void StopAnimation()
|
||||
{
|
||||
foreach (Sprite sprite in sprites)
|
||||
if (_initialized && !_animationCts.IsCancellationRequested)
|
||||
{
|
||||
if (!_isPlaying) yield break;
|
||||
_animationCts.Cancel();
|
||||
_spriteRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator PlaySpriteAnimationInternalAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (Sprite sprite in _sprites)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
_spriteRenderer.sprite = sprite;
|
||||
yield return new WaitForSeconds(1 / fps);
|
||||
yield return _spriteAnimationFrameWaiter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -53,18 +53,13 @@ namespace Core.Utils
|
||||
{
|
||||
var structSize = Marshal.SizeOf(typeof(T));
|
||||
byte[] buffer = new byte[structSize];
|
||||
stream.Read(buffer);
|
||||
_ = stream.Read(buffer);
|
||||
return ReadStructInternal<T>(buffer);
|
||||
}
|
||||
|
||||
public static T ReadStruct<T>(ReadOnlySpan<byte> bytes, int offset = 0) where T : struct
|
||||
{
|
||||
return ReadStructInternal<T>(bytes, offset);
|
||||
|
||||
}
|
||||
public static bool ByteArrayCompare(ReadOnlySpan<byte> a1, ReadOnlySpan<byte> a2)
|
||||
{
|
||||
return a1.SequenceEqual(a2);
|
||||
}
|
||||
|
||||
private static unsafe T ReadStructInternal<T>(ReadOnlySpan<byte> bytes, int offset = 0) where T : struct
|
||||
@@ -164,10 +159,22 @@ namespace Core.Utils
|
||||
return finalBounds;
|
||||
}
|
||||
|
||||
public static bool IsPointWithinCollider(Collider collider, Vector3 point)
|
||||
{
|
||||
if (collider == null) return false;
|
||||
return collider.ClosestPoint(point) == point;
|
||||
}
|
||||
|
||||
public static bool IsPointWithinCollider(Collider collider, Vector3 point, float tolerance)
|
||||
{
|
||||
if (collider == null) return false;
|
||||
return Vector3.Distance(collider.ClosestPoint(point), point) < tolerance;
|
||||
}
|
||||
|
||||
public static Vector3[] CalculateNormals(Vector3[] vertices, int[] triangles)
|
||||
{
|
||||
Vector3[] normals = new Vector3[vertices.Length];
|
||||
|
||||
|
||||
for (var face = 0; face < triangles.Length / 3; face++)
|
||||
{
|
||||
int v1 = triangles[face * 3];
|
||||
@@ -201,7 +208,7 @@ namespace Core.Utils
|
||||
|
||||
return normals;
|
||||
}
|
||||
|
||||
|
||||
public static void DrawBounds(Bounds b, float duration = 1000)
|
||||
{
|
||||
var p1 = new Vector3(b.min.x, b.min.y, b.min.z);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class FeatureEnablement
|
||||
{
|
||||
[MenuItem("Pal3/Extra Features/Realtime lighting and shadow/Enable")]
|
||||
public static void EnableRealtimeLightingAndShadow()
|
||||
{
|
||||
SymbolsHelper.AddSymbol("RTX_ON");
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
[MenuItem("Pal3/Extra Features/Realtime lighting and shadow/Enable", true)]
|
||||
static bool ValidateEnableRealtimeLightingAndShadow()
|
||||
{
|
||||
return Resources.Load<Material>("Materials/Toon") != null && !SymbolsHelper.HasSymbol("RTX_ON");
|
||||
}
|
||||
|
||||
[MenuItem("Pal3/Extra Features/Realtime lighting and shadow/Disable")]
|
||||
public static void DisableRealtimeLightingAndShadow()
|
||||
{
|
||||
SymbolsHelper.RemoveSymbol("RTX_ON");
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
[MenuItem("Pal3/Extra Features/Realtime lighting and shadow/Disable", true)]
|
||||
static bool ValidateDisableRealtimeLightingAndShadow()
|
||||
{
|
||||
return Resources.Load<Material>("Materials/Toon") != null && SymbolsHelper.HasSymbol("RTX_ON");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29ac446b76204a4cbbaf5369808bf028
|
||||
timeCreated: 1667894961
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -14,40 +14,34 @@ namespace Editor
|
||||
|
||||
public static class GameVariantSwitcher
|
||||
{
|
||||
[MenuItem("Pal3/Switch Variant/PAL3")]
|
||||
[MenuItem("Pal3/Switch Variant/PAL3", priority = 1)]
|
||||
public static void SwitchToPal3()
|
||||
{
|
||||
RemoveSymbol("PAL3A");
|
||||
AddSymbol("PAL3");
|
||||
SymbolsHelper.RemoveSymbol("PAL3A");
|
||||
SymbolsHelper.AddSymbol("PAL3");
|
||||
ApplyPlayerSettingsForVariant("PAL3");
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
[MenuItem("Pal3/Switch Variant/PAL3A")]
|
||||
[MenuItem("Pal3/Switch Variant/PAL3", true)]
|
||||
static bool ValidateSwitchToPal3()
|
||||
{
|
||||
return !SymbolsHelper.HasSymbol("PAL3");
|
||||
}
|
||||
|
||||
[MenuItem("Pal3/Switch Variant/PAL3A", priority = 2)]
|
||||
public static void SwitchToPal3A()
|
||||
{
|
||||
RemoveSymbol("PAL3");
|
||||
AddSymbol("PAL3A");
|
||||
SymbolsHelper.RemoveSymbol("PAL3");
|
||||
SymbolsHelper.AddSymbol("PAL3A");
|
||||
ApplyPlayerSettingsForVariant("PAL3A");
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
private static BuildTargetGroup[] GetAllSupportedTargetGroups()
|
||||
[MenuItem("Pal3/Switch Variant/PAL3A", true)]
|
||||
static bool ValidateSwitchToPal3A()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
BuildTargetGroup.Android,
|
||||
BuildTargetGroup.Standalone,
|
||||
BuildTargetGroup.iOS,
|
||||
};
|
||||
}
|
||||
|
||||
private static NamedBuildTarget[] GetAllSupportedNamedBuildTargets()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
NamedBuildTarget.Android,
|
||||
NamedBuildTarget.Standalone,
|
||||
NamedBuildTarget.iOS,
|
||||
};
|
||||
return !SymbolsHelper.HasSymbol("PAL3A");
|
||||
}
|
||||
|
||||
private static void ApplyPlayerSettingsForVariant(string appName)
|
||||
@@ -55,7 +49,7 @@ namespace Editor
|
||||
PlayerSettings.productName = appName;
|
||||
PlayerSettings.companyName = GameConstants.CompanyName;
|
||||
|
||||
foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups())
|
||||
foreach (BuildTargetGroup targetGroup in SymbolsHelper.GetAllSupportedTargetGroups())
|
||||
{
|
||||
PlayerSettings.SetApplicationIdentifier(targetGroup,
|
||||
$"{GameConstants.AppIdentifierPrefix}.{appName}");
|
||||
@@ -64,15 +58,15 @@ namespace Editor
|
||||
var gameIconPath = $"UI/game-icon-{appName}";
|
||||
var gameIcon = Resources.Load<Texture2D>(gameIconPath);
|
||||
if (gameIcon == null) throw new Exception($"Game icon not found: {gameIconPath}");
|
||||
|
||||
foreach (NamedBuildTarget buildTarget in GetAllSupportedNamedBuildTargets())
|
||||
|
||||
foreach (NamedBuildTarget buildTarget in SymbolsHelper.GetAllSupportedNamedBuildTargets())
|
||||
{
|
||||
// Set app icon
|
||||
var iconSizes = PlayerSettings.GetIconSizes(buildTarget, IconKind.Application);
|
||||
PlayerSettings.SetIcons(buildTarget,
|
||||
Enumerable.Repeat(gameIcon, iconSizes.Length).ToArray(),
|
||||
IconKind.Application);
|
||||
|
||||
|
||||
// Set iOS store icon which is required for store publishing or TestFlight
|
||||
if (buildTarget == NamedBuildTarget.iOS)
|
||||
{
|
||||
@@ -81,38 +75,6 @@ namespace Editor
|
||||
PlayerSettings.GetIconSizes(buildTarget, IconKind.Store).Length).ToArray(),
|
||||
IconKind.Store);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
private static void AddSymbol(string symbolToAdd)
|
||||
{
|
||||
foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups())
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
var allDefines = defines.Split(';').ToList();
|
||||
if (!allDefines.Any(_ => string.Equals(_, symbolToAdd)))
|
||||
{
|
||||
allDefines.Add(symbolToAdd);
|
||||
}
|
||||
allDefines.Sort();
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup,
|
||||
string.Join(";", allDefines.ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void RemoveSymbol(string symbolToDelete)
|
||||
{
|
||||
foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups())
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
var allDefines = defines.Split(';').ToList();
|
||||
var newDefines = allDefines
|
||||
.Where(_ => !string.Equals(_, symbolToDelete)).ToList();
|
||||
newDefines.Sort();
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup,
|
||||
string.Join(";", newDefines.ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -9,9 +9,8 @@ namespace Editor.SourceGenerator
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Base;
|
||||
using Pal3.Command.SceCommands;
|
||||
using IngameDebugConsole;
|
||||
using Pal3.Command.InternalCommands;
|
||||
using Pal3.Command;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -53,8 +52,6 @@ namespace Editor.SourceGenerator
|
||||
|
||||
for (var i = 0; i < commands.Length; i++)
|
||||
{
|
||||
//if (!IsCommandAvailableInConsole(commands[i])) continue;
|
||||
|
||||
var commandName = commands[i].Name.Replace("Command", string.Empty);
|
||||
var properties = commands[i].GetProperties();
|
||||
|
||||
@@ -95,9 +92,7 @@ namespace Editor.SourceGenerator
|
||||
|
||||
private static bool IsCommandAvailableInConsole(Type command)
|
||||
{
|
||||
if (command == typeof(ResetGameStateCommand)) return true;
|
||||
return command.GetCustomAttributes()
|
||||
.Any(attribute => attribute is SceCommandAttribute {IsAvailableInConsole: true});
|
||||
return command.GetCustomAttributes().Any(attribute => attribute is AvailableInConsoleAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Editor
|
||||
{
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
|
||||
public static class SymbolsHelper
|
||||
{
|
||||
public static BuildTargetGroup[] GetAllSupportedTargetGroups()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
BuildTargetGroup.Android,
|
||||
BuildTargetGroup.Standalone,
|
||||
BuildTargetGroup.iOS,
|
||||
};
|
||||
}
|
||||
|
||||
public static NamedBuildTarget[] GetAllSupportedNamedBuildTargets()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
NamedBuildTarget.Android,
|
||||
NamedBuildTarget.Standalone,
|
||||
NamedBuildTarget.iOS,
|
||||
};
|
||||
}
|
||||
|
||||
public static bool HasSymbol(string symbol)
|
||||
{
|
||||
return GetAllSupportedTargetGroups()
|
||||
.Select(PlayerSettings.GetScriptingDefineSymbolsForGroup)
|
||||
.Select(defines => defines.Split(';').ToList())
|
||||
.All(allDefines => allDefines.Contains(symbol));
|
||||
}
|
||||
|
||||
public static void AddSymbol(string symbolToAdd)
|
||||
{
|
||||
foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups())
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
var allDefines = defines.Split(';').ToList();
|
||||
if (!allDefines.Any(_ => string.Equals(_, symbolToAdd)))
|
||||
{
|
||||
allDefines.Add(symbolToAdd);
|
||||
}
|
||||
allDefines.Sort();
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup,
|
||||
string.Join(";", allDefines.ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveSymbol(string symbolToDelete)
|
||||
{
|
||||
foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups())
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
var allDefines = defines.Split(';').ToList();
|
||||
var newDefines = allDefines
|
||||
.Where(_ => !string.Equals(_, symbolToDelete)).ToList();
|
||||
newDefines.Sort();
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup,
|
||||
string.Join(";", newDefines.ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf514aeafd514072afb9dc35e364cf81
|
||||
timeCreated: 1667895294
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -70,17 +70,17 @@ namespace Pal3.Actor
|
||||
return ActorConstants.ActionNames[ActorActionType.NpcStand1];
|
||||
}
|
||||
|
||||
public string GetMovementAction(int mode)
|
||||
public string GetMovementAction(MovementMode mode)
|
||||
{
|
||||
if (IsMainActor())
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
0 => ActorConstants.ActionNames[ActorActionType.Walk],
|
||||
1 => HasAction(ActorConstants.ActionNames[ActorActionType.Run])
|
||||
MovementMode.Walk => ActorConstants.ActionNames[ActorActionType.Walk],
|
||||
MovementMode.Run => HasAction(ActorConstants.ActionNames[ActorActionType.Run])
|
||||
? ActorConstants.ActionNames[ActorActionType.Run]
|
||||
: ActorConstants.ActionNames[ActorActionType.Walk],
|
||||
2 => ActorConstants.ActionNames[ActorActionType.Back],
|
||||
MovementMode.StepBack => ActorConstants.ActionNames[ActorActionType.StepBack],
|
||||
_ => ActorConstants.ActionNames[ActorActionType.Walk]
|
||||
};
|
||||
}
|
||||
@@ -92,8 +92,8 @@ namespace Pal3.Actor
|
||||
|
||||
return mode switch
|
||||
{
|
||||
0 => ActorConstants.ActionNames[ActorActionType.NpcWalk],
|
||||
1 => ActorConstants.ActionNames[ActorActionType.NpcRun],
|
||||
MovementMode.Walk => ActorConstants.ActionNames[ActorActionType.NpcWalk],
|
||||
MovementMode.Run => ActorConstants.ActionNames[ActorActionType.NpcRun],
|
||||
_ => ActorConstants.ActionNames[ActorActionType.NpcWalk]
|
||||
};
|
||||
}
|
||||
@@ -110,11 +110,11 @@ namespace Pal3.Actor
|
||||
return Info.Kind switch
|
||||
{
|
||||
ScnActorKind.Soldier => 4f,
|
||||
ScnActorKind.MainActor => 2.5f,
|
||||
ScnActorKind.MainActor => 4f,
|
||||
ScnActorKind.StoryNpc => 4f,
|
||||
ScnActorKind.HotelManager => 6f,
|
||||
ScnActorKind.Dealer => 6f,
|
||||
_ => -1f
|
||||
_ => 4f
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -40,7 +40,9 @@ namespace Pal3.Actor
|
||||
ICommandExecutor<GameStateChangedNotification>
|
||||
{
|
||||
private const float EMOJI_ANIMATION_FPS = 5f;
|
||||
|
||||
private const float ACTOR_COLLIDER_RADIUS_MIN = 0.5f;
|
||||
private const float ACTOR_COLLIDER_RADIUS_MAX = 1.5f;
|
||||
|
||||
private GameResourceProvider _resourceProvider;
|
||||
private Actor _actor;
|
||||
private Color _tintColor;
|
||||
@@ -52,9 +54,10 @@ namespace Pal3.Actor
|
||||
private Mv3ModelRenderer _mv3AnimationRenderer;
|
||||
private WaitUntilCanceled _animationLoopPointWaiter;
|
||||
|
||||
private Bounds _worldBounds;
|
||||
private Bounds _localBounds;
|
||||
private Bounds _rendererBounds;
|
||||
private Bounds _meshBounds;
|
||||
|
||||
private bool _hasColliderAndRigidBody;
|
||||
private Rigidbody _rigidbody;
|
||||
private CapsuleCollider _collider;
|
||||
|
||||
@@ -62,10 +65,14 @@ namespace Pal3.Actor
|
||||
// Also, the player actor is only non-kinematic during gameplay state.
|
||||
private bool _isKinematic = true;
|
||||
|
||||
public void Init(GameResourceProvider resourceProvider, Actor actor, Color tintColor)
|
||||
public void Init(GameResourceProvider resourceProvider,
|
||||
Actor actor,
|
||||
bool hasColliderAndRigidBody,
|
||||
Color tintColor)
|
||||
{
|
||||
_resourceProvider = resourceProvider;
|
||||
_actor = actor;
|
||||
_hasColliderAndRigidBody = hasColliderAndRigidBody;
|
||||
_tintColor = tintColor;
|
||||
}
|
||||
|
||||
@@ -106,12 +113,23 @@ namespace Pal3.Actor
|
||||
return _currentAction;
|
||||
}
|
||||
|
||||
public bool IsCurrentActionIdleAction()
|
||||
{
|
||||
return !string.IsNullOrEmpty(_currentAction) &&
|
||||
string.Equals(_currentAction, _actor.GetIdleAction(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public Rigidbody GetRigidBody()
|
||||
{
|
||||
return _rigidbody;
|
||||
}
|
||||
|
||||
public void PerformAction(ActorActionType actorActionType, bool overwrite = false, int loopCount = -1)
|
||||
public CapsuleCollider GetCollider()
|
||||
{
|
||||
return _collider;
|
||||
}
|
||||
|
||||
public void PerformAction(ActorActionType actorActionType)
|
||||
{
|
||||
PerformAction(ActorConstants.ActionNames[actorActionType]);
|
||||
}
|
||||
@@ -156,7 +174,7 @@ namespace Pal3.Actor
|
||||
|
||||
ActorActionType actionType = ActorConstants.ActionNames
|
||||
.FirstOrDefault(_ => string.Equals(_.Value, actionName, StringComparison.OrdinalIgnoreCase)).Key;
|
||||
|
||||
|
||||
if (mv3File.TagNodes is {Length: > 0} && _actor.GetWeaponName() is {} weaponName &&
|
||||
ActorConstants.ActionNameToWeaponArmTypeMap[actionType] != WeaponArmType.None)
|
||||
{
|
||||
@@ -168,7 +186,7 @@ namespace Pal3.Actor
|
||||
(PolFile polFile, ITextureResourceProvider weaponTextureProvider) = _resourceProvider.GetPol(weaponPath);
|
||||
_mv3AnimationRenderer.Init(mv3File,
|
||||
_resourceProvider.GetMaterialFactory(),
|
||||
textureProvider,
|
||||
textureProvider,
|
||||
_tintColor,
|
||||
polFile,
|
||||
weaponTextureProvider,
|
||||
@@ -183,10 +201,10 @@ namespace Pal3.Actor
|
||||
}
|
||||
|
||||
_mv3AnimationRenderer.AnimationLoopPointReached += AnimationLoopPointReached;
|
||||
_mv3AnimationRenderer.PlayAnimation(loopCount);
|
||||
_mv3AnimationRenderer.StartAnimation(loopCount);
|
||||
|
||||
_worldBounds = _mv3AnimationRenderer.GetWorldBounds();
|
||||
_localBounds = _mv3AnimationRenderer.GetLocalBounds();
|
||||
_rendererBounds = _mv3AnimationRenderer.GetRendererBounds();
|
||||
_meshBounds = _mv3AnimationRenderer.GetMeshBounds();
|
||||
|
||||
ActorActionType action = ActorConstants.ActionNames
|
||||
.FirstOrDefault(a => a.Value.Equals(_currentAction)).Key;
|
||||
@@ -194,14 +212,17 @@ namespace Pal3.Actor
|
||||
#if !RTX_ON
|
||||
SetupShadow(action);
|
||||
#endif
|
||||
|
||||
SetupCollider();
|
||||
SetupRigidBody();
|
||||
|
||||
if (_hasColliderAndRigidBody)
|
||||
{
|
||||
SetupCollider();
|
||||
SetupRigidBody();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupShadow(ActorActionType actorAction)
|
||||
{
|
||||
// Disable shadow for HuaYing and TaoZi
|
||||
// Disable shadow for some of the actors.
|
||||
#if PAL3
|
||||
if (_actor.Info.Id == (byte) PlayerActorId.HuaYing) return;
|
||||
#elif PAL3A
|
||||
@@ -234,10 +255,28 @@ namespace Pal3.Actor
|
||||
_collider = gameObject.AddComponent<CapsuleCollider>();
|
||||
}
|
||||
|
||||
Bounds bounds = GetLocalBounds();
|
||||
Bounds bounds = GetMeshBounds();
|
||||
_collider.center = bounds.center;
|
||||
_collider.height = bounds.size.y;
|
||||
_collider.radius = bounds.size.x * 0.35f;
|
||||
|
||||
// Add a little bit of height to make sure the bottom point of the
|
||||
// collider is below the ground. This is to make sure actor can
|
||||
// interact with StandingPlatform correctly.
|
||||
_collider.height = bounds.size.y + 1f;
|
||||
|
||||
if (_actor.IsMainActor())
|
||||
{
|
||||
// Unify the radius of the collider for main actor.
|
||||
// This is to make sure the main actor can always have
|
||||
// expected behavior when interacting with standing platform.
|
||||
_collider.radius = ACTOR_COLLIDER_RADIUS_MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
_collider.radius = Mathf.Min(Mathf.Max(
|
||||
Mathf.Sqrt(bounds.size.x * bounds.size.x + bounds.size.z * bounds.size.z) * 0.3f,
|
||||
ACTOR_COLLIDER_RADIUS_MIN),
|
||||
ACTOR_COLLIDER_RADIUS_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupRigidBody()
|
||||
@@ -257,41 +296,40 @@ namespace Pal3.Actor
|
||||
private void RenderShadow()
|
||||
{
|
||||
_shadow = new GameObject("Shadow");
|
||||
_shadow.transform.SetParent(transform, false);
|
||||
Transform shadowTransform = _shadow.transform;
|
||||
shadowTransform.localRotation = Quaternion.Euler(90f, 0f, 0f);
|
||||
shadowTransform.localScale = new Vector3(1.4f, 1.4f, 1f);
|
||||
shadowTransform.localPosition = new Vector3(0f, 0.07f, 0f);
|
||||
|
||||
Texture2D shadowTexture = _resourceProvider.GetShadowTexture();
|
||||
_shadowSpriteRenderer = _shadow.AddComponent<SpriteRenderer>();
|
||||
_shadowSpriteRenderer.sprite = Sprite.Create(shadowTexture,
|
||||
new Rect(0, 0, shadowTexture.width, shadowTexture.height),
|
||||
new Vector2(0.5f, 0.5f));
|
||||
_shadowSpriteRenderer.color = new Color(0f, 0f, 0f, 0.7f);
|
||||
Transform shadowTransform = _shadow.transform;
|
||||
shadowTransform.rotation = Quaternion.Euler(90f, 0f, 0f);
|
||||
shadowTransform.localScale = new Vector3(1.4f, 1.4f, 1f);
|
||||
shadowTransform.localPosition = new Vector3(0f, 0.07f, 0f);
|
||||
_shadow.transform.SetParent(transform, false);
|
||||
}
|
||||
|
||||
private IEnumerator ShowEmojiAnimation(ActorEmojiType emojiType)
|
||||
private IEnumerator ShowEmojiAnimationAsync(ActorEmojiType emojiType)
|
||||
{
|
||||
if (!_actor.IsActive) yield break;
|
||||
|
||||
|
||||
// For some reason, there are 12 emoji types exist in the game script,
|
||||
// but only 11 sprite sheet in the data folder (PAL3A has 12 but PAL3 has 11).
|
||||
if (!Enum.IsDefined(typeof(ActorEmojiType), emojiType)) yield break;
|
||||
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
|
||||
var sprites = _resourceProvider.GetEmojiSprites(emojiType);
|
||||
|
||||
var emojiGameObject = new GameObject($"Emoji_{emojiType.ToString()}");
|
||||
emojiGameObject.transform.SetParent(transform);
|
||||
emojiGameObject.transform.SetParent(transform, false);
|
||||
emojiGameObject.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
||||
Vector3 actorHeadPosition = GetActorHeadWorldPosition();
|
||||
emojiGameObject.transform.position = new Vector3(actorHeadPosition.x,
|
||||
actorHeadPosition.y + 0.1f, // With a small Y offset
|
||||
actorHeadPosition.z);
|
||||
emojiGameObject.transform.localPosition = new Vector3(0f, GetActorHeight(), 0f);
|
||||
|
||||
var billboardRenderer = emojiGameObject.AddComponent<AnimatedBillboardRenderer>();
|
||||
billboardRenderer.Init(sprites, EMOJI_ANIMATION_FPS);
|
||||
|
||||
#if PAL3
|
||||
var emojiSfx = ActorEmojiConstants.EmojiSfxInfo[emojiType];
|
||||
@@ -300,43 +338,34 @@ namespace Pal3.Actor
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new PlaySfxCommand(emojiSfx, 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
yield return billboardRenderer.PlaySpriteAnimation(sprites,
|
||||
EMOJI_ANIMATION_FPS,
|
||||
ActorEmojiConstants.AnimationLoopCountInfo[emojiType]);
|
||||
|
||||
yield return billboardRenderer.PlayAnimationAsync(ActorEmojiConstants.AnimationLoopCountInfo[emojiType]);
|
||||
|
||||
Destroy(billboardRenderer);
|
||||
Destroy(emojiGameObject);
|
||||
waiter.CancelWait();
|
||||
}
|
||||
|
||||
public Vector3 GetActorHeadWorldPosition()
|
||||
|
||||
public float GetActorHeight()
|
||||
{
|
||||
Vector3 parentPosition = transform.position;
|
||||
|
||||
if (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible())
|
||||
{
|
||||
return new Vector3(parentPosition.x,
|
||||
parentPosition.y + _localBounds.size.y,
|
||||
parentPosition.z);
|
||||
return _meshBounds.size.y;
|
||||
}
|
||||
|
||||
return new Vector3(parentPosition.x,
|
||||
parentPosition.y +
|
||||
_mv3AnimationRenderer.GetLocalBounds().size.y,
|
||||
parentPosition.z);
|
||||
}
|
||||
|
||||
public Bounds GetWorldBounds()
|
||||
{
|
||||
return (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible()) ? _worldBounds :
|
||||
_mv3AnimationRenderer.GetWorldBounds();
|
||||
|
||||
return _mv3AnimationRenderer.GetMeshBounds().size.y;
|
||||
}
|
||||
|
||||
public Bounds GetLocalBounds()
|
||||
public Bounds GetRendererBounds()
|
||||
{
|
||||
return (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible()) ? _localBounds :
|
||||
_mv3AnimationRenderer.GetLocalBounds();
|
||||
return (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible()) ? _rendererBounds :
|
||||
_mv3AnimationRenderer.GetRendererBounds();
|
||||
}
|
||||
|
||||
public Bounds GetMeshBounds()
|
||||
{
|
||||
return (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible()) ? _meshBounds :
|
||||
_mv3AnimationRenderer.GetMeshBounds();
|
||||
}
|
||||
|
||||
private void AnimationLoopPointReached(object _, int loopCount)
|
||||
@@ -346,7 +375,7 @@ namespace Pal3.Actor
|
||||
_animationLoopPointWaiter?.CancelWait();
|
||||
}
|
||||
|
||||
if (_autoStand)
|
||||
if (_autoStand && _mv3AnimationRenderer.IsVisible())
|
||||
{
|
||||
if (loopCount is 0 ||
|
||||
(loopCount is -2 && !_mv3AnimationRenderer.IsActionInHoldState()))
|
||||
@@ -423,9 +452,9 @@ namespace Pal3.Actor
|
||||
WaitUntilCanceled waiter = null;
|
||||
if (command.LoopCount is > 0 or -2)
|
||||
{
|
||||
waiter = new WaitUntilCanceled(this);
|
||||
waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ScriptRunnerWaitRequest(waiter));
|
||||
new ScriptRunnerAddWaiterRequest(waiter));
|
||||
}
|
||||
PerformAction(command.ActionName, true, command.LoopCount, waiter);
|
||||
}
|
||||
@@ -440,9 +469,9 @@ namespace Pal3.Actor
|
||||
if (_mv3AnimationRenderer.IsActionInHoldState())
|
||||
{
|
||||
_animationLoopPointWaiter?.CancelWait();
|
||||
_animationLoopPointWaiter = new WaitUntilCanceled(this);
|
||||
_animationLoopPointWaiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ScriptRunnerWaitRequest(_animationLoopPointWaiter));
|
||||
new ScriptRunnerAddWaiterRequest(_animationLoopPointWaiter));
|
||||
|
||||
_mv3AnimationRenderer.ResumeAction();
|
||||
}
|
||||
@@ -451,7 +480,7 @@ namespace Pal3.Actor
|
||||
_mv3AnimationRenderer.PauseAnimation();
|
||||
_animationLoopPointWaiter?.CancelWait();
|
||||
|
||||
if (_autoStand)
|
||||
if (_autoStand && _mv3AnimationRenderer.IsVisible())
|
||||
{
|
||||
PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
@@ -499,18 +528,18 @@ namespace Pal3.Actor
|
||||
_rigidbody.isKinematic = _isKinematic;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Execute(ActorShowEmojiCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
StartCoroutine(ShowEmojiAnimation((ActorEmojiType) command.EmojiId));
|
||||
StartCoroutine(ShowEmojiAnimationAsync((ActorEmojiType) command.EmojiId));
|
||||
}
|
||||
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(ActorShowEmoji2Command command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
StartCoroutine(ShowEmojiAnimation((ActorEmojiType) command.EmojiId));
|
||||
StartCoroutine(ShowEmojiAnimationAsync((ActorEmojiType) command.EmojiId));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,31 +1,33 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.Animation;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.GameBox;
|
||||
using Core.Services;
|
||||
using Input;
|
||||
using MetaData;
|
||||
using Player;
|
||||
using Scene;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
|
||||
public class ActorController : MonoBehaviour,
|
||||
ICommandExecutor<ActorSetFacingCommand>,
|
||||
ICommandExecutor<ActorSetFacingDirectionCommand>,
|
||||
ICommandExecutor<ActorRotateFacingCommand>,
|
||||
ICommandExecutor<ActorRotateFacingDirectionCommand>,
|
||||
ICommandExecutor<ActorSetScriptCommand>,
|
||||
#if PAL3A
|
||||
ICommandExecutor<ActorSetYPositionCommand>,
|
||||
#endif
|
||||
ICommandExecutor<ActorChangeScaleCommand>
|
||||
{
|
||||
private Actor _actor;
|
||||
@@ -51,6 +53,8 @@ namespace Pal3.Actor
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isScriptChanged;
|
||||
|
||||
private ScnActorBehaviour _currentBehaviour;
|
||||
|
||||
public void Init(Actor actor,
|
||||
@@ -78,11 +82,25 @@ namespace Pal3.Actor
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
public bool IsInteractable(float distance)
|
||||
public ScnActorBehaviour GetCurrentBehaviour()
|
||||
{
|
||||
var maxInteractionDistance = _actor.GetInteractionMaxDistance();
|
||||
if (distance > maxInteractionDistance) return false;
|
||||
return _actor.Info.ScriptId != 0;
|
||||
return _currentBehaviour;
|
||||
}
|
||||
|
||||
public bool IsDirectlyInteractable(float distance)
|
||||
{
|
||||
if (distance > _actor.GetInteractionMaxDistance()) return false;
|
||||
return _actor.Info.ScriptId != ScriptConstants.InvalidScriptId;
|
||||
}
|
||||
|
||||
public Actor GetActor()
|
||||
{
|
||||
return _actor;
|
||||
}
|
||||
|
||||
public bool IsScriptChanged()
|
||||
{
|
||||
return _isScriptChanged;
|
||||
}
|
||||
|
||||
private void Activate()
|
||||
@@ -95,12 +113,12 @@ namespace Pal3.Actor
|
||||
_actor.ChangeName(ActorConstants.NanGongHuangHumanModeActorName);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (_actor.Info.Kind == ScnActorKind.MainActor)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_actionController.GetCurrentAction()))
|
||||
{
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -112,10 +130,7 @@ namespace Pal3.Actor
|
||||
{
|
||||
case ScnActorBehaviour.None:
|
||||
_currentBehaviour = ScnActorBehaviour.None;
|
||||
_actionController.PerformAction(_actor.Info.Kind != ScnActorKind.HotelManager &&
|
||||
_actor.Info.Kind != ScnActorKind.StoryNpc
|
||||
? _actor.GetInitAction()
|
||||
: _actor.GetIdleAction());
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
break;
|
||||
case ScnActorBehaviour.Hold:
|
||||
_currentBehaviour = ScnActorBehaviour.Hold;
|
||||
@@ -132,15 +147,15 @@ namespace Pal3.Actor
|
||||
}
|
||||
}
|
||||
|
||||
if (_currentBehaviour == ScnActorBehaviour.PathFollow)
|
||||
if (_currentBehaviour == ScnActorBehaviour.PathFollow &&
|
||||
_actor.Info.Path.NumberOfWaypoints > 0)
|
||||
{
|
||||
var waypoints = _actor.Info.Path.Waypoints
|
||||
.Where(p => p != Vector3.zero)
|
||||
.Select(waypoint => GameBoxInterpreter.ToUnityPosition(waypoint)).ToArray();
|
||||
if (waypoints.Length > 0)
|
||||
var waypoints = new Vector3[_actor.Info.Path.NumberOfWaypoints];
|
||||
for (var i = 0; i < _actor.Info.Path.NumberOfWaypoints; i++)
|
||||
{
|
||||
_movementController.SetupPath(waypoints, 0, EndOfPathActionType.Reverse, ignoreObstacle: true);
|
||||
waypoints[i] = GameBoxInterpreter.ToUnityPosition(_actor.Info.Path.GameBoxWaypoints[i]);
|
||||
}
|
||||
_movementController.SetupPath(waypoints, 0, EndOfPathActionType.WaitAndReverse, ignoreObstacle: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,9 +164,28 @@ namespace Pal3.Actor
|
||||
_actionController.DeActivate();
|
||||
}
|
||||
|
||||
private IEnumerator AnimateScale(float toScale, float duration, WaitUntilCanceled waiter = null)
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
yield return AnimationHelper.EnumerateValue(transform.localScale.x,
|
||||
if (_actor.Info.Kind == ScnActorKind.CombatNpc &&
|
||||
ServiceLocator.Instance.Get<SceneManager>()
|
||||
.GetCurrentScene()
|
||||
.GetSceneInfo().SceneType == ScnSceneType.Maze &&
|
||||
collision.gameObject.GetComponent<ActorController>() is {} actorController &&
|
||||
(byte) ServiceLocator.Instance.Get<PlayerManager>()
|
||||
.GetPlayerActor() == actorController.GetActor().Info.Id)
|
||||
{
|
||||
// Player actor collides with combat NPC in maze
|
||||
// TODO: Implement combat
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new PlaySfxCommand("wd130", 1));
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorActivateCommand(_actor.Info.Id, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator AnimateScaleAsync(float toScale, float duration, WaitUntilCanceled waiter = null)
|
||||
{
|
||||
yield return AnimationHelper.EnumerateValueAsync(transform.localScale.x,
|
||||
toScale, duration, AnimationCurveType.Linear, value =>
|
||||
{
|
||||
transform.localScale = new Vector3(value, value, value);
|
||||
@@ -159,6 +193,12 @@ namespace Pal3.Actor
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
public void Execute(ActorSetFacingCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
transform.rotation = Quaternion.Euler(0, command.Degrees, 0);
|
||||
}
|
||||
|
||||
public void Execute(ActorRotateFacingCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
@@ -173,39 +213,67 @@ namespace Pal3.Actor
|
||||
public void Execute(ActorSetFacingDirectionCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
transform.rotation = Quaternion.Euler(0, -command.Direction * 45, 0);
|
||||
|
||||
if (command.Direction is >= 0 and < 8)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(0, -command.Direction * 45, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note: in the original game scripts, this command is sometimes misused to set the facing direction.
|
||||
// Instead of calling ActorRotateFacingCommand, there are places where the script calls
|
||||
// ActorSetFacingDirectionCommand. In this case, the direction parameter is actually the degrees
|
||||
// to rotate. Thus we need to handle this case here.
|
||||
int degrees = command.Direction;
|
||||
Execute(new ActorRotateFacingCommand(command.ActorId, degrees));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorRotateFacingDirectionCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
transform.rotation = Quaternion.Euler(0, -command.Direction * 45, 0);
|
||||
|
||||
if (command.Direction is >= 0 and < 8)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(0, -command.Direction * 45, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note: in the original game scripts, this command is sometimes misused to set the facing direction.
|
||||
// Instead of calling ActorRotateFacingCommand, there are places where the script calls
|
||||
// ActorRotateFacingDirectionCommand. In this case, the direction parameter is actually the degrees
|
||||
// to rotate. Thus we need to handle this case here.
|
||||
int degrees = command.Direction;
|
||||
Execute(new ActorRotateFacingCommand(command.ActorId, degrees));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorSetScriptCommand command)
|
||||
{
|
||||
if (command.ActorId != _actor.Info.Id) return;
|
||||
_actor.Info.ScriptId = (uint)command.ScriptId;
|
||||
if (_actor.Info.ScriptId != (uint) command.ScriptId)
|
||||
{
|
||||
_isScriptChanged = true;
|
||||
_actor.Info.ScriptId = (uint) command.ScriptId;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorChangeScaleCommand command)
|
||||
{
|
||||
if (command.ActorId != _actor.Info.Id) return;
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ScriptRunnerWaitRequest(waiter));
|
||||
StartCoroutine(AnimateScale(command.Scale, 2f, waiter));
|
||||
new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(AnimateScaleAsync(command.Scale, 2f, waiter));
|
||||
}
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(ActorSetYPositionCommand command)
|
||||
{
|
||||
if (command.ActorId != _actor.Info.Id) return;
|
||||
Vector3 oldPosition = transform.position;
|
||||
transform.position = new Vector3(oldPosition.x,
|
||||
command.YPosition / GameBoxInterpreter.GameBoxUnitToUnityUnit,
|
||||
GameBoxInterpreter.ToUnityYPosition(command.GameBoxYPosition),
|
||||
oldPosition.z);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Pal3.Actor
|
||||
Actor actor,
|
||||
Tilemap tilemap,
|
||||
Color tintColor,
|
||||
Func<int, byte[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
|
||||
Func<int, int[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
|
||||
{
|
||||
var actorGameObject = new GameObject($"Actor_{actor.Info.Id}_{actor.Info.Name}")
|
||||
{
|
||||
@@ -32,8 +32,14 @@ namespace Pal3.Actor
|
||||
npcInfoPresent.npcInfo = actor.Info;
|
||||
#endif
|
||||
|
||||
#if PAL3
|
||||
var hasColliderAndRigidBody = (PlayerActorId) actor.Info.Id != PlayerActorId.HuaYing;
|
||||
#elif PAL3A
|
||||
var hasColliderAndRigidBody = (PlayerActorId) actor.Info.Id != PlayerActorId.TaoZi;
|
||||
#endif
|
||||
|
||||
var actionController = actorGameObject.AddComponent<ActorActionController>();
|
||||
actionController.Init(resourceProvider, actor, tintColor);
|
||||
actionController.Init(resourceProvider, actor, hasColliderAndRigidBody, tintColor);
|
||||
|
||||
var movementController = actorGameObject.AddComponent<ActorMovementController>();
|
||||
movementController.Init(actor, tilemap, actionController, getAllActiveActorBlockingTilePositions);
|
||||
@@ -43,20 +49,20 @@ namespace Pal3.Actor
|
||||
|
||||
// Attach additional controller(s) to special actor
|
||||
#if PAL3
|
||||
switch (actor.Info.Id)
|
||||
switch ((PlayerActorId)actor.Info.Id)
|
||||
{
|
||||
case (byte)PlayerActorId.HuaYing:
|
||||
case PlayerActorId.HuaYing:
|
||||
actorGameObject.AddComponent<HuaYingController>().Init(actor, actorController, actionController);
|
||||
break;
|
||||
case (byte)PlayerActorId.LongKui:
|
||||
case PlayerActorId.LongKui:
|
||||
actorGameObject.AddComponent<LongKuiController>().Init(actor, actionController);
|
||||
break;
|
||||
}
|
||||
#elif PAL3A
|
||||
switch (actor.Info.Id)
|
||||
switch ((PlayerActorId)actor.Info.Id)
|
||||
{
|
||||
case (byte)PlayerActorId.TaoZi:
|
||||
actorGameObject.AddComponent<FlyingActorController>().Init(actor, actionController);
|
||||
case PlayerActorId.TaoZi:
|
||||
actorGameObject.AddComponent<FlyingActorController>().Init(actor, actorController, actionController);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -16,8 +16,10 @@ namespace Pal3.Actor
|
||||
using Core.DataReader.Nav;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.GameBox;
|
||||
using Core.Utils;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using Scene.SceneObjects.Common;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
@@ -29,8 +31,22 @@ namespace Pal3.Actor
|
||||
Completed,
|
||||
}
|
||||
|
||||
internal class ActiveColliderInfo
|
||||
{
|
||||
public Collider Collider;
|
||||
public Vector3 ActorPositionWhenCollisionEnter;
|
||||
}
|
||||
|
||||
internal class ActiveStandingPlatformInfo
|
||||
{
|
||||
public StandingPlatformController Platform;
|
||||
public Vector3 PlatformLastKnownPosition;
|
||||
public double TimeWhenEntered;
|
||||
}
|
||||
|
||||
public class ActorMovementController : MonoBehaviour,
|
||||
ICommandExecutor<ActorSetTilePositionCommand>,
|
||||
ICommandExecutor<ActorSetWorldPositionCommand>,
|
||||
ICommandExecutor<ActorPathToCommand>,
|
||||
#if PAL3A
|
||||
ICommandExecutor<ActorWalkToUsingActionCommand>,
|
||||
@@ -42,7 +58,10 @@ namespace Pal3.Actor
|
||||
ICommandExecutor<ActorActivateCommand>,
|
||||
ICommandExecutor<ActorSetNavLayerCommand>
|
||||
{
|
||||
private const float MAX_CROSS_LAYER_Y_DIFFERENTIAL = 2f;
|
||||
private const float MAX_Y_DIFFERENTIAL = 2.2f;
|
||||
private const float MAX_Y_DIFFERENTIAL_CROSS_LAYER = 2f;
|
||||
private const float MAX_Y_DIFFERENTIAL_CROSS_PLATFORM = 2f;
|
||||
private const float DEFAULT_ROTATION_SPEED = 20f;
|
||||
|
||||
private Actor _actor;
|
||||
private Tilemap _tilemap;
|
||||
@@ -50,44 +69,45 @@ namespace Pal3.Actor
|
||||
private int _currentLayerIndex = 0;
|
||||
|
||||
private readonly Path _currentPath = new ();
|
||||
private bool _isMovementOnHold;
|
||||
private WaitUntilCanceled _movementWaiter;
|
||||
private CancellationTokenSource _movementCts = new ();
|
||||
|
||||
private bool _isDuringCollision;
|
||||
private Vector3 _lastKnownValidPositionWhenCollisionEnter;
|
||||
private readonly HashSet<ActiveColliderInfo> _activeColliders = new ();
|
||||
private readonly HashSet<ActiveStandingPlatformInfo> _activeStandingPlatforms = new ();
|
||||
|
||||
private Func<int, byte[], HashSet<Vector2Int>> _getAllActiveActorBlockingTilePositions;
|
||||
private Func<int, int[], HashSet<Vector2Int>> _getAllActiveActorBlockingTilePositions;
|
||||
|
||||
public void Init(Actor actor, Tilemap tilemap, ActorActionController actionController,
|
||||
Func<int, byte[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
|
||||
Func<int, int[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
|
||||
{
|
||||
_actor = actor;
|
||||
_tilemap = tilemap;
|
||||
_actionController = actionController;
|
||||
_currentLayerIndex = actor.Info.OnLayer;
|
||||
_currentLayerIndex = actor.Info.LayerIndex;
|
||||
_getAllActiveActorBlockingTilePositions = getAllActiveActorBlockingTilePositions;
|
||||
|
||||
Vector3 initPosition = GameBoxInterpreter.ToUnityPosition(new Vector3(actor.Info.PositionX,
|
||||
actor.Info.PositionY, actor.Info.PositionZ));
|
||||
Vector3 initPosition = GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
actor.Info.GameBoxXPosition,
|
||||
actor.Info.GameBoxYPosition,
|
||||
actor.Info.GameBoxZPosition));
|
||||
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(initPosition, _currentLayerIndex);
|
||||
if (actor.Info.InitBehaviour != ScnActorBehaviour.Hold &&
|
||||
_tilemap.IsTilePositionInsideTileMap(tilePosition, _currentLayerIndex))
|
||||
_tilemap.TryGetTile(initPosition, _currentLayerIndex, out NavTile tile))
|
||||
{
|
||||
NavTile tile = _tilemap.GetTile(tilePosition, _currentLayerIndex);
|
||||
|
||||
if (tile.IsWalkable())
|
||||
{
|
||||
transform.position = new Vector3(initPosition.x,
|
||||
tile.Y / GameBoxInterpreter.GameBoxUnitToUnityUnit,
|
||||
GameBoxInterpreter.ToUnityYPosition(tile.GameBoxYPosition),
|
||||
initPosition.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(initPosition, _currentLayerIndex);
|
||||
// Snap to the nearest adjacent tile if exists
|
||||
var nextToWalkableTile =_tilemap.TryGetAdjacentWalkableTile(tilePosition,
|
||||
var hasAdjacentWalkableTile =_tilemap.TryGetAdjacentWalkableTile(tilePosition,
|
||||
_currentLayerIndex, out Vector2Int nearestTile);
|
||||
transform.position = nextToWalkableTile ?
|
||||
transform.position = hasAdjacentWalkableTile ?
|
||||
_tilemap.GetWorldPosition(nearestTile, _currentLayerIndex) :
|
||||
initPosition;
|
||||
}
|
||||
@@ -116,21 +136,95 @@ namespace Pal3.Actor
|
||||
_currentLayerIndex = layerIndex;
|
||||
}
|
||||
|
||||
public bool MovementInProgress()
|
||||
public bool IsDuringCollision()
|
||||
{
|
||||
return _activeColliders.Count > 0;
|
||||
}
|
||||
|
||||
private bool IsNearOrOnTopOfPlatform()
|
||||
{
|
||||
return _activeStandingPlatforms.Count > 0;
|
||||
}
|
||||
|
||||
private bool TryGetLastEnteredStandingPlatform(out ActiveStandingPlatformInfo platformInfo)
|
||||
{
|
||||
platformInfo = null;
|
||||
var latestTime = double.MinValue;
|
||||
|
||||
foreach (ActiveStandingPlatformInfo info in _activeStandingPlatforms)
|
||||
{
|
||||
if (info.Platform == null)
|
||||
{
|
||||
continue; // In case the platform is destroyed
|
||||
}
|
||||
|
||||
if (info.TimeWhenEntered > latestTime)
|
||||
{
|
||||
latestTime = info.TimeWhenEntered;
|
||||
platformInfo = info;
|
||||
}
|
||||
}
|
||||
|
||||
return platformInfo != null;
|
||||
}
|
||||
|
||||
private Vector3 GetNearestLastKnownPositionWhenCollisionEnter()
|
||||
{
|
||||
Vector3 nearestPosition = transform.position;
|
||||
float distance = float.MaxValue;
|
||||
|
||||
foreach (var colliderInfo in _activeColliders)
|
||||
{
|
||||
var distanceToLastKnownPosition = Vector3.Distance(
|
||||
colliderInfo.ActorPositionWhenCollisionEnter, transform.position);
|
||||
if (distanceToLastKnownPosition < distance)
|
||||
{
|
||||
distance = distanceToLastKnownPosition;
|
||||
nearestPosition = colliderInfo.ActorPositionWhenCollisionEnter;
|
||||
}
|
||||
}
|
||||
|
||||
return nearestPosition;
|
||||
}
|
||||
|
||||
public bool IsMovementInProgress()
|
||||
{
|
||||
return !_currentPath.IsEndOfPath();
|
||||
}
|
||||
|
||||
public void CancelCurrentMovement()
|
||||
public void CancelMovement()
|
||||
{
|
||||
_currentPath.Clear();
|
||||
}
|
||||
|
||||
public void PauseMovement()
|
||||
{
|
||||
_isMovementOnHold = true;
|
||||
|
||||
if (IsMovementInProgress())
|
||||
{
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
}
|
||||
|
||||
public void ResumeMovement()
|
||||
{
|
||||
if (_isMovementOnHold)
|
||||
{
|
||||
_isMovementOnHold = false;
|
||||
if (IsMovementInProgress())
|
||||
{
|
||||
_actionController.PerformAction(_actor.GetMovementAction(_currentPath.MovementMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_currentPath.IsEndOfPath()) return;
|
||||
if (_isMovementOnHold || _currentPath.IsEndOfPath()) return;
|
||||
|
||||
MovementResult result = MoveTowards(_currentPath.GetCurrentWayPoint(), _currentPath.MovementMode,
|
||||
MovementResult result = MoveTowards(_currentPath.GetCurrentWayPoint(),
|
||||
_currentPath.MovementMode,
|
||||
_currentPath.IgnoreObstacle);
|
||||
|
||||
switch (result)
|
||||
@@ -149,32 +243,63 @@ namespace Pal3.Actor
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
// To sync with the platform movement
|
||||
if (IsNearOrOnTopOfPlatform() && TryGetLastEnteredStandingPlatform(
|
||||
out ActiveStandingPlatformInfo platformInfo))
|
||||
{
|
||||
Vector3 currentPlatformPosition = platformInfo.Platform.gameObject.transform.position;
|
||||
|
||||
if (currentPlatformPosition != platformInfo.PlatformLastKnownPosition)
|
||||
{
|
||||
transform.position += currentPlatformPosition - platformInfo.PlatformLastKnownPosition;
|
||||
platformInfo.PlatformLastKnownPosition = currentPlatformPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// Sanity cleanup
|
||||
if (_activeColliders.Count > 0)
|
||||
{
|
||||
_activeColliders.RemoveWhere(_ => _.Collider == null);
|
||||
}
|
||||
|
||||
// Sanity cleanup
|
||||
if (_activeStandingPlatforms.Count > 0)
|
||||
{
|
||||
_activeStandingPlatforms.RemoveWhere(_ => _.Platform == null);
|
||||
}
|
||||
|
||||
// To prevent actor from bouncing into un-walkable tile position,
|
||||
// we need to reset its position during the collision.
|
||||
// Also we need to adjust Y position based on tile information
|
||||
// during the collision since we are locking Y movement for the
|
||||
// player actor's rigidbody.
|
||||
if (_isDuringCollision && _actionController.GetRigidBody() is {isKinematic: false})
|
||||
if (IsDuringCollision() && _actionController.GetRigidBody() is { isKinematic: false } _)
|
||||
{
|
||||
Vector3 currentPosition = transform.position;
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(currentPosition, _currentLayerIndex);
|
||||
if (!_tilemap.IsTilePositionInsideTileMap(tilePosition, _currentLayerIndex))
|
||||
|
||||
if (IsNearOrOnTopOfPlatform())
|
||||
{
|
||||
transform.position = _lastKnownValidPositionWhenCollisionEnter;
|
||||
// Do nothing.
|
||||
}
|
||||
else if (!_tilemap.TryGetTile(currentPosition, _currentLayerIndex, out NavTile tile))
|
||||
{
|
||||
transform.position = GetNearestLastKnownPositionWhenCollisionEnter();
|
||||
}
|
||||
else
|
||||
{
|
||||
NavTile currentTile = _tilemap.GetTile(tilePosition, _currentLayerIndex);
|
||||
if (!currentTile.IsWalkable())
|
||||
if (!tile.IsWalkable())
|
||||
{
|
||||
transform.position = _lastKnownValidPositionWhenCollisionEnter;
|
||||
transform.position = GetNearestLastKnownPositionWhenCollisionEnter();
|
||||
}
|
||||
else
|
||||
{
|
||||
var adjustedPosition = new Vector3(currentPosition.x,
|
||||
currentTile.Y / GameBoxInterpreter.GameBoxUnitToUnityUnit,
|
||||
GameBoxInterpreter.ToUnityYPosition(tile.GameBoxYPosition),
|
||||
currentPosition.z);
|
||||
transform.position = adjustedPosition;
|
||||
}
|
||||
@@ -182,39 +307,77 @@ namespace Pal3.Actor
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision _)
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
_isDuringCollision = true;
|
||||
|
||||
Vector3 currentActorPosition = transform.position;
|
||||
Vector2Int currentTilePosition = _tilemap.GetTilePosition(currentActorPosition, _currentLayerIndex);
|
||||
|
||||
if (_tilemap.IsTilePositionInsideTileMap(currentTilePosition, _currentLayerIndex) &&
|
||||
_tilemap.GetTile(currentActorPosition, _currentLayerIndex).IsWalkable())
|
||||
|
||||
Vector3 actorPosition;
|
||||
if (IsNearOrOnTopOfPlatform())
|
||||
{
|
||||
_lastKnownValidPositionWhenCollisionEnter = currentActorPosition;
|
||||
actorPosition = currentActorPosition;
|
||||
}
|
||||
else if (_tilemap.TryGetTile(currentActorPosition, _currentLayerIndex, out NavTile tile) && tile.IsWalkable())
|
||||
{
|
||||
actorPosition = currentActorPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastKnownValidPositionWhenCollisionEnter =
|
||||
actorPosition =
|
||||
_tilemap.TryGetAdjacentWalkableTile(currentTilePosition,
|
||||
_currentLayerIndex,
|
||||
out Vector2Int nearestWalkableTilePosition)
|
||||
out Vector2Int nearestWalkableTilePosition)
|
||||
? _tilemap.GetWorldPosition(nearestWalkableTilePosition, _currentLayerIndex)
|
||||
: currentActorPosition; // Highly unlikely to happen, but this is the best effort
|
||||
}
|
||||
|
||||
_activeColliders.Add(new ActiveColliderInfo()
|
||||
{
|
||||
Collider = collision.collider,
|
||||
ActorPositionWhenCollisionEnter = actorPosition
|
||||
});
|
||||
}
|
||||
|
||||
private void OnCollisionExit(Collision _)
|
||||
private void OnCollisionExit(Collision collision)
|
||||
{
|
||||
_isDuringCollision = false;
|
||||
_activeColliders.RemoveWhere(_ => _.Collider == collision.collider);
|
||||
|
||||
if (_actionController.GetRigidBody() is { } actorRigidbody)
|
||||
if (_actionController.GetRigidBody() is { isKinematic: false } actorRigidbody)
|
||||
{
|
||||
actorRigidbody.velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider triggerCollider)
|
||||
{
|
||||
if (triggerCollider.gameObject.GetComponent<StandingPlatformController>() is { } standingPlatformController)
|
||||
{
|
||||
_activeStandingPlatforms.Add(new ActiveStandingPlatformInfo()
|
||||
{
|
||||
Platform = standingPlatformController,
|
||||
PlatformLastKnownPosition = triggerCollider.gameObject.transform.position,
|
||||
TimeWhenEntered = Time.realtimeSinceStartupAsDouble,
|
||||
});
|
||||
|
||||
// Move actor on to the platform if platform is higher than current position
|
||||
Vector3 currentPosition = transform.position;
|
||||
var targetYPosition = standingPlatformController.GetPlatformHeight();
|
||||
if (Mathf.Abs(currentPosition.y - targetYPosition) <= MAX_Y_DIFFERENTIAL_CROSS_PLATFORM &&
|
||||
currentPosition.y < targetYPosition) // Don't move the actor if platform is lower
|
||||
{
|
||||
transform.position = new Vector3(currentPosition.x, targetYPosition, currentPosition.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider triggerCollider)
|
||||
{
|
||||
if (triggerCollider.gameObject.GetComponent<StandingPlatformController>() is { } standingPlatformController)
|
||||
{
|
||||
_activeStandingPlatforms.RemoveWhere(_ => _.Platform == standingPlatformController);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCurrentLayerIndex()
|
||||
{
|
||||
return _currentLayerIndex;
|
||||
@@ -230,30 +393,46 @@ namespace Pal3.Actor
|
||||
return _tilemap.GetTilePosition(transform.position, _currentLayerIndex);
|
||||
}
|
||||
|
||||
public void PortalToPosition(Vector3 position, int layerIndex)
|
||||
public void PortalToPosition(Vector3 position, int layerIndex, bool isPositionOnStandingPlatform)
|
||||
{
|
||||
if (IsNotObstacleAtLayer(position, layerIndex, out var yPosition))
|
||||
if (isPositionOnStandingPlatform)
|
||||
{
|
||||
_currentPath?.Clear();
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
SetNavLayer(layerIndex);
|
||||
transform.position = new Vector3(position.x, yPosition, position.z);
|
||||
transform.position = position;
|
||||
|
||||
Debug.Log($"Portal to: " +
|
||||
$"Layer: {GetCurrentLayerIndex()} " +
|
||||
$"Tile position: {_tilemap.GetTilePosition(position, layerIndex)}");
|
||||
Debug.LogWarning($"Portal to standing platform: {position}, " +
|
||||
$"layer: {layerIndex}");
|
||||
}
|
||||
else if (_tilemap.TryGetTile(position, layerIndex, out NavTile tile) && tile.IsWalkable())
|
||||
{
|
||||
_currentPath?.Clear();
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
SetNavLayer(layerIndex);
|
||||
transform.position = new Vector3(
|
||||
position.x,
|
||||
GameBoxInterpreter.ToUnityYPosition(tile.GameBoxYPosition),
|
||||
position.z);
|
||||
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(position, layerIndex);
|
||||
Debug.LogWarning($"Portal to: {position}, " +
|
||||
$"layer: {layerIndex}, " +
|
||||
$"tile: {tilePosition} DistanceToNearestObstacle: {tile.DistanceToNearestObstacle}, FloorKind: {tile.FloorKind}");
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveToTapPoint(Dictionary<int, Vector3> tapPoints, bool isDoubleTap)
|
||||
public void MoveToTapPoint(Dictionary<int, (Vector3 point, bool isPlatform)> tapPoints, bool isDoubleTap)
|
||||
{
|
||||
Vector3 targetPosition = Vector3.zero;
|
||||
var targetPositionFound = false;
|
||||
if (tapPoints.ContainsKey(_currentLayerIndex))
|
||||
{
|
||||
if (IsNotObstacleAtLayer(tapPoints[_currentLayerIndex], _currentLayerIndex, out _))
|
||||
if (tapPoints[_currentLayerIndex].isPlatform ||
|
||||
(_tilemap.TryGetTile(tapPoints[_currentLayerIndex].point, _currentLayerIndex, out NavTile tile) &&
|
||||
tile.IsWalkable()))
|
||||
{
|
||||
targetPosition = tapPoints[_currentLayerIndex];
|
||||
targetPosition = tapPoints[_currentLayerIndex].point;
|
||||
targetPositionFound = true;
|
||||
}
|
||||
}
|
||||
@@ -263,19 +442,21 @@ namespace Pal3.Actor
|
||||
nextLayer < _tilemap.GetLayerCount() &&
|
||||
tapPoints.ContainsKey(nextLayer))
|
||||
{
|
||||
targetPosition = tapPoints[nextLayer];
|
||||
targetPosition = tapPoints[nextLayer].point;
|
||||
targetPositionFound = true;
|
||||
}
|
||||
|
||||
if (!targetPositionFound)
|
||||
{
|
||||
targetPosition = tapPoints.First().Value;
|
||||
targetPosition = tapPoints.First().Value.point;
|
||||
}
|
||||
|
||||
var moveMode = isDoubleTap ? 1 : 0;
|
||||
// Keep running when actor is already in running mode
|
||||
if (_currentPath?.MovementMode == 1) moveMode = 1;
|
||||
SetupPath(new[] { targetPosition }, moveMode, EndOfPathActionType.Idle, ignoreObstacle: false);
|
||||
MovementMode mode = isDoubleTap ? MovementMode.Run : MovementMode.Walk;
|
||||
|
||||
// Keep running when actor is already in running mode regardless of the tap behavior
|
||||
if (_currentPath?.MovementMode == MovementMode.Run) mode = MovementMode.Run;
|
||||
|
||||
SetupPath(new[] { targetPosition }, mode, EndOfPathActionType.Idle, ignoreObstacle: false);
|
||||
}
|
||||
|
||||
private bool IsNearPortalAreaOfLayer(Vector3 position, int layerIndex)
|
||||
@@ -289,30 +470,37 @@ namespace Pal3.Actor
|
||||
_tilemap.IsInsidePortalArea(tilePosition + DirectionUtils.ToVector2Int(direction), layerIndex));
|
||||
}
|
||||
|
||||
private bool IsNotObstacleAtLayer(Vector3 position, int layerIndex, out float y)
|
||||
{
|
||||
y = 0;
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(position, layerIndex);
|
||||
if (!_tilemap.IsTilePositionInsideTileMap(tilePosition, layerIndex)) return false;
|
||||
NavTile tile = _tilemap.GetTile(tilePosition, layerIndex);
|
||||
if (!tile.IsWalkable()) return false;
|
||||
y = tile.Y / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
return true;
|
||||
}
|
||||
|
||||
public MovementResult MoveTowards(Vector3 targetPosition, int movementMode, bool ignoreObstacle = false)
|
||||
public MovementResult MoveTowards(Vector3 targetPosition, MovementMode movementMode, bool ignoreObstacle = false)
|
||||
{
|
||||
Transform currentTransform = transform;
|
||||
Vector3 currentPosition = currentTransform.position;
|
||||
|
||||
// TODO: Use speed info from datascript\scene.txt file
|
||||
//var speed = _actor.Info.Speed == 0 ? 2f : _actor.Info.Speed;
|
||||
var moveSpeed = movementMode == 1 ? 11f : 5f;
|
||||
var rotationSpeed = 20f;
|
||||
// TODO: Use speed info from datascript\scene.txt file when _actor.Info.Speed == 0
|
||||
var moveSpeed = _actor.Info.Speed <= 0 ? (movementMode == MovementMode.Run ? 11f : 5f) : _actor.Info.Speed / 11f;
|
||||
|
||||
if (!_actor.IsMainActor()) moveSpeed /= 2f;
|
||||
|
||||
Vector3 newPosition = Vector3.MoveTowards(currentPosition, targetPosition, moveSpeed * Time.deltaTime);
|
||||
var currentXZPosition = new Vector2(currentPosition.x, currentPosition.z);
|
||||
var targetXZPosition = new Vector2(targetPosition.x, targetPosition.z);
|
||||
|
||||
Vector2 goalXZPosition = Vector2.MoveTowards(currentXZPosition, targetXZPosition,moveSpeed * Time.deltaTime);
|
||||
|
||||
float goalYPosition = Mathf.Abs(targetPosition.y - currentPosition.y) < 0.01f ? targetPosition.y :
|
||||
(Vector2.Distance(goalXZPosition, currentXZPosition) /
|
||||
Vector2.Distance(targetXZPosition, currentXZPosition)) *
|
||||
(targetPosition.y - currentPosition.y) + currentPosition.y;
|
||||
|
||||
var newPosition = new Vector3(goalXZPosition.x, goalYPosition, goalXZPosition.y);
|
||||
|
||||
// If actor is moving towards a collider, check if the new position is still inside the collider.
|
||||
// If yes, don't move the actor. This is to prevent the actor from moving through the collider
|
||||
// since we are not moving the rigidbody directly but instead moving the transform.
|
||||
if (IsDuringCollision() && _actionController.GetRigidBody() is { isKinematic: false } &&
|
||||
IsNewPositionInsideCollisionCollider(currentPosition, newPosition))
|
||||
{
|
||||
RotateTowards(currentPosition, newPosition, movementMode);
|
||||
return MovementResult.InProgress;
|
||||
}
|
||||
|
||||
var canGotoPosition = CanGotoPosition(currentPosition, newPosition, out var newYPosition);
|
||||
|
||||
@@ -321,31 +509,24 @@ namespace Pal3.Actor
|
||||
return MovementResult.Blocked;
|
||||
}
|
||||
|
||||
if (!canGotoPosition || Mathf.Abs(newYPosition - newPosition.y) > 3f) newYPosition = currentPosition.y;
|
||||
|
||||
var moveDirection = new Vector3(
|
||||
targetPosition.x - currentPosition.x,
|
||||
0f,
|
||||
targetPosition.z - currentPosition.z);
|
||||
|
||||
// Special handling for moving backwards
|
||||
if (movementMode == 2)
|
||||
switch (ignoreObstacle)
|
||||
{
|
||||
currentTransform.forward = moveDirection;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTransform.forward = Vector3.RotateTowards(currentTransform.forward,
|
||||
moveDirection, rotationSpeed * Time.deltaTime, 0.0f);
|
||||
case false when Mathf.Abs(newYPosition - newPosition.y) > MAX_Y_DIFFERENTIAL:
|
||||
return MovementResult.Blocked;
|
||||
case true when Mathf.Abs(newYPosition - newPosition.y) > MAX_Y_DIFFERENTIAL:
|
||||
newYPosition = currentPosition.y;
|
||||
break;
|
||||
}
|
||||
|
||||
RotateTowards(currentPosition, newPosition, movementMode);
|
||||
|
||||
currentTransform.position = new Vector3(
|
||||
newPosition.x,
|
||||
newYPosition,
|
||||
newPosition.z);
|
||||
|
||||
if (Math.Abs(currentTransform.position.x - targetPosition.x) < 0.05f &&
|
||||
Math.Abs(currentTransform.position.z - targetPosition.z) < 0.05f)
|
||||
if (Mathf.Abs(currentTransform.position.x - targetPosition.x) < 0.05f &&
|
||||
Mathf.Abs(currentTransform.position.z - targetPosition.z) < 0.05f)
|
||||
{
|
||||
return MovementResult.Completed;
|
||||
}
|
||||
@@ -353,32 +534,120 @@ namespace Pal3.Actor
|
||||
return MovementResult.InProgress;
|
||||
}
|
||||
|
||||
private void RotateTowards(Vector3 currentPosition, Vector3 targetPosition, MovementMode movementMode)
|
||||
{
|
||||
Transform currentTransform = transform;
|
||||
|
||||
Vector3 moveDirection = new Vector3(
|
||||
targetPosition.x - currentPosition.x,
|
||||
0f,
|
||||
targetPosition.z - currentPosition.z).normalized;
|
||||
|
||||
// Special handling for stepping backwards
|
||||
if (movementMode == MovementMode.StepBack)
|
||||
{
|
||||
currentTransform.forward = moveDirection;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTransform.forward = Vector3.RotateTowards(currentTransform.forward,
|
||||
moveDirection, DEFAULT_ROTATION_SPEED * Time.deltaTime, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsNewPositionInsideCollisionCollider(Vector3 currentPosition, Vector3 newPosition)
|
||||
{
|
||||
// Check if actor is running into any of the active collision colliders
|
||||
foreach (ActiveColliderInfo colliderInfo in _activeColliders)
|
||||
{
|
||||
if (colliderInfo.Collider == null)
|
||||
{
|
||||
continue; // In case the collider is destroyed
|
||||
}
|
||||
|
||||
var centerYPosition = _actionController.GetRendererBounds().center.y;
|
||||
|
||||
var fromCenterPosition = new Vector3(currentPosition.x, centerYPosition, currentPosition.z);
|
||||
var toCenterPosition = new Vector3(newPosition.x, centerYPosition, newPosition.z);
|
||||
Vector3 movingDirection = (toCenterPosition - fromCenterPosition).normalized;
|
||||
|
||||
if (_actionController.GetCollider() is { } capsuleCollider)
|
||||
{
|
||||
if (Utility.IsPointWithinCollider(colliderInfo.Collider,
|
||||
toCenterPosition + movingDirection * capsuleCollider.radius))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool CanGotoPosition(Vector3 currentPosition, Vector3 newPosition, out float newYPosition)
|
||||
{
|
||||
newYPosition = 0f;
|
||||
newYPosition = float.MinValue;
|
||||
var isNewPositionValid = false;
|
||||
|
||||
// Check if actor is on top of a platform
|
||||
if (IsNearOrOnTopOfPlatform())
|
||||
{
|
||||
// Check if the new position is still on top of the nearest platform(s)
|
||||
foreach (ActiveStandingPlatformInfo platformInfo in _activeStandingPlatforms)
|
||||
{
|
||||
var targetYPosition = platformInfo.Platform.GetPlatformHeight();
|
||||
|
||||
// Tolerance is used to allow the actor to be able to walk
|
||||
// on a standing platform that has a slight slope
|
||||
const float tolerance = 0.3f;
|
||||
|
||||
// Make sure actor is on top of the platform
|
||||
if (Utility.IsPointWithinCollider(platformInfo.Platform.GetCollider(),
|
||||
new Vector3(newPosition.x, targetYPosition, newPosition.z), tolerance) &&
|
||||
Mathf.Abs(currentPosition.y - targetYPosition) <= MAX_Y_DIFFERENTIAL_CROSS_PLATFORM)
|
||||
{
|
||||
newYPosition = targetYPosition;
|
||||
isNewPositionValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// New position is not blocked at current layer
|
||||
if (IsNotObstacleAtLayer(newPosition, _currentLayerIndex, out var currentLayerY))
|
||||
if (_tilemap.TryGetTile(newPosition, _currentLayerIndex, out NavTile tileAtCurrentLayer) &&
|
||||
tileAtCurrentLayer.IsWalkable())
|
||||
{
|
||||
newYPosition = currentLayerY;
|
||||
return true;
|
||||
var tileYPosition = GameBoxInterpreter.ToUnityYPosition(tileAtCurrentLayer.GameBoxYPosition);
|
||||
|
||||
// Choose a higher position if possible
|
||||
if (tileYPosition > newYPosition)
|
||||
{
|
||||
newYPosition = tileYPosition;
|
||||
}
|
||||
|
||||
isNewPositionValid = true;
|
||||
}
|
||||
|
||||
if (isNewPositionValid) return true;
|
||||
|
||||
if (_tilemap.GetLayerCount() <= 1) return false;
|
||||
|
||||
var nextLayer = (_currentLayerIndex + 1) % 2;
|
||||
|
||||
// New position is not blocked at next layer and y offset is within range
|
||||
if (IsNotObstacleAtLayer(newPosition, nextLayer, out var nextLayerY))
|
||||
if (_tilemap.TryGetTile(newPosition, nextLayer, out NavTile tileAtNextLayer) &&
|
||||
tileAtNextLayer.IsWalkable())
|
||||
{
|
||||
if (Mathf.Abs(currentPosition.y - nextLayerY) > MAX_CROSS_LAYER_Y_DIFFERENTIAL)
|
||||
var yPositionAtNextLayer = GameBoxInterpreter.ToUnityYPosition(tileAtNextLayer.GameBoxYPosition);
|
||||
|
||||
if (Mathf.Abs(currentPosition.y - yPositionAtNextLayer) > MAX_Y_DIFFERENTIAL_CROSS_LAYER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Switching layer
|
||||
SetNavLayer(nextLayer);
|
||||
newYPosition = nextLayerY;
|
||||
newYPosition = yPositionAtNextLayer;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -394,7 +663,7 @@ namespace Pal3.Actor
|
||||
}
|
||||
|
||||
public void SetupPath(Vector3[] wayPoints,
|
||||
int mode,
|
||||
MovementMode mode,
|
||||
EndOfPathActionType endOfPathAction,
|
||||
bool ignoreObstacle,
|
||||
string specialAction = null)
|
||||
@@ -406,7 +675,7 @@ namespace Pal3.Actor
|
||||
private void ReachingToEndOfPath()
|
||||
{
|
||||
_movementWaiter?.CancelWait();
|
||||
|
||||
|
||||
switch (_currentPath.EndOfPathAction)
|
||||
{
|
||||
case EndOfPathActionType.DisposeSelf:
|
||||
@@ -415,20 +684,20 @@ namespace Pal3.Actor
|
||||
case EndOfPathActionType.Idle:
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
break;
|
||||
case EndOfPathActionType.Reverse:
|
||||
case EndOfPathActionType.WaitAndReverse:
|
||||
{
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
var waypoints = _currentPath.GetAllWayPoints();
|
||||
waypoints.Reverse();
|
||||
StartCoroutine(WaitForSomeTimeAndFollowPath(waypoints.ToArray(),
|
||||
StartCoroutine(WaitForSomeTimeAndFollowPathAsync(waypoints.ToArray(),
|
||||
_currentPath.MovementMode,
|
||||
_movementCts.Token));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Special handling for final rotation after moving backwards
|
||||
if (_currentPath.MovementMode == 2)
|
||||
// Special handling for final rotation after stepping backwards
|
||||
if (_currentPath.MovementMode == MovementMode.StepBack)
|
||||
{
|
||||
Transform actorTransform = transform;
|
||||
actorTransform.forward = -actorTransform.forward;
|
||||
@@ -437,43 +706,54 @@ namespace Pal3.Actor
|
||||
_currentPath.Clear();
|
||||
}
|
||||
|
||||
private IEnumerator WaitForSomeTimeAndFollowPath(Vector3[] waypoints, int mode, CancellationToken cancellationToken)
|
||||
private IEnumerator WaitForSomeTimeAndFollowPathAsync(Vector3[] waypoints, MovementMode mode, CancellationToken cancellationToken)
|
||||
{
|
||||
yield return new WaitForSeconds(Random.Range(3, 8));
|
||||
yield return new WaitUntil(() => !_isMovementOnHold);
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
SetupPath(waypoints, mode, EndOfPathActionType.Reverse, ignoreObstacle: true);
|
||||
SetupPath(waypoints, mode, EndOfPathActionType.WaitAndReverse, ignoreObstacle: true);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator MoveDirectlyTo(Vector3 position, int mode)
|
||||
public IEnumerator MoveDirectlyToAsync(Vector3 position, MovementMode mode, bool ignoreObstacle)
|
||||
{
|
||||
_currentPath.Clear();
|
||||
MovementResult result;
|
||||
_actionController.PerformAction(_actor.GetMovementAction(mode));
|
||||
do
|
||||
{
|
||||
result = MoveTowards(position, mode, ignoreObstacle: true);
|
||||
result = MoveTowards(position, mode, ignoreObstacle);
|
||||
yield return null;
|
||||
} while (result == MovementResult.InProgress);
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
|
||||
private IEnumerator FindPathAndMoveToTilePosition(Vector2Int position,
|
||||
int mode,
|
||||
private IEnumerator FindPathAndMoveToTilePositionAsync(Vector2Int toTilePosition,
|
||||
MovementMode mode,
|
||||
EndOfPathActionType endOfPathAction,
|
||||
CancellationToken cancellationToken,
|
||||
bool moveTowardsPositionIfNoPathFound = false,
|
||||
string specialAction = default)
|
||||
{
|
||||
Vector2Int fromTilePosition = _tilemap.GetTilePosition(transform.position, _currentLayerIndex);
|
||||
|
||||
if (fromTilePosition == toTilePosition)
|
||||
{
|
||||
_movementWaiter?.CancelWait();
|
||||
yield break;
|
||||
}
|
||||
|
||||
Vector2Int[] path = Array.Empty<Vector2Int>();
|
||||
Vector2Int fromTile = _tilemap.GetTilePosition(transform.position, _currentLayerIndex);
|
||||
var obstacles = _getAllActiveActorBlockingTilePositions(_currentLayerIndex, new [] {_actor.Info.Id});
|
||||
var obstacles = _getAllActiveActorBlockingTilePositions(_currentLayerIndex, new [] {(int)_actor.Info.Id});
|
||||
|
||||
var pathFindingThread = new Thread(() =>
|
||||
{
|
||||
path = _tilemap.FindPathToTilePositionThreadSafe(fromTile,
|
||||
new Vector2Int(position.x, position.y), _currentLayerIndex, obstacles);
|
||||
path = _tilemap.FindPathToTilePositionThreadSafe(
|
||||
fromTilePosition,
|
||||
toTilePosition,
|
||||
_currentLayerIndex,
|
||||
obstacles);
|
||||
})
|
||||
{
|
||||
IsBackground = true,
|
||||
@@ -487,14 +767,14 @@ namespace Pal3.Actor
|
||||
}
|
||||
|
||||
if (cancellationToken.IsCancellationRequested) yield break;
|
||||
|
||||
|
||||
if (path.Length <= 0)
|
||||
{
|
||||
if (moveTowardsPositionIfNoPathFound)
|
||||
{
|
||||
var directWayPoints = new[]
|
||||
{
|
||||
_tilemap.GetWorldPosition(position, _currentLayerIndex),
|
||||
_tilemap.GetWorldPosition(toTilePosition, _currentLayerIndex),
|
||||
};
|
||||
|
||||
SetupPath(directWayPoints, mode, endOfPathAction, ignoreObstacle: true, specialAction);
|
||||
@@ -502,7 +782,8 @@ namespace Pal3.Actor
|
||||
else
|
||||
{
|
||||
_movementWaiter?.CancelWait();
|
||||
Debug.LogError($"Failed to find path to tile position: {position}");
|
||||
Debug.LogError($"Failed to find path from tile position {fromTilePosition} " +
|
||||
$"to tile position: {toTilePosition}");
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
@@ -516,61 +797,101 @@ namespace Pal3.Actor
|
||||
SetupPath(wayPoints, mode, endOfPathAction, ignoreObstacle: true, specialAction);
|
||||
}
|
||||
|
||||
private void MoveToTilePosition(Vector2Int position, int mode)
|
||||
private void MoveToTilePosition(Vector2Int position, MovementMode mode)
|
||||
{
|
||||
MoveTo(_tilemap.GetWorldPosition(position, _currentLayerIndex), mode);
|
||||
}
|
||||
|
||||
private void MoveTo(Vector3 position, int mode)
|
||||
private void MoveTo(Vector3 position, MovementMode mode)
|
||||
{
|
||||
_movementWaiter?.CancelWait();
|
||||
_movementWaiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(_movementWaiter));
|
||||
_movementWaiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(_movementWaiter));
|
||||
|
||||
var wayPoints = new [] { position };
|
||||
SetupPath(wayPoints, mode, EndOfPathActionType.Idle, ignoreObstacle: false);
|
||||
}
|
||||
|
||||
public void Execute(ActorSetWorldPositionCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(
|
||||
new Vector3(command.XPosition, 0f, command.ZPosition), _currentLayerIndex);
|
||||
|
||||
if (_tilemap.IsTilePositionInsideTileMap(tilePosition, _currentLayerIndex))
|
||||
{
|
||||
Execute(new ActorSetTilePositionCommand(command.ActorId, tilePosition.x, tilePosition.y));
|
||||
}
|
||||
else // Try next layer
|
||||
{
|
||||
tilePosition = _tilemap.GetTilePosition(
|
||||
new Vector3(command.XPosition, 0f, command.ZPosition), (_currentLayerIndex + 1) % 2);
|
||||
|
||||
if (_tilemap.IsTilePositionInsideTileMap(tilePosition, (_currentLayerIndex + 1) % 2))
|
||||
{
|
||||
Execute(new ActorSetTilePositionCommand(command.ActorId, tilePosition.x, tilePosition.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorSetTilePositionCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
CancelCurrentMovement();
|
||||
|
||||
var tilePosition = new Vector2Int(command.TileXPosition, command.TileZPosition);
|
||||
CancelMovement();
|
||||
|
||||
// Check if position at current layer exists,
|
||||
// if not, auto switch to next layer (if tile at next layer is walkable)
|
||||
var tilePosition = new Vector2Int(command.TileXPosition, command.TileYPosition);
|
||||
|
||||
// Check if position at current layer exists, if not, auto switch
|
||||
// to next layer (if tile at next layer is valid).
|
||||
// If position at both layers are valid, switch to next layer.
|
||||
// If current layer is not walkable but next layer is walkable.
|
||||
if (_tilemap.GetLayerCount() > 1)
|
||||
{
|
||||
var isTileInsideCurrentLayer = _tilemap.IsTilePositionInsideTileMap(tilePosition, _currentLayerIndex);
|
||||
var isTileInsideAtNextLayer = _tilemap.IsTilePositionInsideTileMap(tilePosition, (_currentLayerIndex + 1) % 2);
|
||||
if (!isTileInsideCurrentLayer && isTileInsideAtNextLayer)
|
||||
bool isTileExistsInCurrentLayer = _tilemap.TryGetTile(tilePosition,
|
||||
_currentLayerIndex, out NavTile tileAtCurrentLayer);
|
||||
bool isTileExistsInNextLayer = _tilemap.TryGetTile(tilePosition,
|
||||
(_currentLayerIndex + 1) % 2, out NavTile tileAtNextLayer);
|
||||
|
||||
if (!isTileExistsInCurrentLayer && isTileExistsInNextLayer)
|
||||
{
|
||||
SetNavLayer((_currentLayerIndex + 1) % 2);
|
||||
}
|
||||
}
|
||||
else if (isTileExistsInCurrentLayer && isTileExistsInNextLayer &&
|
||||
!tileAtCurrentLayer.IsWalkable() && tileAtNextLayer.IsWalkable())
|
||||
{
|
||||
SetNavLayer((_currentLayerIndex + 1) % 2);
|
||||
}
|
||||
}
|
||||
|
||||
transform.position = _tilemap.GetWorldPosition(tilePosition, _currentLayerIndex);
|
||||
|
||||
// Cancel current action if any
|
||||
if (_actionController.GetCurrentAction() != string.Empty)
|
||||
{
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorPathToCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
_movementWaiter?.CancelWait();
|
||||
_movementWaiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(_movementWaiter));
|
||||
StartCoroutine(FindPathAndMoveToTilePosition(new Vector2Int(command.TileX, command.TileZ),
|
||||
command.Mode, EndOfPathActionType.Idle, _movementCts.Token));
|
||||
_movementWaiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(_movementWaiter));
|
||||
StartCoroutine(FindPathAndMoveToTilePositionAsync(new Vector2Int(command.TileXPosition, command.TileYPosition),
|
||||
(MovementMode)command.Mode, EndOfPathActionType.Idle, _movementCts.Token));
|
||||
}
|
||||
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(ActorWalkToUsingActionCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
_movementWaiter?.CancelWait();
|
||||
_movementWaiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(_movementWaiter));
|
||||
StartCoroutine(FindPathAndMoveToTilePosition(new Vector2Int(command.TileX, command.TileZ),
|
||||
_movementWaiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(_movementWaiter));
|
||||
StartCoroutine(FindPathAndMoveToTilePositionAsync(new Vector2Int(command.TileXPosition, command.TileYPosition),
|
||||
mode: 0, EndOfPathActionType.Idle, _movementCts.Token, specialAction: command.Action));
|
||||
}
|
||||
#endif
|
||||
@@ -578,15 +899,15 @@ namespace Pal3.Actor
|
||||
public void Execute(ActorMoveToCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
MoveToTilePosition(new Vector2Int(command.TileX, command.TileZ), command.Mode);
|
||||
MoveToTilePosition(new Vector2Int(command.TileXPosition, command.TileYPosition), (MovementMode)command.Mode);
|
||||
}
|
||||
|
||||
public void Execute(ActorMoveBackwardsCommand command)
|
||||
{
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
var moveDistance = command.Distance / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
var moveDistance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
Vector3 newPosition = transform.position + (-transform.forward * moveDistance);
|
||||
MoveTo(newPosition, 2);
|
||||
MoveTo(newPosition, MovementMode.StepBack);
|
||||
}
|
||||
|
||||
public void Execute(ActorMoveOutOfScreenCommand command)
|
||||
@@ -594,12 +915,12 @@ namespace Pal3.Actor
|
||||
if (_actor.Info.Id != command.ActorId) return;
|
||||
|
||||
_movementWaiter?.CancelWait();
|
||||
_movementWaiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(_movementWaiter));
|
||||
_movementWaiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(_movementWaiter));
|
||||
|
||||
StartCoroutine(FindPathAndMoveToTilePosition(
|
||||
new Vector2Int(command.TileX, command.TileZ),
|
||||
command.Mode,
|
||||
StartCoroutine(FindPathAndMoveToTilePositionAsync(
|
||||
new Vector2Int(command.TileXPosition, command.TileYPosition),
|
||||
(MovementMode)command.Mode,
|
||||
EndOfPathActionType.DisposeSelf,
|
||||
_movementCts.Token,
|
||||
true));
|
||||
@@ -629,6 +950,9 @@ namespace Pal3.Actor
|
||||
_movementCts?.Cancel();
|
||||
_movementCts = new CancellationTokenSource();
|
||||
_currentPath.Clear();
|
||||
|
||||
_activeColliders.Clear();
|
||||
_activeStandingPlatforms.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -17,15 +17,20 @@ namespace Pal3.Actor
|
||||
public class FlyingActorController : MonoBehaviour,
|
||||
ICommandExecutor<FlyingActorFlyToCommand>
|
||||
{
|
||||
private const float FLY_SPEED = 144f / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
public const float DefaultFlySpeed = 7.5f;
|
||||
public const float MaxFlySpeed = 11f;
|
||||
|
||||
private const float FLYING_MOVEMENT_MODE_SWITCH_DISTANCE = 5f;
|
||||
|
||||
private const float MAX_TARGET_DISTANCE = 20f;
|
||||
|
||||
private Actor _actor;
|
||||
private ActorController _actorController;
|
||||
private ActorActionController _actionController;
|
||||
|
||||
public void Init(Actor actor, ActorActionController actionController)
|
||||
public void Init(Actor actor, ActorController actorController, ActorActionController actionController)
|
||||
{
|
||||
_actor = actor;
|
||||
_actorController = actorController;
|
||||
_actionController = actionController;
|
||||
}
|
||||
|
||||
@@ -41,32 +46,42 @@ namespace Pal3.Actor
|
||||
|
||||
public void Execute(FlyingActorFlyToCommand command)
|
||||
{
|
||||
Vector3 targetPosition = GameBoxInterpreter.ToUnityPosition(new Vector3(command.X, command.Y, command.Z));
|
||||
|
||||
if (Vector3.Distance(transform.position, PlayerActorNpcInfo.InitPosition) < float.Epsilon)
|
||||
Vector3 targetPosition = GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
|
||||
// If actor is inactive or at it's init position, just teleport to target position
|
||||
if (!_actorController.IsActive ||
|
||||
Vector3.Distance(transform.position, PlayerActorNpcInfoFactory.ActorInitPosition) < float.Epsilon)
|
||||
{
|
||||
transform.position = targetPosition;
|
||||
_actionController.PerformAction(_actor.GetIdleAction());
|
||||
return;
|
||||
}
|
||||
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
|
||||
// In case the target position is too far away
|
||||
if (Vector3.Distance(transform.position, targetPosition) > MAX_TARGET_DISTANCE)
|
||||
{
|
||||
transform.position = (transform.position - targetPosition).normalized * MAX_TARGET_DISTANCE + targetPosition;
|
||||
}
|
||||
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
|
||||
var distance = (targetPosition - transform.position).magnitude;
|
||||
var duration = distance / FLY_SPEED;
|
||||
var duration = distance / DefaultFlySpeed;
|
||||
|
||||
_actionController.PerformAction(distance < FLYING_MOVEMENT_MODE_SWITCH_DISTANCE
|
||||
? _actor.GetMovementAction(0)
|
||||
: _actor.GetMovementAction(1));
|
||||
? _actor.GetMovementAction(MovementMode.Walk)
|
||||
: _actor.GetMovementAction(MovementMode.Run));
|
||||
|
||||
StartCoroutine(Fly(targetPosition, duration, waiter));
|
||||
StartCoroutine(FlyAsync(targetPosition, duration, waiter));
|
||||
}
|
||||
|
||||
private IEnumerator Fly(Vector3 targetPosition, float duration, WaitUntilCanceled waiter = null)
|
||||
|
||||
private IEnumerator FlyAsync(Vector3 targetPosition, float duration, WaitUntilCanceled waiter = null)
|
||||
{
|
||||
Vector3 oldPosition = transform.position;
|
||||
|
||||
|
||||
// Facing towards target position, ignoring y
|
||||
transform.LookAt(new Vector3(targetPosition.x, oldPosition.y, targetPosition.z));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -18,12 +18,13 @@ namespace Pal3.Actor
|
||||
public sealed class HuaYingController : FlyingActorController,
|
||||
ICommandExecutor<HuaYingSwitchBehaviourModeCommand>
|
||||
{
|
||||
private const float FLY_SPEED = 144f / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
private const float MAX_FLY_SPEED = 11f;
|
||||
private const float ROTATION_SPEED = 10f;
|
||||
private const float ROTATION_SYNCING_DISTANCE = 2f;
|
||||
private const float FOLLOW_TARGET_MIN_DISTANCE = 1f;
|
||||
private const float FOLLOW_TARGET_MAX_DISTANCE = 6f;
|
||||
private const float FOLLOW_TARGET_X_OFFSET = -0.8f;
|
||||
private const float FOLLOW_TARGET_FLY_SPEED_CHANEG_DISTANCE = 8f;
|
||||
private const float FOLLOW_TARGET_MAX_DISTANCE = 15f;
|
||||
private const float FOLLOW_TARGET_X_OFFSET = 0.8f;
|
||||
private const float FOLLOW_TARGET_Y_OFFSET = -0.8f;
|
||||
|
||||
private const PlayerActorId FOLLOW_ACTOR_ID = PlayerActorId.XueJian;
|
||||
@@ -41,11 +42,11 @@ namespace Pal3.Actor
|
||||
private bool _followTarget = true;
|
||||
private int _currentMode = 1; // defaults to follow target actor
|
||||
|
||||
public void Init(Actor actor,
|
||||
public new void Init(Actor actor,
|
||||
ActorController actorController,
|
||||
ActorActionController actionController)
|
||||
{
|
||||
base.Init(actor, actionController);
|
||||
base.Init(actor, actorController, actionController);
|
||||
_actor = actor;
|
||||
_actorController = actorController;
|
||||
_actorActionController = actionController;
|
||||
@@ -56,7 +57,7 @@ namespace Pal3.Actor
|
||||
{
|
||||
return _currentMode;
|
||||
}
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
@@ -104,7 +105,7 @@ namespace Pal3.Actor
|
||||
|
||||
if (_targetHeight == 0f)
|
||||
{
|
||||
_targetHeight = _targetActorActionController.GetLocalBounds().size.y;
|
||||
_targetHeight = _targetActorActionController.GetMeshBounds().size.y;
|
||||
transform.position = GetTargetStayPosition();
|
||||
}
|
||||
|
||||
@@ -117,21 +118,25 @@ namespace Pal3.Actor
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector3.Distance(myNewPosition, transform.position) < FOLLOW_TARGET_MAX_DISTANCE)
|
||||
{
|
||||
_actorActionController.PerformAction(_actor.GetMovementAction(0));
|
||||
}
|
||||
else
|
||||
// Set max distance to follow target if it's too far away
|
||||
var distanceToTarget = Vector3.Distance(myNewPosition, transform.position);
|
||||
if (distanceToTarget > FOLLOW_TARGET_MAX_DISTANCE)
|
||||
{
|
||||
transform.position = (transform.position - myNewPosition).normalized * FOLLOW_TARGET_MAX_DISTANCE +
|
||||
myNewPosition;
|
||||
_actorActionController.PerformAction(_actor.GetMovementAction(1));
|
||||
}
|
||||
|
||||
|
||||
// Increase fly speed if the distance is greater than a threshold
|
||||
var flySpeed = distanceToTarget > FOLLOW_TARGET_FLY_SPEED_CHANEG_DISTANCE ? MaxFlySpeed : DefaultFlySpeed;
|
||||
|
||||
_actorActionController.PerformAction(
|
||||
Vector3.Distance(myNewPosition, transform.position) < FOLLOW_TARGET_FLY_SPEED_CHANEG_DISTANCE - 1f
|
||||
? _actor.GetMovementAction(MovementMode.Walk)
|
||||
: _actor.GetMovementAction(MovementMode.Run));
|
||||
|
||||
transform.position = Vector3.MoveTowards(transform.position,
|
||||
myNewPosition,
|
||||
Time.deltaTime * FLY_SPEED);
|
||||
transform.LookAt(new Vector3(myNewPosition.x, transform.position.y, myNewPosition.z));
|
||||
Time.deltaTime * flySpeed);
|
||||
}
|
||||
|
||||
if (distanceToNewPosition < ROTATION_SYNCING_DISTANCE)
|
||||
@@ -140,16 +145,20 @@ namespace Pal3.Actor
|
||||
_target.transform.forward, ROTATION_SPEED * Time.deltaTime, 0.0f);
|
||||
transform.rotation = Quaternion.LookRotation(newRotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.LookAt(new Vector3(myNewPosition.x, transform.position.y, myNewPosition.z));
|
||||
}
|
||||
}
|
||||
|
||||
private void FindAndSetTarget()
|
||||
{
|
||||
_target = _sceneManager.GetCurrentScene().GetActorGameObject((byte) FOLLOW_ACTOR_ID);
|
||||
_target = _sceneManager.GetCurrentScene().GetActorGameObject((int) FOLLOW_ACTOR_ID);
|
||||
_targetActorController = _target.GetComponent<ActorController>();
|
||||
_targetActorActionController = _target.GetComponent<ActorActionController>();
|
||||
_isTargetRegistered = true;
|
||||
}
|
||||
|
||||
|
||||
public void Execute(HuaYingSwitchBehaviourModeCommand command)
|
||||
{
|
||||
switch (command.Mode)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -40,18 +40,18 @@ namespace Pal3.Actor
|
||||
{
|
||||
return _currentMode;
|
||||
}
|
||||
|
||||
|
||||
public void Execute(LongKuiSwitchModeCommand command)
|
||||
{
|
||||
_currentMode = command.Mode;
|
||||
|
||||
|
||||
_actor.ChangeName(command.Mode == 0 ?
|
||||
ActorConstants.LongKuiHumanModeActorName :
|
||||
ActorConstants.LongKuiGhostModeActorName);
|
||||
|
||||
ActorConstants.LongKuiBlueModeActorName :
|
||||
ActorConstants.LongKuiRedModeActorName);
|
||||
|
||||
if (_actor.IsActive)
|
||||
{
|
||||
_actionController.PerformAction(_actor.GetIdleAction(), overwrite: true);
|
||||
_actionController.PerformAction(_actor.GetIdleAction(), overwrite: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,12 +1,14 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Command.InternalCommands
|
||||
namespace Pal3.Actor
|
||||
{
|
||||
public class VideoEndedNotification : ICommand
|
||||
public enum MovementMode
|
||||
{
|
||||
public VideoEndedNotification() { }
|
||||
Walk = 0,
|
||||
Run = 1,
|
||||
StepBack = 2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c1f0fa72feb4dc9acb1ab98c6cc8a80
|
||||
timeCreated: 1677630514
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -12,12 +12,12 @@ namespace Pal3.Actor
|
||||
{
|
||||
Idle = 0,
|
||||
DisposeSelf,
|
||||
Reverse
|
||||
WaitAndReverse
|
||||
}
|
||||
|
||||
public class Path
|
||||
{
|
||||
public int MovementMode { get; private set; }
|
||||
public MovementMode MovementMode { get; private set; }
|
||||
|
||||
public EndOfPathActionType EndOfPathAction { get; private set; }
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Pal3.Actor
|
||||
private int _currentWayPointIndex;
|
||||
|
||||
public void SetPath(Vector3[] wayPoints,
|
||||
int movementMode,
|
||||
MovementMode movementMode,
|
||||
EndOfPathActionType endOfPathAction,
|
||||
bool ignoreObstacle)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace Pal3.Audio
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.DataLoader;
|
||||
using Core.DataReader.Cpk;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.Extensions;
|
||||
@@ -47,10 +46,10 @@ namespace Pal3.Audio
|
||||
private string _currentScriptMusic = string.Empty;
|
||||
private readonly List<string> _playingSfxSourceNames = new ();
|
||||
|
||||
// TODO: Fix and remove this hack
|
||||
private const string PLAYER_ACTOR_MOVEMENT_SFX_AUDIO_SOURCE_NAME = "PlayerActorMovementSfx";
|
||||
// TODO: Maybe it is better to control movement sfx
|
||||
// by the player gameplay controller instead of AudioManager?
|
||||
private bool _playerMovementSfxInProgress;
|
||||
|
||||
|
||||
private CancellationTokenSource _sceneAudioCts = new ();
|
||||
|
||||
public void Init(Camera mainCamera,
|
||||
@@ -74,7 +73,7 @@ namespace Pal3.Audio
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
private IEnumerator PlaySceneMusic(string cityName, string sceneName)
|
||||
private IEnumerator PlaySceneMusicAsync(string cityName, string sceneName)
|
||||
{
|
||||
var key = $"{cityName}_{sceneName}";
|
||||
var musicName = string.Empty;
|
||||
@@ -103,11 +102,11 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = musicName;
|
||||
var musicFileVirtualPath = GetMusicFileVirtualPath(musicName);
|
||||
var musicFileCachePath = _resourceProvider.GetMp3FilePathInCacheFolder(musicFileVirtualPath);
|
||||
|
||||
yield return PlayMusic(musicName, musicFileVirtualPath, musicFileCachePath, -1);
|
||||
|
||||
yield return PlayMusicAsync(musicName, musicFileVirtualPath, musicFileCachePath, -1);
|
||||
}
|
||||
|
||||
private IEnumerator PlayAudioClip(AudioSource audioSource,
|
||||
private IEnumerator PlayAudioClipAsync(AudioSource audioSource,
|
||||
AudioClip audioClip,
|
||||
int loopCount,
|
||||
float interval,
|
||||
@@ -146,9 +145,9 @@ namespace Pal3.Audio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Spatial Audio
|
||||
private IEnumerator AttachSfxToGameObjectAndPlaySfx(GameObject parent,
|
||||
private IEnumerator AttachSfxToGameObjectAndPlaySfxAsync(GameObject parent,
|
||||
string sfxFilePath,
|
||||
string audioSourceName,
|
||||
int loopCount,
|
||||
@@ -160,17 +159,15 @@ namespace Pal3.Audio
|
||||
|
||||
AudioClip sfxAudioClip = null;
|
||||
|
||||
yield return _resourceProvider.LoadAudioClip(sfxFilePath, AudioType.WAV, audioClip =>
|
||||
{
|
||||
sfxAudioClip = audioClip;
|
||||
});
|
||||
|
||||
yield return _resourceProvider.LoadAudioClipAsync(sfxFilePath, AudioType.WAV, streamAudio: false,
|
||||
audioClip => { sfxAudioClip = audioClip; });
|
||||
|
||||
if (parent == null ||
|
||||
cancellationToken.IsCancellationRequested ||
|
||||
sfxAudioClip == null) yield break;
|
||||
|
||||
if (parent != _mainCamera.gameObject &&
|
||||
audioSourceName == PLAYER_ACTOR_MOVEMENT_SFX_AUDIO_SOURCE_NAME &&
|
||||
audioSourceName == AudioConstants.PlayerActorMovementSfxAudioSourceName &&
|
||||
_playerMovementSfxInProgress == false)
|
||||
{
|
||||
yield break; // Means movement sfx is already stopped before it started due to the delay of the coroutine
|
||||
@@ -200,10 +197,10 @@ namespace Pal3.Audio
|
||||
audioSource.rolloffMode = AudioRolloffMode.Linear;
|
||||
audioSource.maxDistance = 75f;
|
||||
|
||||
yield return PlayAudioClip(audioSource, sfxAudioClip, loopCount, interval, volume, cancellationToken);
|
||||
yield return PlayAudioClipAsync(audioSource, sfxAudioClip, loopCount, interval, volume, cancellationToken);
|
||||
}
|
||||
|
||||
private IEnumerator StartWithDelay(
|
||||
|
||||
private IEnumerator StartWithDelayAsync(
|
||||
float delayInSeconds,
|
||||
IEnumerator coroutine,
|
||||
CancellationToken cancellationToken)
|
||||
@@ -226,26 +223,24 @@ namespace Pal3.Audio
|
||||
$"{FileConstants.MusicCpkPathInfo.relativePath}{separator}{musicName}.mp3";
|
||||
}
|
||||
|
||||
public IEnumerator PlayMusic(string musicName,
|
||||
public IEnumerator PlayMusicAsync(string musicName,
|
||||
string musicFileVirtualPath,
|
||||
string musicFileCachePath,
|
||||
int loopCount)
|
||||
{
|
||||
yield return _resourceProvider.ExtractAndMoveMp3FileToCacheFolder(musicFileVirtualPath, musicFileCachePath);
|
||||
|
||||
yield return _resourceProvider.ExtractAndMoveMp3FileToCacheFolderAsync(musicFileVirtualPath, musicFileCachePath);
|
||||
|
||||
AudioClip musicClip = null;
|
||||
yield return _resourceProvider.LoadAudioClip(musicFileCachePath, AudioType.MPEG, audioClip =>
|
||||
{
|
||||
musicClip = audioClip;
|
||||
});
|
||||
|
||||
yield return _resourceProvider.LoadAudioClipAsync(musicFileCachePath, AudioType.MPEG, streamAudio: true,
|
||||
audioClip => { musicClip = audioClip; });
|
||||
|
||||
// We need to check if current music clip is the same as the one we are trying to play,
|
||||
// since we are using coroutine to load and play music, there is a chance that the music
|
||||
// clip we are trying to play is not the same as the one we supposed to play.
|
||||
if (musicClip == null ||
|
||||
!string.Equals(_currentMusicClipName, musicName, StringComparison.OrdinalIgnoreCase)) yield break;
|
||||
|
||||
yield return PlayAudioClip(_musicPlayer, musicClip, loopCount, 0f, DefaultMusicVolume,
|
||||
|
||||
yield return PlayAudioClipAsync(_musicPlayer, musicClip, loopCount, 0f, DefaultMusicVolume,
|
||||
new CancellationToken(false)); // Should not stop music during scene switch
|
||||
}
|
||||
|
||||
@@ -264,16 +259,16 @@ namespace Pal3.Audio
|
||||
if (audioSourceParentTransform.GetComponent<AudioSource>() is { } audioSource)
|
||||
{
|
||||
audioSource.Stop();
|
||||
|
||||
|
||||
if (audioSource.clip != null)
|
||||
{
|
||||
Destroy(audioSource.clip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Destroy(audioSourceParentTransform.gameObject);
|
||||
}
|
||||
|
||||
|
||||
_playingSfxSourceNames.Clear();
|
||||
}
|
||||
|
||||
@@ -297,7 +292,7 @@ namespace Pal3.Audio
|
||||
#elif PAL3A
|
||||
var sfxName = command.SfxName.ToUpper();
|
||||
#endif
|
||||
|
||||
|
||||
var loopCount = command.LoopCount;
|
||||
|
||||
#if PAL3
|
||||
@@ -316,7 +311,7 @@ namespace Pal3.Audio
|
||||
{
|
||||
case 0: // start playing sfx indefinitely for the given sfxName
|
||||
_playingSfxSourceNames.Add(sfxName);
|
||||
StartCoroutine(AttachSfxToGameObjectAndPlaySfx(_mainCamera.gameObject,
|
||||
StartCoroutine(AttachSfxToGameObjectAndPlaySfxAsync(_mainCamera.gameObject,
|
||||
_resourceProvider.GetSfxFilePath(sfxName),
|
||||
sfxName, // use sfx name as audio source name
|
||||
loopCount: -1, // loop indefinitely
|
||||
@@ -336,7 +331,7 @@ namespace Pal3.Audio
|
||||
_playingSfxSourceNames.Add(sfxName);
|
||||
var sfxFilePath = _resourceProvider.GetSfxFilePath(sfxName);
|
||||
CancellationToken cancellationToken = _sceneAudioCts.Token;
|
||||
StartCoroutine(AttachSfxToGameObjectAndPlaySfx(_mainCamera.gameObject,
|
||||
StartCoroutine(AttachSfxToGameObjectAndPlaySfxAsync(_mainCamera.gameObject,
|
||||
sfxFilePath,
|
||||
sfxName, // use sfx name as audio source name
|
||||
loopCount,
|
||||
@@ -350,15 +345,15 @@ namespace Pal3.Audio
|
||||
|
||||
public void Execute(AttachSfxToGameObjectRequest request)
|
||||
{
|
||||
if (request.AudioSourceName == PLAYER_ACTOR_MOVEMENT_SFX_AUDIO_SOURCE_NAME)
|
||||
if (request.AudioSourceName == AudioConstants.PlayerActorMovementSfxAudioSourceName)
|
||||
{
|
||||
_playerMovementSfxInProgress = true;
|
||||
}
|
||||
|
||||
|
||||
var sfxFilePath = _resourceProvider.GetSfxFilePath(request.SfxName);
|
||||
CancellationToken cancellationToken = _sceneAudioCts.Token;
|
||||
StartCoroutine(StartWithDelay(request.StartDelayInSeconds,
|
||||
AttachSfxToGameObjectAndPlaySfx(request.Parent,
|
||||
StartCoroutine(StartWithDelayAsync(request.StartDelayInSeconds,
|
||||
AttachSfxToGameObjectAndPlaySfxAsync(request.Parent,
|
||||
sfxFilePath,
|
||||
request.AudioSourceName,
|
||||
request.LoopCount,
|
||||
@@ -367,21 +362,21 @@ namespace Pal3.Audio
|
||||
cancellationToken),
|
||||
cancellationToken));
|
||||
}
|
||||
|
||||
|
||||
public void Execute(StopSfxPlayingAtGameObjectRequest command)
|
||||
{
|
||||
if (command.AudioSourceName == PLAYER_ACTOR_MOVEMENT_SFX_AUDIO_SOURCE_NAME)
|
||||
if (command.AudioSourceName == AudioConstants.PlayerActorMovementSfxAudioSourceName)
|
||||
{
|
||||
_playerMovementSfxInProgress = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Transform audioSourceParentTransform = command.Parent.transform.Find(command.AudioSourceName);
|
||||
if (audioSourceParentTransform == null) return;
|
||||
|
||||
GameObject audioSourceParent = audioSourceParentTransform.gameObject;
|
||||
var audioSource = audioSourceParent.GetComponentInChildren<AudioSource>();
|
||||
if (audioSource == default) return;
|
||||
|
||||
|
||||
audioSource.Stop();
|
||||
audioSource.clip = null;
|
||||
|
||||
@@ -413,7 +408,7 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = command.MusicName;
|
||||
var musicFileVirtualPath = GetMusicFileVirtualPath(command.MusicName);
|
||||
var musicFileCachePath = _resourceProvider.GetMp3FilePathInCacheFolder(musicFileVirtualPath);
|
||||
StartCoroutine(PlayMusic(command.MusicName,
|
||||
StartCoroutine(PlayMusicAsync(command.MusicName,
|
||||
musicFileVirtualPath,
|
||||
musicFileCachePath,
|
||||
command.Loop == 0 ? -1 : command.Loop));
|
||||
@@ -430,7 +425,7 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = string.Empty;
|
||||
|
||||
ScnSceneInfo sceneInfo = _sceneManager.GetCurrentScene().GetSceneInfo();
|
||||
StartCoroutine(PlaySceneMusic(sceneInfo.CityName, sceneInfo.Name));
|
||||
StartCoroutine(PlaySceneMusicAsync(sceneInfo.CityName, sceneInfo.SceneName));
|
||||
}
|
||||
|
||||
public void Execute(ScenePreLoadingNotification command)
|
||||
@@ -444,7 +439,7 @@ namespace Pal3.Audio
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentScriptMusic))
|
||||
{
|
||||
StartCoroutine(PlaySceneMusic(command.NewSceneInfo.CityName, command.NewSceneInfo.Name));
|
||||
StartCoroutine(PlaySceneMusicAsync(command.NewSceneInfo.CityName, command.NewSceneInfo.SceneName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -36,6 +36,8 @@ namespace Pal3.Camera
|
||||
#if PAL3A
|
||||
ICommandExecutor<CameraOrbitHorizontalCommand>,
|
||||
ICommandExecutor<CameraOrbitVerticalCommand>,
|
||||
ICommandExecutor<CameraMoveToLookAtPointCommand>,
|
||||
ICommandExecutor<CameraMoveToDefaultLookAtPointCommand>,
|
||||
#endif
|
||||
ICommandExecutor<CameraFadeInCommand>,
|
||||
ICommandExecutor<CameraFadeInWhiteCommand>,
|
||||
@@ -43,7 +45,7 @@ namespace Pal3.Camera
|
||||
ICommandExecutor<CameraFadeOutWhiteCommand>,
|
||||
ICommandExecutor<CameraPushCommand>,
|
||||
ICommandExecutor<CameraMoveCommand>,
|
||||
ICommandExecutor<CameraFreeCommand>,
|
||||
ICommandExecutor<CameraFollowPlayerCommand>,
|
||||
ICommandExecutor<CameraSetYawCommand>,
|
||||
ICommandExecutor<CameraFocusOnActorCommand>,
|
||||
ICommandExecutor<CameraFocusOnSceneObjectCommand>,
|
||||
@@ -53,38 +55,36 @@ namespace Pal3.Camera
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
private const float FADE_ANIMATION_DURATION = 3f;
|
||||
private const float SCENE_STORY_B_ROOM_HEIGHT = 32f;
|
||||
private const float SCENE_IN_DOOR_ROOM_FLOOR_HEIGHT = 1.6f;
|
||||
private const float CAMERA_DEFAULT_DISTANCE = 46f;
|
||||
private const float CAMERA_IN_DOOR_DISTANCE = 34f;
|
||||
private const float CAMERA_ROTATION_SPEED_KEY_PRESS = 120f;
|
||||
private const float CAMERA_ROTATION_SPEED_SCROLL = 15f;
|
||||
private const float CAMERA_ROTATION_SPEED_DRAG = 10f;
|
||||
private const float CAMERA_SMOOTH_FOLLOW_TIME = 0.2f;
|
||||
private const float CAMERA_SMOOTH_FOLLOW_MAX_DISTANCE = 3f;
|
||||
private const float CAMERA_SMOOTH_FOLLOW_MAX_DISTANCE = 7f;
|
||||
|
||||
private Camera _camera;
|
||||
private Image _curtainImage;
|
||||
|
||||
private GameObject _lookAtGameObject;
|
||||
private Vector3 _lastLookAtPoint = Vector3.zero;
|
||||
private Vector3 _cameraMoveVelocity = Vector3.zero;
|
||||
|
||||
private bool _shouldResetVelocity = false;
|
||||
|
||||
private Vector3 _actualPosition = Vector3.zero;
|
||||
private Vector3 _actualLookAtPoint = Vector3.zero;
|
||||
|
||||
private Vector3 _cameraOffset = Vector3.zero;
|
||||
private float _lookAtPointYOffset;
|
||||
|
||||
private bool _free = true;
|
||||
private bool _freeToRotate;
|
||||
private bool _cameraFollowPlayer = true;
|
||||
private bool _shouldResetVelocity = false;
|
||||
private int _currentAppliedDefaultTransformOption = 0;
|
||||
|
||||
private PlayerInputActions _inputActions;
|
||||
private PlayerGamePlayController _gamePlayController;
|
||||
private SceneManager _sceneManager;
|
||||
private GameStateManager _gameStateManager;
|
||||
private bool _freeToRotate;
|
||||
|
||||
private GameObject _lookAtGameObject;
|
||||
|
||||
private int _currentAppliedDefaultTransformOption = 0;
|
||||
|
||||
private RectTransform _joyStickRect;
|
||||
private float _joyStickMovementRange;
|
||||
private bool _isTouchEnabled;
|
||||
@@ -98,7 +98,7 @@ namespace Pal3.Camera
|
||||
Vector3 cameraPosition,
|
||||
Quaternion cameraRotation,
|
||||
Vector3 cameraOffset)> _cameraLastKnownSceneState = new ();
|
||||
|
||||
|
||||
public void Init(PlayerInputActions inputActions,
|
||||
PlayerGamePlayController gamePlayController,
|
||||
SceneManager sceneManager,
|
||||
@@ -111,7 +111,7 @@ namespace Pal3.Camera
|
||||
_gamePlayController = gamePlayController != null ? gamePlayController : throw new ArgumentNullException(nameof(gamePlayController));
|
||||
_sceneManager = sceneManager ?? throw new ArgumentNullException(nameof(sceneManager));
|
||||
_gameStateManager = gameStateManager ?? throw new ArgumentNullException(nameof(gameStateManager));
|
||||
|
||||
|
||||
_camera = mainCamera;
|
||||
_camera!.fieldOfView = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Pal3.Camera
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!_free)
|
||||
if (!_cameraFollowPlayer)
|
||||
{
|
||||
_shouldResetVelocity = true;
|
||||
return;
|
||||
@@ -144,9 +144,14 @@ namespace Pal3.Camera
|
||||
|
||||
if (_cameraAnimationInProgress) return;
|
||||
|
||||
_lastLookAtPoint = _lookAtGameObject != null ?
|
||||
_lookAtGameObject.transform.position :
|
||||
_gamePlayController.GetPlayerActorLastKnownPosition();
|
||||
if (_lookAtGameObject != null)
|
||||
{
|
||||
_lastLookAtPoint = _lookAtGameObject.transform.position;
|
||||
}
|
||||
else if (_gamePlayController.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
{
|
||||
_lastLookAtPoint = playerActorPosition;
|
||||
}
|
||||
|
||||
var yOffset = new Vector3(0f, _lookAtPointYOffset, 0f);
|
||||
Vector3 targetPosition = _lastLookAtPoint + _cameraOffset;
|
||||
@@ -248,10 +253,10 @@ namespace Pal3.Camera
|
||||
return Mathf.Rad2Deg * 2 * Mathf.Atan(Mathf.Tan((horizontalFov * Mathf.Deg2Rad) / 2f) / aspect);
|
||||
}
|
||||
|
||||
private IEnumerator Shake(float duration, float amplitude, WaitUntilCanceled waiter = null)
|
||||
private IEnumerator ShakeAsync(float duration, float amplitude, WaitUntilCanceled waiter = null)
|
||||
{
|
||||
_cameraAnimationInProgress = true;
|
||||
yield return AnimationHelper.ShakeTransform(_camera.transform,
|
||||
yield return AnimationHelper.ShakeTransformAsync(_camera.transform,
|
||||
duration,
|
||||
amplitude,
|
||||
false,
|
||||
@@ -261,17 +266,16 @@ namespace Pal3.Camera
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
private IEnumerator Move(Vector3 position,
|
||||
private IEnumerator MoveAsync(Vector3 position,
|
||||
float duration,
|
||||
int mode,
|
||||
AnimationCurveType curveType,
|
||||
WaitUntilCanceled waiter = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
_cameraAnimationInProgress = true;
|
||||
var curveType = (AnimationCurveType) mode;
|
||||
Transform cameraTransform = _camera.transform;
|
||||
Vector3 oldPosition = cameraTransform.position;
|
||||
yield return AnimationHelper.MoveTransform(cameraTransform, position, duration, curveType, cancellationToken);
|
||||
yield return AnimationHelper.MoveTransformAsync(cameraTransform, position, duration, curveType, cancellationToken);
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
_lastLookAtPoint += position - oldPosition;
|
||||
@@ -281,7 +285,7 @@ namespace Pal3.Camera
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
private IEnumerator Orbit(Quaternion toRotation,
|
||||
private IEnumerator OrbitAsync(Quaternion toRotation,
|
||||
float duration,
|
||||
AnimationCurveType curveType,
|
||||
float distanceDelta,
|
||||
@@ -290,7 +294,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
_cameraAnimationInProgress = true;
|
||||
Vector3 lookAtPoint = _lastLookAtPoint;
|
||||
yield return AnimationHelper.OrbitTransformAroundCenterPoint(_camera.transform,
|
||||
yield return AnimationHelper.OrbitTransformAroundCenterPointAsync(_camera.transform,
|
||||
toRotation,
|
||||
lookAtPoint,
|
||||
duration,
|
||||
@@ -306,14 +310,14 @@ namespace Pal3.Camera
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
private IEnumerator Rotate(Quaternion toRotation,
|
||||
private IEnumerator RotateAsync(Quaternion toRotation,
|
||||
float duration,
|
||||
AnimationCurveType curveType,
|
||||
WaitUntilCanceled waiter = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
_cameraAnimationInProgress = true;
|
||||
yield return AnimationHelper.RotateTransform(_camera.transform,
|
||||
yield return AnimationHelper.RotateTransformAsync(_camera.transform,
|
||||
toRotation,
|
||||
duration,
|
||||
curveType,
|
||||
@@ -322,7 +326,7 @@ namespace Pal3.Camera
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
public IEnumerator Push(float distance,
|
||||
public IEnumerator PushAsync(float distance,
|
||||
float duration,
|
||||
AnimationCurveType curveType,
|
||||
WaitUntilCanceled waiter = null,
|
||||
@@ -331,13 +335,13 @@ namespace Pal3.Camera
|
||||
_cameraAnimationInProgress = true;
|
||||
Vector3 oldPosition = _camera.transform.position;
|
||||
var oldDistance = Vector3.Distance(oldPosition, _lastLookAtPoint);
|
||||
Vector3 cameraDirection = (oldPosition - _lastLookAtPoint).normalized;
|
||||
Vector3 newPosition = oldPosition + cameraDirection * (distance - oldDistance);
|
||||
Vector3 cameraFacingDirection = (oldPosition - _lastLookAtPoint).normalized;
|
||||
Vector3 newPosition = oldPosition + cameraFacingDirection * (distance - oldDistance);
|
||||
Transform cameraTransform = _camera.transform;
|
||||
|
||||
yield return AnimationHelper.MoveTransform(cameraTransform,
|
||||
|
||||
yield return AnimationHelper.MoveTransformAsync(cameraTransform,
|
||||
newPosition,
|
||||
duration,
|
||||
duration,
|
||||
curveType,
|
||||
cancellationToken);
|
||||
|
||||
@@ -349,7 +353,7 @@ namespace Pal3.Camera
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
public IEnumerator Fade(bool fadeIn,
|
||||
public IEnumerator FadeAsync(bool fadeIn,
|
||||
float duration,
|
||||
Color color,
|
||||
WaitUntilCanceled waiter = null,
|
||||
@@ -360,7 +364,7 @@ namespace Pal3.Camera
|
||||
float from = 1f, to = 0f;
|
||||
if (!fadeIn) { from = 0f; to = 1f; }
|
||||
|
||||
yield return AnimationHelper.EnumerateValue(from, to, duration, AnimationCurveType.Linear,
|
||||
yield return AnimationHelper.EnumerateValueAsync(from, to, duration, AnimationCurveType.Linear,
|
||||
alpha =>
|
||||
{
|
||||
_curtainImage.color = new Color(color.r, color.g, color.b, alpha);
|
||||
@@ -368,7 +372,7 @@ namespace Pal3.Camera
|
||||
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
_curtainImage.color = new Color(color.r, color.g, color.b, to);
|
||||
_curtainImage.color = new Color(color.r, color.g, color.b, to);
|
||||
}
|
||||
|
||||
waiter?.CancelWait();
|
||||
@@ -378,28 +382,24 @@ namespace Pal3.Camera
|
||||
{
|
||||
return _currentAppliedDefaultTransformOption;
|
||||
}
|
||||
|
||||
|
||||
private void ApplySceneSettings(ScnSceneInfo sceneInfo)
|
||||
{
|
||||
switch (sceneInfo.SceneType)
|
||||
{
|
||||
case ScnSceneType.StoryB:
|
||||
_freeToRotate = false;
|
||||
_lookAtPointYOffset = SCENE_STORY_B_ROOM_HEIGHT /
|
||||
GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
_camera.nearClipPlane = 1f;
|
||||
_camera.farClipPlane = 500f;
|
||||
ApplyDefaultSettings(1);
|
||||
break;
|
||||
case ScnSceneType.StoryA:
|
||||
_freeToRotate = true;
|
||||
case ScnSceneType.OutDoor:
|
||||
_lookAtPointYOffset = 0;
|
||||
_camera.nearClipPlane = 2f;
|
||||
_camera.farClipPlane = 800f;
|
||||
ApplyDefaultSettings(0);
|
||||
break;
|
||||
case ScnSceneType.InDoor:
|
||||
_lookAtPointYOffset = SCENE_IN_DOOR_ROOM_FLOOR_HEIGHT;
|
||||
_camera.nearClipPlane = 1f;
|
||||
_camera.farClipPlane = 500f;
|
||||
ApplyDefaultSettings(1);
|
||||
break;
|
||||
case ScnSceneType.Maze:
|
||||
_freeToRotate = true;
|
||||
_lookAtPointYOffset = 0;
|
||||
_camera.nearClipPlane = 2f;
|
||||
_camera.farClipPlane = 800f;
|
||||
@@ -418,39 +418,49 @@ namespace Pal3.Camera
|
||||
|
||||
private void ApplyDefaultSettings(int option)
|
||||
{
|
||||
Quaternion rotation;
|
||||
float distance = 688.0f / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
float cameraDistance;
|
||||
Quaternion cameraRotation;
|
||||
float cameraFov;
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case 0:
|
||||
_camera.fieldOfView = HorizontalToVerticalFov(26.0f, 4f/3f);
|
||||
distance = 1000 / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
rotation = GameBoxInterpreter.ToUnityRotation(-30.37f, -52.65f, 0f);
|
||||
_freeToRotate = true;
|
||||
cameraFov = HorizontalToVerticalFov(26.0f, 4f/3f);
|
||||
cameraDistance = CAMERA_DEFAULT_DISTANCE;
|
||||
cameraRotation = GameBoxInterpreter.ToUnityRotation(-30.37f, -52.65f, 0f);
|
||||
break;
|
||||
case 1:
|
||||
_camera.fieldOfView = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
rotation = GameBoxInterpreter.ToUnityRotation(-19.48f, 33.24f, 0f);
|
||||
_freeToRotate = false;
|
||||
cameraFov = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
cameraDistance = CAMERA_IN_DOOR_DISTANCE;
|
||||
cameraRotation = GameBoxInterpreter.ToUnityRotation(-19.48f, 33.24f, 0f);
|
||||
break;
|
||||
case 2:
|
||||
_camera.fieldOfView = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
rotation = GameBoxInterpreter.ToUnityRotation(-19.48f, -33.24f, 0f);
|
||||
_freeToRotate = false;
|
||||
cameraFov = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
cameraDistance = CAMERA_IN_DOOR_DISTANCE;
|
||||
cameraRotation = GameBoxInterpreter.ToUnityRotation(-19.48f, -33.24f, 0f);
|
||||
break;
|
||||
case 3:
|
||||
_camera.fieldOfView = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
rotation = GameBoxInterpreter.ToUnityRotation(-19.48f, 0f, 0f);
|
||||
_freeToRotate = false;
|
||||
cameraFov = HorizontalToVerticalFov(24.05f, 4f/3f);
|
||||
cameraDistance = CAMERA_IN_DOOR_DISTANCE;
|
||||
cameraRotation = GameBoxInterpreter.ToUnityRotation(-19.48f, 0f, 0f);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_camera.fieldOfView = cameraFov;
|
||||
|
||||
var yOffset = new Vector3(0f, _lookAtPointYOffset, 0f);
|
||||
|
||||
Vector3 cameraDirection = (rotation * Vector3.forward).normalized;
|
||||
Vector3 cameraPosition = _lastLookAtPoint + cameraDirection * -distance + yOffset;
|
||||
Vector3 cameraFacingDirection = (cameraRotation * Vector3.forward).normalized;
|
||||
Vector3 cameraPosition = _lastLookAtPoint + cameraFacingDirection * -cameraDistance + yOffset;
|
||||
|
||||
Transform cameraTransform = _camera.transform;
|
||||
cameraTransform.rotation = rotation;
|
||||
cameraTransform.rotation = cameraRotation;
|
||||
cameraTransform.position = cameraPosition;
|
||||
|
||||
_cameraOffset = cameraTransform.position - _lastLookAtPoint;
|
||||
@@ -459,84 +469,89 @@ namespace Pal3.Camera
|
||||
public void Execute(CameraSetDefaultTransformCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
_lastLookAtPoint = _gamePlayController.GetPlayerActorLastKnownPosition();
|
||||
|
||||
if (_gamePlayController.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
{
|
||||
_lastLookAtPoint = playerActorPosition;
|
||||
}
|
||||
|
||||
ApplyDefaultSettings(command.Option);
|
||||
_currentAppliedDefaultTransformOption = command.Option;
|
||||
_free = true;
|
||||
_cameraFollowPlayer = true;
|
||||
}
|
||||
|
||||
public void Execute(CameraSetTransformCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
|
||||
_lookAtGameObject = null;
|
||||
|
||||
Vector3 cameraPosition = GameBoxInterpreter.ToUnityPosition(
|
||||
new Vector3(command.X, command.Y, command.Z));
|
||||
Vector3 cameraPosition = GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
Transform cameraTransform = _camera.transform;
|
||||
cameraTransform.position = cameraPosition;
|
||||
cameraTransform.rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
|
||||
_lastLookAtPoint = cameraTransform.position + cameraTransform.forward *
|
||||
(command.Distance / GameBoxInterpreter.GameBoxUnitToUnityUnit);
|
||||
_lastLookAtPoint = cameraTransform.position +
|
||||
cameraTransform.forward * GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
_cameraOffset = cameraPosition - _lastLookAtPoint;
|
||||
|
||||
if (_gameStateManager.GetCurrentState() != GameState.Gameplay)
|
||||
{
|
||||
_free = false;
|
||||
_cameraFollowPlayer = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(CameraFreeCommand command)
|
||||
public void Execute(CameraFollowPlayerCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
_lookAtGameObject = null;
|
||||
_free = command.Free == 1;
|
||||
_cameraFollowPlayer = command.Follow == 1;
|
||||
}
|
||||
|
||||
public void Execute(CameraShakeEffectCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
StartCoroutine(Shake(command.Duration,
|
||||
command.Amplitude / GameBoxInterpreter.GameBoxUnitToUnityUnit, waiter));
|
||||
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(ShakeAsync(command.Duration, GameBoxInterpreter.ToUnityDistance(command.Amplitude), waiter));
|
||||
}
|
||||
|
||||
public void Execute(CameraOrbitCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Orbit(rotation, command.Duration, (AnimationCurveType)command.CurveType, 0f, waiter));
|
||||
StartCoroutine(OrbitAsync(rotation, command.Duration, (AnimationCurveType)command.CurveType, 0f, waiter));
|
||||
}
|
||||
|
||||
public void Execute(CameraRotateCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
|
||||
#if PAL3
|
||||
if (true)
|
||||
#elif PAL3A
|
||||
if (command.Synchronous == 1)
|
||||
#endif
|
||||
{
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Rotate(rotation, command.Duration, (AnimationCurveType)command.CurveType, waiter));
|
||||
StartCoroutine(RotateAsync(rotation, command.Duration, (AnimationCurveType)command.CurveType, waiter));
|
||||
}
|
||||
#if PAL3A
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Rotate(rotation,
|
||||
StartCoroutine(RotateAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
waiter: null,
|
||||
@@ -544,124 +559,64 @@ namespace Pal3.Camera
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(CameraOrbitHorizontalCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var oldDistance = _cameraOffset.magnitude;
|
||||
var newDistance = (command.Distance / GameBoxInterpreter.GameBoxUnitToUnityUnit);
|
||||
var distanceDelta = newDistance - oldDistance;
|
||||
|
||||
if (command.Synchronous == 1)
|
||||
{
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Orbit(rotation, command.Duration, (AnimationCurveType)command.CurveType, distanceDelta, waiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Orbit(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
waiter: null,
|
||||
_asyncCameraAnimationCts.Token));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(CameraOrbitVerticalCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var oldDistance = _cameraOffset.magnitude;
|
||||
var newDistance = (command.Distance / GameBoxInterpreter.GameBoxUnitToUnityUnit);
|
||||
var distanceDelta = newDistance - oldDistance;
|
||||
|
||||
if (command.Synchronous == 1)
|
||||
{
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Orbit(rotation, command.Duration, (AnimationCurveType)command.CurveType, distanceDelta, waiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(Orbit(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
waiter: null,
|
||||
_asyncCameraAnimationCts.Token));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Execute(CameraFadeInCommand command)
|
||||
{
|
||||
if (!_cameraFadeAnimationCts.IsCancellationRequested) _cameraFadeAnimationCts.Cancel();
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
StartCoroutine(Fade(true, FADE_ANIMATION_DURATION, Color.black, waiter, _cameraFadeAnimationCts.Token));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(true, FADE_ANIMATION_DURATION, Color.black, waiter, _cameraFadeAnimationCts.Token));
|
||||
}
|
||||
|
||||
public void Execute(CameraFadeInWhiteCommand command)
|
||||
{
|
||||
if (!_cameraFadeAnimationCts.IsCancellationRequested) _cameraFadeAnimationCts.Cancel();
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
StartCoroutine(Fade(true, FADE_ANIMATION_DURATION, Color.white, waiter, _cameraFadeAnimationCts.Token));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(true, FADE_ANIMATION_DURATION, Color.white, waiter, _cameraFadeAnimationCts.Token));
|
||||
}
|
||||
|
||||
public void Execute(CameraFadeOutCommand command)
|
||||
{
|
||||
if (!_cameraFadeAnimationCts.IsCancellationRequested) _cameraFadeAnimationCts.Cancel();
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
StartCoroutine(Fade(false, FADE_ANIMATION_DURATION, Color.black, waiter, _cameraFadeAnimationCts.Token));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(false, FADE_ANIMATION_DURATION, Color.black, waiter, _cameraFadeAnimationCts.Token));
|
||||
}
|
||||
|
||||
public void Execute(CameraFadeOutWhiteCommand command)
|
||||
{
|
||||
if (!_cameraFadeAnimationCts.IsCancellationRequested) _cameraFadeAnimationCts.Cancel();
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
StartCoroutine(Fade(false, FADE_ANIMATION_DURATION, Color.white, waiter, _cameraFadeAnimationCts.Token));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(false, FADE_ANIMATION_DURATION, Color.white, waiter, _cameraFadeAnimationCts.Token));
|
||||
}
|
||||
|
||||
public void Execute(CameraPushCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
|
||||
#if PAL3
|
||||
if (true)
|
||||
#elif PAL3A
|
||||
if (command.Synchronous == 1)
|
||||
#endif
|
||||
{
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
var distance = command.Distance / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
StartCoroutine(Push(distance, command.Duration, (AnimationCurveType)command.CurveType, waiter));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
var distance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
StartCoroutine(PushAsync(distance, command.Duration, (AnimationCurveType)command.CurveType, waiter));
|
||||
}
|
||||
#if PAL3A
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
var distance = command.Distance / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
StartCoroutine(Push(distance,
|
||||
var distance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
StartCoroutine(PushAsync(distance,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
waiter: null,
|
||||
@@ -673,26 +628,32 @@ namespace Pal3.Camera
|
||||
public void Execute(CameraMoveCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
|
||||
#if PAL3
|
||||
if (true)
|
||||
#elif PAL3A
|
||||
if (command.Synchronous == 1)
|
||||
#endif
|
||||
{
|
||||
var waiter = new WaitUntilCanceled(this);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerWaitRequest(waiter));
|
||||
Vector3 position = GameBoxInterpreter.ToUnityPosition(new Vector3(command.X, command.Y, command.Z));
|
||||
StartCoroutine(Move(position, command.Duration, command.Mode, waiter));
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Vector3 position = GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position, command.Duration, (AnimationCurveType)command.CurveType, waiter));
|
||||
}
|
||||
#if PAL3A
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Vector3 position = GameBoxInterpreter.ToUnityPosition(new Vector3(command.X, command.Y, command.Z));
|
||||
StartCoroutine(Move(position,
|
||||
Vector3 position = GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position,
|
||||
command.Duration,
|
||||
command.Mode,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
waiter: null,
|
||||
_asyncCameraAnimationCts.Token));
|
||||
}
|
||||
@@ -709,8 +670,8 @@ namespace Pal3.Camera
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene() is not { } currentScene) return;
|
||||
|
||||
if (_gameStateManager.GetCurrentState() == GameState.Gameplay &&
|
||||
currentScene.GetSceneInfo().SceneType != ScnSceneType.StoryB)
|
||||
// Remember the current scene's camera position and rotation
|
||||
if (_cameraFollowPlayer && currentScene.GetSceneInfo().SceneType != ScnSceneType.InDoor)
|
||||
{
|
||||
var cameraTransform = _camera.transform;
|
||||
_cameraLastKnownSceneState.Add((
|
||||
@@ -722,18 +683,17 @@ namespace Pal3.Camera
|
||||
if (_cameraLastKnownSceneState.Count > LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH)
|
||||
{
|
||||
_cameraLastKnownSceneState.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Execute(ScenePreLoadingNotification notification)
|
||||
{
|
||||
_currentAppliedDefaultTransformOption = 0;
|
||||
ApplySceneSettings(notification.NewSceneInfo);
|
||||
|
||||
|
||||
// Apply the last known scene state if found in record.
|
||||
if (_gameStateManager.GetCurrentState() == GameState.Gameplay &&
|
||||
notification.NewSceneInfo.SceneType != ScnSceneType.StoryB)
|
||||
if (_cameraFollowPlayer && notification.NewSceneInfo.SceneType != ScnSceneType.InDoor)
|
||||
{
|
||||
if (_cameraLastKnownSceneState.Count > 0 && _cameraLastKnownSceneState.Any(_ =>
|
||||
_.sceneInfo.ModelEquals(notification.NewSceneInfo)))
|
||||
@@ -746,31 +706,142 @@ namespace Pal3.Camera
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Execute(CameraFocusOnActorCommand command)
|
||||
{
|
||||
if (command.ActorId == ActorConstants.PlayerActorVirtualID) return;
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
_lookAtGameObject = _sceneManager.GetCurrentScene().GetActorGameObject((byte)command.ActorId);
|
||||
_lookAtGameObject = _sceneManager.GetCurrentScene().GetActorGameObject(command.ActorId);
|
||||
}
|
||||
|
||||
public void Execute(CameraFocusOnSceneObjectCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
|
||||
_lookAtGameObject = _sceneManager.GetCurrentScene()
|
||||
.GetSceneObjectGameObject((byte)command.SceneObjectId);
|
||||
.GetSceneObject(command.SceneObjectId).GetGameObject();
|
||||
}
|
||||
|
||||
public void Execute(GameStateChangedNotification command)
|
||||
{
|
||||
if (command.NewState == GameState.Gameplay) _free = true;
|
||||
if (command.NewState == GameState.Gameplay)
|
||||
{
|
||||
_cameraFollowPlayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ResetGameStateCommand command)
|
||||
{
|
||||
_cameraLastKnownSceneState.Clear();
|
||||
_free = true;
|
||||
_cameraFollowPlayer = true;
|
||||
}
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(CameraOrbitHorizontalCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var oldDistance = _cameraOffset.magnitude;
|
||||
var newDistance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
var distanceDelta = newDistance - oldDistance;
|
||||
|
||||
if (command.Synchronous == 1)
|
||||
{
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation, command.Duration, (AnimationCurveType)command.CurveType, distanceDelta, waiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
waiter: null,
|
||||
_asyncCameraAnimationCts.Token));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(CameraOrbitVerticalCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var oldDistance = _cameraOffset.magnitude;
|
||||
var newDistance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
var distanceDelta = newDistance - oldDistance;
|
||||
|
||||
if (command.Synchronous == 1)
|
||||
{
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation, command.Duration, (AnimationCurveType)command.CurveType, distanceDelta, waiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
waiter: null,
|
||||
_asyncCameraAnimationCts.Token));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(CameraMoveToLookAtPointCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
_cameraFollowPlayer = false;
|
||||
const float duration = 1f;
|
||||
|
||||
if (command.Synchronous == 1)
|
||||
{
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Vector3 position = _cameraOffset + GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position, duration, AnimationCurveType.Sine, waiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Vector3 position = _cameraOffset + GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position,
|
||||
duration,
|
||||
AnimationCurveType.Sine,
|
||||
waiter: null,
|
||||
_asyncCameraAnimationCts.Token));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(CameraMoveToDefaultLookAtPointCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
|
||||
if (_gamePlayController.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
{
|
||||
Vector3 position = _cameraOffset + playerActorPosition;
|
||||
StartCoroutine(MoveAsync(position, command.Duration, AnimationCurveType.Sine, waiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
_cameraFollowPlayer = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Pal3.Command
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -35,16 +36,19 @@ namespace Pal3.Command
|
||||
/// </summary>
|
||||
public void Dispatch<T>(T command) where T : TCommand
|
||||
{
|
||||
var executed = false;
|
||||
foreach (var commandExecutor in _commandExecutorRegistry.GetRegisteredExecutors<T>())
|
||||
{
|
||||
commandExecutor.Execute(command);
|
||||
executed = true;
|
||||
}
|
||||
// Call ToList to prevent modified collection exception since a new executor may be registered during the iteration.
|
||||
var executors = _commandExecutorRegistry.GetRegisteredExecutors<T>().ToList();
|
||||
|
||||
if (!executed)
|
||||
if (executors.Any())
|
||||
{
|
||||
Debug.LogWarning($"No command executor found for command: {typeof(T).Name}");
|
||||
foreach (var executor in executors)
|
||||
{
|
||||
executor.Execute(command);
|
||||
}
|
||||
}
|
||||
else if (Attribute.GetCustomAttribute(typeof(T), typeof(SceCommandAttribute)) != null)
|
||||
{
|
||||
Debug.LogWarning($"No command executor found for sce command: {typeof(T).Name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,19 +59,22 @@ namespace Pal3.Command
|
||||
{
|
||||
Type commandExecutorType = typeof(ICommandExecutor<>).MakeGenericType(command.GetType());
|
||||
|
||||
var executed = false;
|
||||
foreach (var commandExecutor in _commandExecutorRegistry.GetRegisteredExecutors(commandExecutorType))
|
||||
// Call ToList to prevent modified collection exception since a new executor may be registered during the iteration.
|
||||
var executors = _commandExecutorRegistry.GetRegisteredExecutors(commandExecutorType).ToList();
|
||||
|
||||
if (executors.Any())
|
||||
{
|
||||
if (GetCommandExecutorExecuteMethod(commandExecutorType) is { } method)
|
||||
foreach (var executor in executors)
|
||||
{
|
||||
method.Invoke(commandExecutor, new object[] {command});
|
||||
executed = true;
|
||||
if (GetCommandExecutorExecuteMethod(commandExecutorType) is { } method)
|
||||
{
|
||||
method.Invoke(executor, new object[] {command});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!executed)
|
||||
else if (Attribute.GetCustomAttribute(command.GetType(), typeof(SceCommandAttribute)) != null)
|
||||
{
|
||||
Debug.LogWarning($"No command executor found for command: {command.GetType().Name}");
|
||||
Debug.LogWarning($"No command executor found for sce command: {command.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -23,11 +23,7 @@ namespace Pal3.Command
|
||||
|
||||
private CommandExecutorRegistry() { }
|
||||
|
||||
/// <summary>
|
||||
/// Register a ICommandExecutor instance.
|
||||
/// </summary>
|
||||
/// <param name="executor">ICommandExecutor instance</param>
|
||||
/// <typeparam name="T">TCommand instance type</typeparam>
|
||||
/// <inheritdoc />
|
||||
public void Register<T>(ICommandExecutor<T> executor) where T : TCommand
|
||||
{
|
||||
if (_executors.ContainsKey(typeof(ICommandExecutor<T>)))
|
||||
@@ -44,10 +40,7 @@ namespace Pal3.Command
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automatically register all ICommandExecutor types for the given instance.
|
||||
/// </summary>
|
||||
/// <param name="executor">ICommandExecutor instance</param>
|
||||
/// <inheritdoc />
|
||||
public void Register(object executor)
|
||||
{
|
||||
var executorTypes = executor.GetType().GetInterfaces()
|
||||
@@ -76,11 +69,7 @@ namespace Pal3.Command
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister a ICommandExecutor instance.
|
||||
/// </summary>
|
||||
/// <param name="executor">ICommandExecutor instance</param>
|
||||
/// <typeparam name="T">TCommand instance type</typeparam>
|
||||
/// <inheritdoc />
|
||||
public void UnRegister<T>(ICommandExecutor<T> executor) where T : TCommand
|
||||
{
|
||||
if (!_executors.ContainsKey(typeof(ICommandExecutor<T>)))
|
||||
@@ -95,10 +84,7 @@ namespace Pal3.Command
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automatically unregister all ICommandExecutor types for the given instance.
|
||||
/// </summary>
|
||||
/// <param name="executor">ICommandExecutor instance</param>
|
||||
/// <inheritdoc />
|
||||
public void UnRegister(object executor)
|
||||
{
|
||||
var executorTypes = executor.GetType().GetInterfaces()
|
||||
@@ -125,11 +111,7 @@ namespace Pal3.Command
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all registered ICommandExecutor based on ICommand instance type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">TCommand instance type</typeparam>
|
||||
/// <returns>ICommandExecutors</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<ICommandExecutor<T>> GetRegisteredExecutors<T>() where T : TCommand
|
||||
{
|
||||
Type handlerType = typeof(ICommandExecutor<T>);
|
||||
@@ -142,11 +124,7 @@ namespace Pal3.Command
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all registered ICommandExecutor based on TCommand instance type.
|
||||
/// using reflection
|
||||
/// </summary>
|
||||
/// <returns>ICommandExecutors</returns>
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<object> GetRegisteredExecutors(Type type)
|
||||
{
|
||||
if (!_executors.ContainsKey(type)) yield break;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -15,19 +15,17 @@ namespace Pal3.Command
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
Type type = command.GetType();
|
||||
|
||||
|
||||
builder.Append(type.Name[..^"Command".Length]);
|
||||
builder.Append(' ');
|
||||
|
||||
|
||||
foreach (PropertyInfo propertyInfo in type.GetProperties())
|
||||
{
|
||||
builder.Append(propertyInfo.GetValue(command));
|
||||
builder.Append(' ');
|
||||
}
|
||||
|
||||
var commandStr = builder.ToString();
|
||||
if (commandStr.EndsWith(' ')) commandStr = commandStr[..^1];
|
||||
return commandStr;
|
||||
return builder.ToString().TrimEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Command
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute for enabling the command in console.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class AvailableInConsoleAttribute : Attribute
|
||||
{
|
||||
public AvailableInConsoleAttribute() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5cca8f0dbf345c5942f679c78655715
|
||||
timeCreated: 1668320977
|
||||
Loaded 100 of 562 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user