Skip to content

Instantly share code, notes, and snippets.

@yaegaki
Last active August 29, 2015 14:15
Show Gist options
  • Save yaegaki/c24da3f4c7f477594969 to your computer and use it in GitHub Desktop.
Save yaegaki/c24da3f4c7f477594969 to your computer and use it in GitHub Desktop.
UniRxほげ
this.UpdateAsObservable()
.TakeUntil(this.UpdateAsObservable().Where(_ => Input.GetMouseButtonUp(0)))
.Scan(new List<Vector3>(), (list, _) =>
{
Debug.Log("Scan");
return list;
})
.Where(list =>
{
Debug.Log("Where");
var current = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (list.Count > 0)
{
if (Vector3.Distance(list[list.Count - 1], current) < .1f)
{
return false;
}
}
else
{
this.startPosition = current;
}
list.Add(current);
return true;
})
.Select(list => list[list.Count - 1])
.Subscribe(p =>
{
this.positions.Enqueue(p);
UpdateMeshAndCollider();
Observable.Timer(TimeSpan.FromMilliseconds(2000f))
.Subscribe(_ =>
{
this.positions.Dequeue();
UpdateMeshAndCollider();
Debug.Log(this);
Debug.Log(this.hoge);
});
},
() =>
{
});
var dragStream = this.UpdateAsObservable()
.TakeUntil(this.UpdateAsObservable().Select(_ => Input.GetMouseButtonUp(0)))
.Select(_ => Camera.main.ScreenToWorldPoint(Input.mousePosition));
dragStream
.Zip(dragStream.Skip(1), (prev, current) => Vector3.Distance(prev, current))
.Scan(0f, (acc, distance) =>
{
return acc += distance;
})
.Where(acc => acc >= 100)
.Subscribe(acc =>
{
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment