简体   繁体   中英

Question about data access control in game programming with ECS (Entity-Component-System)

We're developing a game with ECS (Entity-Component-System).

Because all data stored in components are public, so everyone can access them easily. Sometimes somebody modify the data by mistake, which cause a bug that is hard to find it.

I want to make a tool to restrict access and then a system can only access some fixed components. How can I do this?

I think that for Unity dev activities most of the values are usually left open and easily changeable. If you have something that needs to be public within your C# but not visible from the Unity Editor, define it as a

public var {get;set;}

If you need to further restrict within Unity, define your variable as a

public var {get; private set;}

If you really need further protection, break the values into an accessor and backing variable, ie:

var _x;
public var X
{
  get {return _x;}
  set {
      if( valueAllowedToBeWritten)
        _x = value;
      }

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM