AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SpriteAtlasExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 using System.Collections.Generic;
4 using UnityEditor;
5 using UnityEngine;
6 using UnityEngine.U2D;
7 
8 namespace HoloToolkit.Unity
9 {
10  public static class SpriteAtlasExtensions
11  {
12 #if UNITY_2017_1_OR_NEWER
13  public const string SpritePackables = "m_EditorData.packables";
14 
15  public static void SetSprites(this SpriteAtlas spriteAtlas, IList<Sprite> sprites)
16  {
17  var serializedObject = new SerializedObject(spriteAtlas);
18  var packables = serializedObject.FindProperty(SpritePackables);
19  packables.SetObjects(sprites);
20  serializedObject.ApplyModifiedProperties();
21  }
22 
23  public static bool ContainsSprite(this SpriteAtlas spriteAtlas, Sprite sprite)
24  {
25  var serializedObject = new SerializedObject(spriteAtlas);
26  var packables = serializedObject.FindProperty(SpritePackables);
27  for (var i = 0; i < packables.arraySize; i++)
28  {
29  var containedSprite = packables.GetArrayElementAtIndex(i).objectReferenceValue as Sprite;
30  if (sprite != containedSprite) { continue; }
31  return true;
32  }
33  return false;
34  }
35 #endif // UNITY_2017_1_OR_NEWER
36  }
37 }