Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubAssetKey == を実装した #891

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Extract(SubAssetKey key, TextureImportParam param)
case TextureImportTypes.StandardMap:
{
// write converted texture
var (_, subAsset) = m_subAssets.FirstOrDefault(kv => kv.Key.Equals(key));
var (_, subAsset) = m_subAssets.FirstOrDefault(kv => kv.Key == key);
if (subAsset == null)
{
throw new KeyNotFoundException();
Expand Down
36 changes: 34 additions & 2 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/SubAssetKey.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using System.Collections.Generic;

namespace UniGLTF
{
Expand All @@ -17,7 +17,7 @@ namespace UniGLTF
/// の呼び出し時に、identifier.name と externalObject.name が同じでない運用にしてみる。
///
/// </summary>
public struct SubAssetKey
public struct SubAssetKey : IEquatable<SubAssetKey>
{
public readonly Type Type;
public readonly string Name;
Expand All @@ -36,5 +36,37 @@ public override string ToString()
{
return $"{Type}:{Name}";
}

public override bool Equals(object obj)
{
if (obj is SubAssetKey key)
{
return this == key;
}
else
{
return true;
}
}

public bool Equals(SubAssetKey other)
{
return Type == other.Type && Name == other.Name;
}

public static bool operator ==(SubAssetKey l, SubAssetKey r)
{
return l.Equals(r);
}

public static bool operator !=(SubAssetKey l, SubAssetKey r)
{
return !(l == r);
}

public override int GetHashCode()
{
return Name.GetHashCode();
}
}
}