This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Developed by Tom Kail at Inkle | |
| // Released under the MIT Licence as held at https://opensource.org/licenses/MIT | |
| // Must be placed within a folder named "Editor" | |
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using UnityEditor; | |
| using UnityEngine; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEngine.EventSystems; | |
| public class BeginDragImmediately : MonoBehavior, IInitializePotentialDragHandler, IBeginDragHandler, IDragHandler { | |
| public void OnInitializePotentialDrag(PointerEventData eventData) { | |
| eventData.pointerDrag = gameObject; | |
| eventData.dragging = true; | |
| eventData.useDragThreshold = false; | |
| ExecuteEvents.ExecuteHierarchy(transform.gameObject, eventData, ExecuteEvents.beginDragHandler); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // RiveUIRenderer.cs created by Tom Kail. This file is licensed under the MIT License. | |
| // Renders a Rive asset to Unity UI using a RenderTexture in a similar manner to RawImage. | |
| // Supports pointer events and masking. | |
| using Rive; | |
| using UnityEditor; | |
| using UnityEngine; | |
| using UnityEngine.EventSystems; | |
| using UnityEngine.Rendering; | |
| using UnityEngine.UI; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Released under MIT License | |
| using System.Reflection; | |
| using TMPro; | |
| using UnityEngine; | |
| using UnityEngine.EventSystems; | |
| using UnityEngine.UI; | |
| // Workaround for Unity's inability to keep an input field selected when you click a button. | |
| // Call ReactivateInputField to immediately activate and restore caret position/selection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Used to draw custom inspectors for unrecognised file types, which Unity imports as "DefaultAsset" | |
| /// To do this, create a new editor class extending DefaultAssetInspector | |
| /// Return true in the IsValid function if the file extension of the file matches the type you'd like to draw. | |
| /// The DefaultAssetEditor class will then hold a reference to the new instance of your editor class and call the appropriate methods for drawing. | |
| /// An example can be found at the bottom of the file. | |
| using UnityEngine; | |
| using UnityEditor; | |
| using System; | |
| using System.IO; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Applying float.MaxValue to a rectTransform can cause crashes (not sure why) so we just use a very big number instead. | |
| const float veryLargeNumber = 10000000; | |
| // Gets the tightest bounds for the text by updating the text and using GetRenderedValues | |
| // Note this uses sizeDelta for sizing so won't work when using anchors. | |
| // This is wayyyy more reliable than the actual GetRenderedValues because it won't return stupid values, as GetRenderedValues is prone to doing. | |
| public static Vector2 GetRenderedValues (this TMP_Text textComponent, string text, float maxWidth = veryLargeNumber, float maxHeight = veryLargeNumber, bool onlyVisibleCharacters = true) { | |
| if(string.IsNullOrEmpty(text)) return Vector2.zero; | |
| // Setting RT size to Infinity can lead to weird results, so we use a very large number instead. | |
| if(maxWidth > veryLargeNumber) maxWidth = veryLargeNumber; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| // Sets the rect of the attached RectTransform to a viewport space rect, regardless of the pivot, anchors, or (optionally) scale of the RectTransform. | |
| [ExecuteAlways] | |
| [RequireComponent(typeof(RectTransform))] | |
| public class AbsoluteRectTransformController : MonoBehaviour { | |
| public Rect viewportRect = new Rect(0,0,1,1); | |
| public bool ignoreScale; | |
| static Vector3[] corners = new Vector3[4]; | |
| DrivenRectTransformTracker drivenRectTransformTracker; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEditor; | |
| using System.Collections; | |
| public static class BetterPropertyField { | |
| /// <summary> | |
| /// Draws a serialized property (including children) fully, even if it's an instance of a custom serializable class. | |
| /// Supersedes EditorGUILayout.PropertyField(serializedProperty, true); | |
| /// </summary> | |
| /// <param name="_serializedProperty">Serialized property.</param> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Usage example: | |
| // using System.Collections.Generic; | |
| // using System.Text.RegularExpressions; | |
| // public enum AudioCategory { | |
| // Undefined, | |
| // Music, | |
| // Narration, | |
| // } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.IO; | |
| using UnityEditor; | |
| using UnityEditor.Presets; | |
| using System.Linq; | |
| // This script automatically applies Presets to assets when they are imported into a folder containing a Preset. | |
| // It also adds any labels on the Preset file to the asset. | |
| public class PresetImportPerFolder : AssetPostprocessor { | |
| void OnPreprocessAsset() { | |
| // Make sure we are applying presets the first time an asset is imported. |
NewerOlder