了解 Auki 网络和代币经济的基本原理
在 Auki 网络的支持下,获取自己的领域。
深入了解Auki网络白皮书的细节
在Uniswap DEX上交易$AUKI
在MEXC CEX上交易$AUKI
在Aerodrome DEX上交易$AUKI
实时跟踪 Auki 网络的网络状况。
See how the Auki network is empowering robot fleets.
See how the Auki network is enabling AI.
See how the Auki network is enabling XR experiences.
使用ConjureKit,构建第一代社交增强现实体验。
申请高达 100,000 美元 Auki 代币的开发者补助金
了解如何在 posemesh 上使用我们的 SDK 构建应用程序。
所有 ConjureKit SDK 文档和支援。
了解 Cactus 如何提高零售效率。
了解 Gotu 如何协助物业经理工作。
了解 Gotu 导航如何提升您的活动体验。
零售行业的空间人工智能平台。
为活动和物业提供室内导航。
家庭和展览装饰应用。
通过这个同时多人共享的AR体验,让您大获全胜。
看看谁在与Auki一起搭建 posemesh。
深入了解我们的理念。
加入 Discord 对话。
通过 X 随时了解 Auki 社区的最新动态。
Stay up to date with the Auki community on X.
关于 Auki 和 posemesh 的常见问题。
我们的新闻稿、媒体资料工具包和联系方式。
Let's now learn how to get and set data on a component using a system.
The component data is a ^byte[]^, and it's up to the developer to decide what data to store and how. Create two methods to convert ^Color^ to ^byte[]^ and vice versa;
byte[]^
Color^
// Convert Color32 to byte array private byte[] ColorToByteArray(Color32 color) { byte[] colorBytes = new byte[4]; colorBytes[0] = color.r; colorBytes[1] = color.g; colorBytes[2] = color.b; colorBytes[3] = color.a; return colorBytes; } // Convert byte array to Color32 public Color32 ByteArrayToColor(byte[] bytes) { if (bytes.Length < 4) { Debug.LogError("Byte array must have at least 4 elements (R, G, B, A)."); return Color.clear; } byte r = bytes[0]; byte g = bytes[1]; byte b = bytes[2]; byte a = bytes[3]; Color32 color = new Color32(r, g, b, a); return color; }
Now create a ^SetColor^ method that will update the component with the new color locally and broadcast the update to all the other participants. We'll need to first verify that an entity with the given id exists. If the entity exists but doesn't yet have the ^color^ component, add a new one.
SetColor^
color^
public bool SetColor(uint entityId, Color color) { // Check if the entity with the given id exists var entity = _session.GetEntity(entityId); if (entity == null) return false; // Store the data locally _entityColorDataMap[entityId] = color; // If the entity doesn't already have Color component add one var component = _session.GetEntityComponent(entityId, COLOR_COMPONENT_NAME); if (component == null) { _session.AddComponent( COLOR_COMPONENT_NAME, entityId, ColorToByteArray(color), () => {}, error => Debug.LogError(error) ); return true; } else { return _session.UpdateComponent( COLOR_COMPONENT_NAME, entityId, ColorToByteArray(color) ); } }
Create a ^GetColor^ method that will return the locally stored value or a default one if the component or the entity doesn't exist.
GetColor^
public Color GetColor(uint entityId) { if (_session.GetEntity(entityId) == null || !_entityColorDataMap.ContainsKey(entityId)) return Color.clear; return _entityColorDataMap[entityId]; }
Override the Delete method that will be called by ConjureKit when other participants remove a component from an entity and a ^DeleteColor^ method to delete the color locally.
DeleteColor
public override void Delete(IReadOnlyList<(EntityComponent component, bool localChange)> deleted) { foreach (var (entityComponent, localChange) in deleted) { var entity = _session.GetEntity(entityComponent.EntityId); if (entity == null) continue; _entityColorDataMap.Remove(entity.Id); } }
In this tutorial, we are not going to use the delete functionality, but it is necessary to override the ^Delete^ method. You can later implement a public ^DeleteColor^ method that can be called to remove a color component from an entity.
Delete^
DeleteColor^
public void DeleteColor(uint entityId) { _session.DeleteComponent(COLOR_COMPONENT_NAME, entityId, () => { _entityColorDataMap.Remove(entityId); }); }
In the ^ConjureKitManager^ class, declare a ^ColorSystem^ and a Dictionary to store the cubes.
ConjureKitManager^
ColorSystem^
private ColorSystem _colorSystem; private Dictionary<uint, Renderer> _cubes = new Dictionary<uint, Renderer>();
In ^Conjurekit.Onjoined^ callback, register the color system to the joining participant
_conjureKit.OnJoined += session => { sessionID.text = session.Id.ToString(); !! _colorSystem = new ColorSystem(session); session.RegisterSystem(_colorSystem, () => Debug.Log("System registered in session")); _colorSystem.OnColorComponentUpdated += OnColorComponentUpdated; !! };
Create a method that will change the cube's color when its component is updated.
private void OnColorComponentUpdated(uint entityId, Color color) { _cubes[entityId].material.color = color; }
Simplify the ^TouchableByHand^ class to stop updating the color locally and instead trigger an event when the cube is touched.
TouchableByHand^
public class TouchableByHand : MonoBehaviour { public event Action OnTouched; private void OnTriggerEnter(Collider other) { if (other.CompareTag("hand")) { OnTouched?.Invoke(); } } }
Update the ^CreateCubeEntity^ and the ^CreateCube^ methods to initialize a cube with white color and update with random color when touched.
CreateCubeEntity^
CreateCube^
public void CreateCubeEntity() { if (_conjureKit.GetState() != State.Calibrated) return; Vector3 position = arCamera.transform.position + arCamera.transform.forward * 0.5f; Quaternion rotation = Quaternion.Euler(0, arCamera.transform.eulerAngles.y, 0); Pose entityPos = new Pose(position, rotation); _conjureKit.GetSession().AddEntity( entityPos, onComplete: entity => { !! // Initialize with white color _colorSystem.SetColor(entity.Id, Color.white); !! CreateCube(entity); }, onError: error => Debug.Log(error)); } private void CreateCube(Entity entity) { if (entity.Flag == EntityFlag.EntityFlagParticipantEntity) return; var pose = _conjureKit.GetSession().GetEntityPose(entity); var touchableCube = Instantiate(cube, pose.position, pose.rotation).GetComponent<TouchableByHand>(); !! _cubes[entity.Id] = touchableCube.GetComponent<Renderer>(); _cubes[entity.Id].material.color = _colorSystem.GetColor(entity.Id); touchableCube.OnTouched += () => { _colorSystem.SetColor(entity.Id, Random.ColorHSV()); _cubes[entity.Id].material.color = _colorSystem.GetColor(entity.Id); }; !! }
Build and run on two or more devices, and you should see cubes with shared colors.
申请 AUKI 代币补助金以启动您的项目,并直接与 Auki Labs 团队合作,将您的创意推向市场。成功申请者可获得价值高达 10 万美元的 AUKI 代币,以及 Auki Labs 团队提供的开发和营销支持。