跳到主要内容

Network Properties Sync

Description

NetworkPropertiesSync 组件将为 NetworkGameObject 提供属性。如对象的健康状况、等级、名称等。

Properties

NameTypeDescription
GetHealthInt Currententity health value
GetObjectLevelIntCurrent entity level value
GetObjectNameStringCurrent entity name value
GetCustomPropertiesStringCurrent entity custom properties value

Events

注册一个回调事件来监听数值的变化。

public Action<float, NetworkIdentity> HealthSyncedCallback;
public Action<int, NetworkIdentity> ObjectLevelSyncedCallback;
public Action<string, NetworkIdentity> ObjectNameSyncedCallback;
public Action<string, NetworkIdentity> CustomPropertiesSyncedCallback;

Methods

CmdSubtractHealth

Description

改变实体健康值。您可以注册健康值变化事件来监听值的变化。

public void CmdSubtractHealth(int _newValue,NetworkIdentity _sender)

Parameters

ConnectionTypeDescription
_newValueIntThe value of health to be subtracted
_senderNetworkIdentityThe sender of the operation. e.g. Player attack to enemy, the sender is player

CmdAddHealth

public void CmdAddHealth(int _newValue,NetworkIdentity _sender)

Description

改变实体健康值并同步到所有用户。

Parameters

ConnectionTypeDescription
_newValueIntThe value of health to be subtracted
_senderNetworkIdentityThe sender of the operation. e.g. Player attack to enemy, the sender is player

Event

开发者可以注册健康值变化事件来监听值的变化。

public Action<float, NetworkIdentity> HealthSyncedCallback;

Example

Getcomponent<NetworkPropertiesSync>().HealthSyncedCallback += (_health,_sender)=>{
//TODO: YOUR Logic code here
}

CmdLevelUp

public void CmdLevelUp(int _additionLevel,NetworkIdentity _sender)

Description

改变实体级别的值并同步到所有用户。

Parameters

ConnectionTypeDescription
_additionLevelIntThe value of level to be up
_senderNetworkIdentityThe sender of the operation. e.g. Player attack to enemy, the sender is player

Event

开发者可以注册Level值变化事件来监听值的变化。

public Action<float, NetworkIdentity> ObjectLevelSyncedCallback;

Example

Getcomponent<NetworkPropertiesSync>().ObjectLevelSyncedCallback += (_level_,_sender)=>{
//TODO: YOUR Logic code here
}

CmdDegradeLevel

public void CmdDegradeLevel(int _level, NetworkIdentity _sender)

Description

改变实体的级别值。您可以注册级别值变化事件来监听值的变化。

Parameters

ConnectionTypeDescription
_levelIntThe value of level to be degrade
_senderNetworkIdentityThe sender of the operation. e.g. Player attack to enemy, the sender is player

Event

Developer can register for Level value change event to listen for value changes.

public Action<float, NetworkIdentity> ObjectLevelSyncedCallback;

Example

Getcomponent<NetworkPropertiesSync>().ObjectLevelSyncedCallback += (_level_,_sender)=>{
//TODO: YOUR Logic code here
}

CmdSetObjectName

public void CmdSetObjectName(string _name,NetworkIdentity _sender)

Description

命名您的游戏对象并同步到所有用户。

Parameters

ConnectionTypeDescription
_namestringThe value of name to set.
_senderNetworkIdentityThe sender of the operation. e.g. Player attack to enemy, the sender is player

Event

Developer can register for name value change event to listen for value changes.

public Action<float, NetworkIdentity> ObjectNameSyncedCallback;

Example

Getcomponent<NetworkPropertiesSync>().ObjectNameSyncedCallback += (_name_,_sender)=>{
//TODO: YOUR Logic code here
}

CmdUpdateCustomProperties

public void CmdUpdateCustomProperties(string _customProperties,NetworkIdentity _sender)

Description

In addition to the above Properties, additional Properties can be added and sync to all user.

Parameters

ConnectionTypeDescription
_customPropertiesIntIncoming custom properties value
_senderNetworkIdentityThe sender of the operation

Event

开发者可以注册自定义数据变化事件来监听值的变化。

public Action<string, NetworkIdentity> CustomPropertiesSyncedCallback;

Example

Getcomponent<NetworkPropertiesSync>().CustomPropertiesSyncedCallback += (_customdata,_sender)=>{
//TODO: YOUR Logic code here
}