/// <summary> /// Creates a deep clone of this repeated field. /// </summary> /// <remarks> /// If the field type is /// a message type, each element is also cloned; otherwise, it is /// assumed that the field type is primitive (including string and /// bytes, both of which are immutable) and so a simple copy is /// equivalent to a deep clone. /// </remarks> /// <returns>A deep clone of this repeated field.</returns> public RepeatedField <T> Clone() { int len = Count; if (len > 0) { bool isDeepCloner = base[0] is IDeepCloneable <T>; RepeatedField <T> clone = new RepeatedField <T>(len); if (isDeepCloner) { for (int i = 0; i < len; i++) { IDeepCloneable <T> item = base[i] as IDeepCloneable <T>; if (item != null) { clone.Add(item.Clone()); } else { clone.Add(base[i]); } } } else { for (int i = 0; i < len; i++) { clone.Add(base[i]); } } return(clone); } return(new RepeatedField <T>()); }
static void collect_child_collider_data(GameObject go, Vector3 pos, Quaternion rot, Vector3 scale, Google.Protobuf.Collections.RepeatedField <Arenadata.Collider> sink) { var colliders = go.GetComponents <Collider>(); if (colliders != null && colliders.Length > 0) { if (colliders.Length == 1) //There are only one collider. So there can be child colliders { var data = create_collider_data(pos, rot, scale, colliders[0]); sink.Add(data); collect_child_collider_data_iterate(go, scale, data.Children); } else //There are multiple colliders on one game object. So there can not be any child colliders { foreach (var collider in colliders) { var data = create_collider_data(pos, rot, scale, collider); sink.Add(data); } check_no_child_colliders(go); } } else //There are no colliders, just iterate down { collect_child_collider_data_iterate(go, scale, sink); } }
public override void Initialize(ServerWindowOpenMessage msg) { // elements elements = new Google.Protobuf.Collections.RepeatedField <Org.Dragonet.Cloudland.Net.Protocol.GUIElement>(); inventoryElem.Type = GUIElementType.Inventory; inventoryElem.Value = new SerializedMetadata(); UpdateItems(); inventoryElem.X = 32; inventoryElem.Y = 32; inventoryElem.Width = 500 - 64; inventoryElem.Height = 400 - 64; elements.Add(inventoryElem); craftingInputElem.Type = GUIElementType.Inventory; craftingInputElem.Value = new SerializedMetadata(); UpdateCraftingInputs(); craftingInputElem.X = 500; craftingInputElem.Y = 80; craftingInputElem.Width = 110; craftingInputElem.Height = 110; elements.Add(craftingInputElem); craftingOutputElem.Type = GUIElementType.Inventory; craftingOutputElem.Value = new SerializedMetadata(); UpdateCraftingOutput(); craftingOutputElem.X = 650; craftingOutputElem.Y = 100; craftingOutputElem.Width = 64; craftingOutputElem.Height = 64; elements.Add(craftingOutputElem); rect = new UnityEngine.Rect(UnityEngine.Screen.width / 2 - 400, UnityEngine.Screen.height / 2 - 240, 800, 480); title = "Inventory"; }
public void NullValuesRejected() { var list = new RepeatedField <string>(); Assert.Throws <ArgumentNullException>(() => list.Add((string)null)); Assert.Throws <ArgumentNullException>(() => list.Add((IEnumerable <string>)null)); Assert.Throws <ArgumentNullException>(() => list.Add((RepeatedField <string>)null)); Assert.Throws <ArgumentNullException>(() => list.Contains(null)); Assert.Throws <ArgumentNullException>(() => list.IndexOf(null)); }
/// <summary> /// Callback for start session subscription /// </summary> /// <param name="record"></param> public async void OnStartSession(TopicDataRecord record) { List <ProcessingModule> localPMs = new List <ProcessingModule>(); foreach (Ubii.Processing.ProcessingModule pm in record.Session.ProcessingModules) { if (pm.NodeId == this.GetID()) { //Debug.Log("UbiiNode.OnStartSession() - applicable pm: " + pm); ProcessingModule newModule = this.processingModuleManager.CreateModule(pm); //Debug.Log("UbiiNode.OnStartSession() - created instance: " + newModule.ToString()); if (newModule != null) { localPMs.Add(newModule); } } } Google.Protobuf.Collections.RepeatedField <Ubii.Processing.ProcessingModule> elements = new Google.Protobuf.Collections.RepeatedField <Ubii.Processing.ProcessingModule>(); foreach (ProcessingModule pm in localPMs) { elements.Add(pm.ToProtobuf()); } ServiceRequest pmRuntimeAddRequest = new ServiceRequest { Topic = UbiiConstants.Instance.DEFAULT_TOPICS.SERVICES.PM_RUNTIME_ADD, ProcessingModuleList = new Ubii.Processing.ProcessingModuleList { Elements = { elements } } }; //Debug.Log(nameof(OnStartSession) + " - runtime add request: " + pmRuntimeAddRequest); ServiceReply reply = await CallService(pmRuntimeAddRequest); //Debug.Log("start session runtime add PMs reply: " + reply); if (reply.Success != null) { try { bool success = await this.processingModuleManager.ApplyIOMappings(record.Session.IoMappings, record.Session.Id); foreach (var pm in localPMs) { this.processingModuleManager.StartModule(new Ubii.Processing.ProcessingModule { Id = pm.Id }); } } catch (Exception e) { Debug.LogError(e.ToString()); } } else { //TODO: delete modules } }
public void Add_SingleItem() { var list = new RepeatedField <string>(); list.Add("foo"); Assert.AreEqual(1, list.Count); Assert.AreEqual("foo", list[0]); }
public void IList_Add() { IList list = new RepeatedField <string> { "first", "second" }; list.Add("third"); CollectionAssert.AreEqual(new[] { "first", "second", "third" }, list); }
public void Add_Sequence() { var list = new RepeatedField <string>(); list.Add(new[] { "foo", "bar" }); Assert.AreEqual(2, list.Count); Assert.AreEqual("foo", list[0]); Assert.AreEqual("bar", list[1]); }
public void Add_RepeatedField() { var list = new RepeatedField <string> { "original" }; list.Add(new RepeatedField <string> { "foo", "bar" }); Assert.AreEqual(3, list.Count); Assert.AreEqual("original", list[0]); Assert.AreEqual("foo", list[1]); Assert.AreEqual("bar", list[2]); }