// Start is called before the first frame update void Start() { EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; //²éѯ EntityQuery entityQuery = entityManager.CreateEntityQuery(typeof(BufferComponent8)); NativeArray <Entity> entities = entityQuery.ToEntityArray(Allocator.TempJob); foreach (var entity in entities) { DynamicBuffer <BufferComponent8> dynamicbuffer = entityManager.GetBuffer <BufferComponent8>(entity); //ɾ³ý dynamicbuffer.RemoveAt(0); //²åÈë dynamicbuffer.Insert(0, new BufferComponent8() { data = 5, data2 = 6 }); var i = 0; foreach (var buffer in dynamicbuffer) { Debug.Log("EntityIndex: " + entity.Index + ", BufferIndex: " + i + ", data = " + buffer.data + ", data2 = " + buffer.data2); ++i; } } entities.Dispose(); }
private InputFieldCaretState ProcessInput(Entity inputFieldEntity, DynamicBuffer <KeyboardInputBuffer> inputBuffer, DynamicBuffer <TextData> textData, InputFieldCaretState caretState, int chunkIndex) { for (int i = 0; i < inputBuffer.Length; i++) { var key = inputBuffer[i]; if (key.EventType == KeyboardEventType.Key) { switch ((KeyCode)key.KeyCode) { case KeyCode.Backspace: if (caretState.CaretPosition > 0) { textData.RemoveAt(caretState.CaretPosition - 1); caretState.CaretPosition--; } break; case KeyCode.LeftArrow: caretState.CaretPosition = math.max(0, caretState.CaretPosition - 1); break; case KeyCode.RightArrow: caretState.CaretPosition = math.min(textData.Length, caretState.CaretPosition + 1); break; case KeyCode.Home: caretState.CaretPosition = 0; break; case KeyCode.End: caretState.CaretPosition = textData.Length; break; case KeyCode.Return: case KeyCode.KeypadEnter: CommandBuff.AddComponent(chunkIndex, inputFieldEntity, new InputFieldReturnEvent()); return(caretState); } } else { textData.Insert(caretState.CaretPosition, new TextData() { Value = key.Character }); caretState.CaretPosition++; } } return(caretState); }
private void AddAction(int chunkIndex, Entity entity, DynamicBuffer <Action> actions, int posToAdd, CurrentAction current, Action toAdd) { if (posToAdd == 0) // if the action was added at the start of the buffer //Debug.Log("Added to start!"); { if (current.type == ActionType.No_Action) { entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction { }); // tell the system that the current action should be changed } } else // //Debug.Log("Added after start"); { } // Add the action at the correct position actions.Insert(posToAdd, toAdd); }
private void ShowAdd() { DynamicBuffer <int> buffer = new DynamicBuffer <int>(); DynamicBuffer <int> secondBuffer = new DynamicBuffer <int>(); #region dynamicbuffer.add buffer.Add(5); #endregion #region dynamicbuffer.addrange int[] source = { 1, 2, 3, 4, 5 }; NativeArray <int> newElements = new NativeArray <int>(source, Allocator.Persistent); buffer.AddRange(newElements); #endregion #region dynamicbuffer.asnativearray int[] intArray = { 1, 2, 3, 4, 5 }; NativeArray <int> .Copy(intArray, buffer.AsNativeArray()); #endregion #region dynamicbuffer.capacity #endregion #region dynamicbuffer.clear buffer.Clear(); #endregion #region dynamicbuffer.copyfrom.dynamicbuffer buffer.CopyFrom(secondBuffer); #endregion #region dynamicbuffer.copyfrom.nativearray int[] sourceArray = { 1, 2, 3, 4, 5 }; NativeArray <int> nativeArray = new NativeArray <int>(source, Allocator.Persistent); buffer.CopyFrom(nativeArray); #endregion #region dynamicbuffer.copyfrom.nativeslice NativeSlice <int> nativeSlice = new NativeSlice <int>(nativeArray, 1, 3); buffer.CopyFrom(nativeSlice); #endregion #region dynamicbuffer.copyfrom.array int[] integerArray = { 1, 2, 3, 4, 5 }; buffer.CopyFrom(integerArray); #endregion #region dynamicbuffer.getenumerator foreach (var element in buffer) { //Use element... } #endregion #region dynamicbuffer.getunsafeptr #endregion int insertionIndex = 2; #region dynamicbuffer.insert if (insertionIndex < buffer.Length) { buffer.Insert(insertionIndex, 6); } #endregion #region dynamicbuffer.iscreated #endregion #region dynamicbuffer.length for (int i = 0; i < buffer.Length; i++) { buffer[i] = i * i; } #endregion #region dynamicbuffer.removeat if (insertionIndex < buffer.Length) { buffer.RemoveAt(insertionIndex); } #endregion int start = 1; #region dynamicbuffer.removerange buffer.RemoveRange(start, 5); #endregion #region dynamicbuffer.reserve buffer.EnsureCapacity(buffer.Capacity + 10); #endregion #region dynamicbuffer.resizeuninitialized buffer.ResizeUninitialized(buffer.Length + 10); #endregion #region dynamicbuffer.indexoperator for (int i = 0; i < buffer.Length; i++) { buffer[i] = i * i; } #endregion #region dynamicbuffer.tonativearray NativeArray <int> copy = buffer.ToNativeArray(Allocator.Persistent); #endregion #region dynamicbuffer.trimexcess if (buffer.Capacity > buffer.Length) { buffer.TrimExcess(); } #endregion }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { Entity[] holders = new Entity[3]; //Create a separate entity to hold the waypoint buffer for (int i = 0; i < 3; i++) { holders[i] = dstManager.CreateEntity(); //dstManager.SetName(holders[i], "Waypoint Holder " + i); DynamicBuffer <WayPoint> tempBuff = dstManager.AddBuffer <WayPoint>(holders[i]); if (i == 0) // if is the first entity, access the first position list { foreach (float3 location in positions1) //Add the waypoints { tempBuff.Add(new WayPoint { value = location }); } } else if (i == 1) // if is the second entity, access the second position list { foreach (float3 location in positions2) //Add the waypoints { tempBuff.Add(new WayPoint { value = location }); } } else // if is the third entity, access the third position list { foreach (float3 location in positions3) //Add the waypoints { tempBuff.Add(new WayPoint { value = location }); } } } DynamicBuffer <Action> dynamicBuffer = dstManager.AddBuffer <Action>(entity); // add a buffer to the entity //wpBuffer.Add(new WayPoint {point = float3.zero} ); for (int i = 0; i < priorites.Length; i++) { int curPriority = priorites[i]; //int curMessage = messages[i]; float curTime = times[i]; //find out where the new element should be added int pos = 0; //Debug.Log(i + " try, Length is: " + dynamicBuffer.Length); while (pos < dynamicBuffer.Length && curPriority <= dynamicBuffer[pos].priority) { if (curPriority == dynamicBuffer[pos].priority) // if the current priorities are the same //compare the times { if (curTime >= dynamicBuffer[pos].timeCreated) // if the current elements time is greater than the other element's time, this element should go later { pos++; } else { break; } } else if (curPriority < dynamicBuffer[pos].priority) // if this elements priority is smaller than the other element's priority, this element should go later { pos++; } else { break; } } //add the element at that location dynamicBuffer.Insert( pos, new Action { id = i, priority = priorites[i], type = ActionType.Follow_WayPoints, timeCreated = times[i], dataHolder = holders[i], }); // the Values (in the buffer) are the values in the array } }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { //Create a separate entity to hold the waypoint buffer Entity holder = dstManager.CreateEntity(); //dstManager.SetName(holder, "Waypoint Holder 1"); DynamicBuffer <WayPoint> tempBuff = dstManager.AddBuffer <WayPoint>(holder); foreach (float3 location in positions1) //Add the waypoints { tempBuff.Add(new WayPoint { value = location }); } dstManager.AddComponentData <FollowWayPointsStorage>(holder, new FollowWayPointsStorage { id = 0, curPointNum = 0 }); // add the FollowWayPointsAction to the crowd agent Entity holder2 = dstManager.CreateEntity(); //dstManager.SetName(holder2, "Waypoint Holder 2"); DynamicBuffer <WayPoint> tempBuff2 = dstManager.AddBuffer <WayPoint>(holder2); tempBuff2.Add(new WayPoint { value = new float3(0, 0, 0) }); dstManager.AddComponentData <FollowWayPointsStorage>(holder2, new FollowWayPointsStorage { id = 1, curPointNum = 0 }); // add the FollowWayPointsAction to the crowd agent*/ DynamicBuffer <Action> dynamicBuffer = dstManager.AddBuffer <Action>(entity); // add a buffer to the entity //wpBuffer.Add(new WayPoint {point = float3.zero} ); for (int i = 0; i < priorites.Length; i++) { int curPriority = priorites[i]; //int curMessage = messages[i]; float curTime = times[i]; //find out where the new element should be added int pos = 0; //Debug.Log(i + " try, Length is: " + dynamicBuffer.Length); while (pos < dynamicBuffer.Length && curPriority <= dynamicBuffer[pos].priority) { if (curPriority == dynamicBuffer[pos].priority) // if the current priorities are the same //compare the times { if (curTime >= dynamicBuffer[pos].timeCreated) // if the current elements time is greater than the other element's time, this element should go later { pos++; } else { break; } } else if (curPriority < dynamicBuffer[pos].priority) // if this elements priority is smaller than the other element's priority, this element should go later { pos++; } else { break; } } //add the element at that location if (i == 0) { dynamicBuffer.Insert( pos, new Action { id = i, priority = priorites[i], type = ActionType.Follow_WayPoints, timeCreated = times[i], dataHolder = holder, }); // the Values (in the buffer) are the values in the array } else if (i == 1) { dynamicBuffer.Insert( pos, new Action { id = i, priority = priorites[i], type = ActionType.Follow_WayPoints, timeCreated = times[i], dataHolder = holder2, }); // the Values (in the buffer) are the values in the array } } dstManager.AddComponentData <CurrentAction>(entity, new CurrentAction { id = 22, type = ActionType.Follow_WayPoints }); dstManager.AddComponentData <FollowWayPointsAction>(entity, new FollowWayPointsAction { id = 22, curPointNum = 0 }); DynamicBuffer <WayPoint> wpBuffer = dstManager.AddBuffer <WayPoint>(entity); // add a buffer to the entity wpBuffer.Add(new WayPoint { value = new float3(1, 1, 1) }); }
public static void Add(ref DynamicBuffer <ExternalEntityRef> buffer, ExternalEntityRef entityref) { int i = FindInsertionPoint(ref buffer, entityref); buffer.Insert(i, entityref); }