浏览代码

Created IEnumerable extension for zipping together enumerables

(so that we can easily iterate over 2 collections using their
IEnumerable interface, rather than having to index into one of them)
/main
Peter Bay Bastian 8 年前
当前提交
fa8baa2c
共有 5 个文件被更改,包括 84 次插入6 次删除
  1. 13
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs
  2. 25
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/EnumerableExtensions.cs
  3. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/EnumerableExtensions.cs.meta
  4. 28
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/ValueTuple.cs
  5. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/ValueTuple.cs.meta

13
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs


using RMGUI.GraphView;
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleSheets;
using System.Linq;
using UnityEditor.Graphing.Util;
using System;
namespace UnityEditor.Graphing.Drawing
{

void UpdateContainer(VisualContainer container, IEnumerable<TitleBarButtonDrawData> itemDatas)
{
// The number of items can't change for now.
int i = 0;
foreach (var itemData in itemDatas)
foreach (var pair in itemDatas.Zip(container.children.OfType<TitleBarButtonDrawer>()))
var item = container.GetChildAtIndex(i) as TitleBarButtonDrawer;
if (item != null)
item.dataProvider = itemData;
i++;
var itemData = pair.Item1;
var item = pair.Item2;
item.dataProvider = itemData;
}
}

25
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/EnumerableExtensions.cs


using System;
using System.Collections;
using System.Collections.Generic;
namespace UnityEditor.Graphing.Util
{
public static class EnumerableExtensions
{
public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
{
var e1 = first.GetEnumerator();
var e2 = second.GetEnumerator();
while (e1.MoveNext() && e2.MoveNext())
{
yield return resultSelector(e1.Current, e2.Current);
}
}
public static IEnumerable<ValueTuple<TFirst, TSecond>> Zip<TFirst, TSecond>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second)
{
return first.Zip(second, ValueTuple.Create);
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/EnumerableExtensions.cs.meta


fileFormatVersion: 2
guid: 3042c033e57ba45458680f0259feca30
timeCreated: 1481279276
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

28
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/ValueTuple.cs


using System;
namespace UnityEditor.Graphing.Util
{
public struct ValueTuple<T1, T2>
{
public T1 Item1 { get; set; }
public T2 Item2 { get; set; }
public ValueTuple(T1 item1, T2 item2)
{
Item1 = item1;
Item2 = item2;
}
public static ValueTuple<T1, T2> Create(T1 item1, T2 item2)
{
return new ValueTuple<T1, T2>(item1, item2);
}
}
public static class ValueTuple
{
public static ValueTuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
{
return new ValueTuple<T1, T2>(item1, item2);
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/ValueTuple.cs.meta


fileFormatVersion: 2
guid: 7fdb7b91a165649ba9e20ceaea67a970
timeCreated: 1481279988
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存