第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何創(chuàng)建模塊化類列表屬性

如何創(chuàng)建模塊化類列表屬性

PHP
冉冉說 2024-01-20 21:47:36
我可能問錯了問題,因為我在網(wǎng)上找不到任何關于此的信息......本質(zhì)上我的目標是在 project\Schemas\Move.cs 中定義一個移動類:public class Move{    private int power;    private float accuracy;    private string type;     private string style;     public Move(int p, float a, string t, string s, float sh)    {        this.power = p;        this.accuracy = a;        this.type = t;        this.style = s;    }}我希望可以從我的游戲引擎訪問所有動作的集合,但我希望根據(jù) project\Moves\move_* 下的其他文件自動構(gòu)建該動作集合。老實說,我不確定如何在 C# 中執(zhí)行此操作。在另一種語言中,我將簡單地初始化一個全局集合,并在每個移動文件中我只需調(diào)用GlobalCollection.Add(new Move(...))或類似的東西。希望有人可以幫助我!
查看完整描述

3 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

如果我正確理解你的意思,你正在嘗試擁有一個例如List<Move>,并且你想“注冊”Move這里創(chuàng)建的每個實例。那么為什么不簡單地像


// This is a static class so it does not have to be instantiated

// but rather simply "lives" in the assets

public static class MoveManager

{

    public static List<Move> Moves = new List<Move>();

}

那么你可以這樣


public class Move

{

    private int power;

    private float accuracy;

    private string type; 

    private string style;  


    public Move(int p, float a, string t, string s, float sh)

    {

        power = p;

        accuracy = a;

        type = t;

        style = s;


        // a static class member is simply accessed via the type itself

        MoveManager.Moves.Add(this);

    }

}

問題:什么時候?qū)⑺鼈儚牧斜碇袆h除?


通常你想在解構(gòu)函數(shù)中執(zhí)行此操作,例如


~Move()

{

    MoveManager.Moves.Remove(this);

}

但在 Unity 中,解構(gòu)函數(shù)不會自動調(diào)用 - 特別是當任何東西仍在引用此Move實例時......劇透警報:Moves列表總是可以的!Moves因此,如果需要,每次您確實想要銷毀實例時,都必須“手動”清理列表Move。


查看完整回答
反對 回復 2024-01-20
?
有只小跳蛙

TA貢獻1824條經(jīng)驗 獲得超8個贊

我正在使用建議的方法,但發(fā)現(xiàn)為了在運行時“導入”[RuntimeInitializeOnLoadMethod]必須設置使用的類型。可能還有其他方法,但這是我最終得到的用于完成答案的 3 個移動文件。


MoveManager.cs


?public static class MoveManager

?{

? ? public static List<Move> Moves = new List<Move>();

?}

移動.cs


public class Move

{

? ? public string name;

? ? public string description;

? ? public Target target;

? ? public int power;

? ? public float accuracy;

? ? public int cost;

? ? public game_Type type;

? ? public Style style;


? ? public Move(

? ? ? ? string name

? ? ? ? , string description

? ? ? ? , int power

? ? ? ? , float accuracy

? ? ? ? , int cost

? ? ? ? , string typeName

? ? ? ? , string styleName

? ? ? ? , string targetType

? ? )

? ? {

? ? ? ? this.name = name;

? ? ? ? this.power = power;

? ? ? ? this.accuracy = accuracy;

? ? ? ? this.description = description;


? ? ? ? this.type = game_Types.getByName(typeName);

? ? ? ? this.style = MasterStyles.getByName(styleName);

? ? ? ? this.target = new Target(targetType);


? ? ? ? // a static class member is simply accessed via the type itself

? ? ? ? Debug.Log("Registering " + name + " type!");

? ? ? ? MoveManager.Moves.Add(this);

? ? }

}

move_basic.cs


class move_basic

{

? ? [RuntimeInitializeOnLoadMethod]

? ? static void OnRuntimeMethodLoad()

? ? {

? ? ? ? // Name this move

? ? ? ? string name = "Attack!";

? ? ? ? // Describe this move

? ? ? ? string description = "Strike out at the enemy with tooth, claw, weapon, or whatever else is available!";

? ? ? ? // Choose the type of target this move is for

? ? ? ? // self/ally/selfAlly/enemy/enemies

? ? ? ? string target = "enemy";

? ? ? ? // The move typing - This determines cost reduction as well as potential attack bonuses

? ? ? ? string typeName = "physical";

? ? ? ? game_Type type = game_Types.Types.Find(x => x.name == typeName);

? ? ? ? // The move style - This determines additional bonuses and modifiers

? ? ? ? string styleName = "martial";

? ? ? ? // Style style = ??

? ? ? ? // Power of the move, base/'normal' power is 50.

? ? ? ? int power = 50;

? ? ? ? // Accuracy of the move, base/normal is 90

? ? ? ? int accuracy = 90;

? ? ? ? // MP Cost of the move

? ? ? ? int cost = 0;



? ? ? ? Move mv = new Move(name, description, power, accuracy, cost, typeName, styleName, target);

? ? }

}

既然我已經(jīng)確認這項工作有效,下一步就是向注冊的動作添加方法,這才是真正的魔力所在。


當您需要創(chuàng)建一個易于擴展的對象庫(可能需要包含可調(diào)用方法)時,這似乎是一個非常理想的解決方案。如果不是出于這種需要,從 csv 或其他東西導入屬性可能會更好。


一般來說,我對統(tǒng)一和游戲設計還很陌生,所以我非常高興編輯/更正/改進這篇文章以幫助未來的搜索者。


查看完整回答
反對 回復 2024-01-20
?
慕尼黑8549860

TA貢獻1818條經(jīng)驗 獲得超11個贊

沒有(好的)方法可以做你想做的事。

選項1:

自己親手寫出來。例如,就像我在這里所做的那樣。這總是有效的,并且是您要努力避免的事情。

選項2:

反思性地檢查程序集并加載它包含的所有類,如下所示。但這很容易出現(xiàn)意想不到的事情。例如,當您創(chuàng)建獨立構(gòu)建時,Unity 會剔除這些類,以免它們被編譯,因為它們在任何地方都沒有被引用?;蛘邿o意中實例化了一個不應該實例化的對象?;蛘邲]有記住“哦,是的,MoveXYZ 有一個獨特的構(gòu)造函數(shù),需要一個額外的參數(shù)。”


查看完整回答
反對 回復 2024-01-20
  • 3 回答
  • 0 關注
  • 239 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號