Advertisement
Guest User

spine-unity 4 compatibility helper

a guest
Aug 2nd, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2.  
  3. /* 
  4.  *  Compatibility helper for using spine-unity (as of Aug. 1 2016)
  5.  *  with Unity 4.x
  6.  */
  7. namespace UnityEngine
  8. {
  9.     public static class GUILayoutExtensions
  10.     {
  11.         /// <summary>
  12.         /// Creating dummy placeholders for elements not present in Unity4, but present in Unity5.
  13.         /// </summary>
  14.         public static object EditorStyles_HelpBox(this GUIStyle style)
  15.         {
  16.             return null;
  17.         }
  18.     }
  19.  
  20.     /// <summary>
  21.     /// Wrapper for GUILayout static class, implementing some Using functionality present in Unity5 but not Unity4.
  22.     /// </summary>
  23.     public class GUILayoutWrapper : IDisposable
  24.     {
  25.         public enum EType
  26.         {
  27.             Horizontal,
  28.             Vertical
  29.         }
  30.  
  31.         public EType Type { get; private set; }
  32.  
  33.         public GUILayoutWrapper(EType type, params object [] args)
  34.         {
  35.             Type = type;
  36.             switch (type)
  37.             {
  38.                 case EType.Horizontal:
  39.                     GUILayout.BeginHorizontal();
  40.                     break;
  41.                 case EType.Vertical:
  42.                     GUILayout.BeginVertical();
  43.                     break;
  44.             }
  45.         }
  46.  
  47.         public void Dispose()
  48.         {
  49.             switch (Type)
  50.             {
  51.                 case EType.Horizontal:
  52.                     GUILayout.EndHorizontal();
  53.                     break;
  54.                 case EType.Vertical:
  55.                     GUILayout.EndVertical();
  56.                     break;
  57.             }
  58.         }
  59.     }
  60. }
  61.  
  62. /// <summary>
  63. /// Wrapper for EditorGUI static class, implementing some Using functionality present in Unity5 but not Unity4.
  64. /// </summary>
  65. namespace UnityEditor
  66. {
  67.     public class EditorGUIWrapper : IDisposable
  68.     {
  69.         public enum EType
  70.         {
  71.             DisabledGroup
  72.         }
  73.  
  74.         public EType Type { get; private set; }
  75.  
  76.         public EditorGUIWrapper(EType type, params object [] args)
  77.         {
  78.             Type = type;
  79.  
  80.             switch (Type)
  81.             {
  82.                 case EType.DisabledGroup:
  83.                     EditorGUI.BeginDisabledGroup((bool)args[0]);
  84.                     break;
  85.             }
  86.         }
  87.  
  88.         public void Dispose()
  89.         {
  90.             switch (Type)
  91.             {
  92.                 case EType.DisabledGroup:
  93.                     EditorGUI.EndDisabledGroup();
  94.                     break;
  95.             }
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement