public bool ShuffleIn(ICardModel card) { if (Maxxed.Value) { return(false); } var index = Math.RandomRanged(0, _Cards.Count); _Cards.Insert(index, card); return(true); }
private void UpdateQueue() { if (_items.Count >= 8) { _items.RemoveAt(_items.Count - 1); } while (_items.Count < 8) { _items.Insert(0, new HackerPacketQueueItem() { Colour = (HackerPacketQueueItemColour)UnityEngine.Random.Range(0, 3), Type = HackerPacketQueueItemType.Type1 }); } }
private void PieceAdded(CollectionAddEvent <IPieceModel> add) { var pieceAgent = Registry.Get <IPieceAgent>(add.Value); pieceAgent.SetOwner(add.Value.Owner.Value); _pieces.Insert(add.Index, pieceAgent); }
void Start() { data.Reset(Enumerable.Range(0, 5).Select(_ => Random.Range(0, 20))); insertButton.ClickStream().Listen(() => data.Insert(Random.Range(0, data.current.Count), Random.Range(0, 20))); removeButton.ClickStream().Listen(() => { if (data.current.Count > 0) { data.RemoveAt(Random.Range(0, data.current.Count)); } }); TableLayoutSettings settings = new TableLayoutSettings { direction = LayoutDirection.Horizontal, margin = 30, topShift = 30, bottomShift = 30, }; Action <int, SimpleView> factory = (i, view) => { view.name.text = i.ToString(); }; addConnection = Rui.PresentInScrollWithReusableViews(initial, data, prefab, settings, factory, delegates: Animations.Default <SimpleView>()); var mappedData = data.Map(val => (val * 3 + 5) % 10); addConnection = Rui.PresentInScrollWithReusableViews(mapped, mappedData, prefab, settings, factory, delegates: Animations.Default <SimpleView>()); var filteredData = mappedData.Filter(val => val % 2 == 0); addConnection = Rui.PresentInScrollWithReusableViews(filtered, filteredData, prefab, settings, factory, delegates: Animations.Default <SimpleView>()); }
public void Insert(int index, Line child) { Line oldParent = child.parent_; if (oldParent == this) { children_.Move(child.Index, index); } else { children_.Insert(index, child); child.Tree = Tree; child.parent_ = this; if (oldParent != null) { oldParent.children_.Remove(child); } } child.OnFoundParent(); if (child.Tree is LogTree == false) { foreach (string tag in child.Tags) { bool add = (child.IsDone == false); TagParent tagParent = GameContext.TagList.GetTagParent(tag); if (tagParent == null) { // Doneしてないタグなら生成する if (add) { tagParent = GameContext.TagList.InstantiateTagParent(tag); } } else { // DoneしててもRepeatなら追加してよい add |= tagParent.IsRepeat; } add &= tagParent != null && tagParent.FindBindedLine(child) == null; if (add) { tagParent.InstantiateTaggedLine(child); } } if (child.Field != null) { child.Field.SetHashTags(child.tags_); } } }
public AppShellViewModel() { var desktopManager = new DesktopManager().AddTo(this); var processManager = new WindowManager().AddTo(this); _desktopWindowManager = new DesktopWindowManager().AddTo(this); Title = new ReactiveProperty <string>("Robock"); Status = StatusTextService.Instance.ObserveProperty(w => w.Status).ToReactiveProperty(); Status.Throttle(TimeSpan.FromSeconds(30)).Subscribe(_ => StatusTextService.Instance.Status = "Ready").AddTo(this); Tabs = new ReactiveCollection <TabViewModel> { new AboutTabViewModel() }; Tabs.ToCollectionChanged().Subscribe(w => { if (!(w.Value is DesktopViewModel model) || !model.IsPrimary) { return; } VirtualScreen.SelectedIndex.Value = w.Index; model.IsSelected.Value = true; }); VirtualScreen = new VirtualScreenViewModel(); // Subscribe desktopManager.Desktops.CollectionChangedAsObservable().Subscribe(w => { if (w.Action != NotifyCollectionChangedAction.Add || !(w.NewItems[0] is Desktop desktop)) { return; } var viewModel = new DesktopViewModel(desktop, processManager, _desktopWindowManager).AddTo(this); Tabs.Insert(desktop.No - 1, viewModel); VirtualScreen.Desktops.Insert(desktop.No - 1, viewModel); }).AddTo(this); desktopManager.Initialize(); processManager.Start(); }
IEnumerator TestRemove() { Func <int> random = () => UnityEngine.Random.Range(0, data.current.Count); Action removeRandom = () => data.RemoveAt(random()); Action insertRandom = () => { var i = random(); data.Insert(i, new Cell <int>(i)); }; Action correct = () => { data.current.ForeachWithIndices((item, i) => item.value = i); PrintCollection(); }; const float mult = 4f; while (true) { removeRandom(); correct(); yield return(new WaitForSeconds(0.5f * mult)); insertRandom(); correct(); yield return(new WaitForSeconds(0.5f * mult)); insertRandom(); insertRandom(); insertRandom(); correct(); yield return(new WaitForSeconds(0.5f * mult)); removeRandom(); removeRandom(); removeRandom(); correct(); } }
public void IListSmokeTest() { var fixture = new ReactiveCollection <string>() as IList; Assert.NotNull(fixture); var pos = fixture.Add("foo"); Assert.Equal(0, pos); Assert.Equal(1, fixture.Count); Assert.True(fixture.Contains("foo")); fixture.Insert(0, "bar"); Assert.Equal(0, fixture.IndexOf("bar")); Assert.Equal(1, fixture.IndexOf("foo")); Assert.Equal("bar", fixture[0] as string); Assert.Equal("foo", fixture[1] as string); var arr = new string[2]; fixture.CopyTo(arr, 0); Assert.Equal(2, arr.Length); Assert.Equal("bar", arr[0]); Assert.Equal("foo", arr[1]); fixture[1] = "baz"; Assert.Equal(1, fixture.IndexOf("baz")); Assert.Equal(-1, fixture.IndexOf("foo")); Assert.Equal("baz", fixture[1] as string); Assert.False(fixture.Contains("foo")); Assert.True(fixture.Contains("baz")); fixture.Remove("bar"); Assert.Equal(1, fixture.Count); Assert.False(fixture.Contains("bar")); }
public void IListTSmokeTest() { var fixture = new ReactiveCollection <string>() as IList <string>; Assert.NotNull(fixture); fixture.Add("foo"); Assert.Equal(1, fixture.Count); Assert.True(fixture.Contains("foo")); fixture.Insert(0, "bar"); Assert.Equal(0, fixture.IndexOf("bar")); Assert.Equal(1, fixture.IndexOf("foo")); Assert.Equal("bar", fixture[0]); Assert.Equal("foo", fixture[1]); var genericEnum = ((IEnumerable <string>)fixture).GetEnumerator(); Assert.NotNull(genericEnum); bool result = genericEnum.MoveNext(); Assert.True(result); Assert.Equal("bar", genericEnum.Current); result = genericEnum.MoveNext(); Assert.True(result); Assert.Equal("foo", genericEnum.Current); result = genericEnum.MoveNext(); Assert.False(result); var plainEnum = ((IEnumerable)fixture).GetEnumerator(); Assert.NotNull(plainEnum); result = plainEnum.MoveNext(); Assert.True(result); Assert.Equal("bar", plainEnum.Current as string); result = plainEnum.MoveNext(); Assert.True(result); Assert.Equal("foo", plainEnum.Current as string); result = plainEnum.MoveNext(); Assert.False(result); var arr = new string[2]; fixture.CopyTo(arr, 0); Assert.Equal(2, arr.Length); Assert.Equal("bar", arr[0]); Assert.Equal("foo", arr[1]); fixture[1] = "baz"; Assert.Equal(1, fixture.IndexOf("baz")); Assert.Equal(-1, fixture.IndexOf("foo")); Assert.Equal("baz", fixture[1]); Assert.False(fixture.Contains("foo")); Assert.True(fixture.Contains("baz")); fixture.RemoveAt(1); Assert.False(fixture.Contains("baz")); fixture.Remove("bar"); Assert.Equal(0, fixture.Count); Assert.False(fixture.Contains("bar")); }
//Insertに対応 public Component(ReactiveCollection <Component> collection, int index) : this() { collection.Insert(index, this); }
private void Add(CollectionAddEvent<ICardModel> add) { Verbose(6, $"DeckAgent: Add {add.Value} @{add.Index}"); _cards.Insert(add.Index, Registry.Get<ICardAgent>(add.Value)); }
public override void OnGUI(Rect rect) { scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos); for (int i = 0; i < rc.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.MaxWidth(30)); T e = rc [i]; string tempJson = JsonConvert.SerializeObject(e); string tempJson2 = EditorGUILayout.DelayedTextField(tempJson); if (tempJson != tempJson2) { rc [i] = JsonConvert.DeserializeObject <T> (tempJson2); parent.VMCopyToJson(); } if (GUILayout.Button("-", GUILayout.MaxWidth(20))) { rc.RemoveAt(i); parent.VMCopyToJson(); break; } if (GUILayout.Button("+", GUILayout.MaxWidth(20))) { rc.Insert(i, PE); parent.VMCopyToJson(); break; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("NEW", GUILayout.MaxWidth(30)); string PEJson = JsonConvert.SerializeObject(PE); PEJson = EditorGUILayout.DelayedTextField(PEJson); PE = JsonConvert.DeserializeObject <T> (PEJson); if (GUILayout.Button("+", GUILayout.MaxWidth(40))) { rc.Add(PE); (parent as IElementEditor).VMCopyToJson(); } EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Json")) { PRDebug.TagLog("ReactiveDictionary", new Color(.2f, .2f, 1f), JsonConvert.SerializeObject(rc, Formatting.Indented)); } if (GUILayout.Button("Clear")) { rc.Clear(); this.editorWindow.Close(); parent.VMCopyToJson(); GUI.changed = true; } if (GUILayout.Button("Close")) { this.editorWindow.Close(); } EditorGUILayout.EndScrollView(); }
private void Add(CollectionAddEvent <ICardAgent> add) { Verbose(5, $"HandView: Add {add.Value} @{add.Index}"); _cards.Insert(add.Index, CreateViewFromAgent(add.Value)); Redraw(); }