Skip to content

Instantly share code, notes, and snippets.

@jacobdufault
Created May 10, 2014 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobdufault/8c3e1817c4e8773f97d4 to your computer and use it in GitHub Desktop.
Save jacobdufault/8c3e1817c4e8773f97d4 to your computer and use it in GitHub Desktop.
RotorzGUIHelper without Delegate.CreateDelegate
// Copyright (c) 2012-2013 Rotorz Limited. All rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the LICENSE file.
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
namespace FullInspector.Rotorz.ReorderableList.Internal {
/// <summary>
/// Utility functions to assist with GUIs.
/// </summary>
internal static class RotorzGUIHelper {
static RotorzGUIHelper() {
var tyGUIClip = typeof(GUI).Assembly.GetType("UnityEngine.GUIClip");
if (tyGUIClip != null) {
var piVisibleRect = tyGUIClip.GetProperty("visibleRect", BindingFlags.Static | BindingFlags.Public);
if (piVisibleRect != null) {
var getGetMethod = piVisibleRect.GetGetMethod();
VisibleRect = () => (Rect)getGetMethod.Invoke(null, null);
}
}
var miFocusTextInControl = typeof(EditorGUI).GetMethod("FocusTextInControl", BindingFlags.Static | BindingFlags.Public);
if (miFocusTextInControl == null)
miFocusTextInControl = typeof(GUI).GetMethod("FocusControl", BindingFlags.Static | BindingFlags.Public);
FocusTextInControl = str => miFocusTextInControl.Invoke(null, new object[] { str });
}
/// <summary>
/// Gets visible rectangle within GUI.
/// </summary>
/// <remarks>
/// <para>VisibleRect = TopmostRect + scrollViewOffsets</para>
/// </remarks>
public static Func<Rect> VisibleRect;
/// <summary>
/// Focus control and text editor where applicable.
/// </summary>
public static Action<string> FocusTextInControl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment