NudgeGUIElements

From Unify Community Wiki
Revision as of 19:34, 29 March 2007 by Aarku (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Author: Jonathan Czeck (aarku)

Contents

Description

This script provides menu items to nudge the pixelInset of a GUITexture by 1 pixel or 10 pixels. This is useful for positioning user interfaces. It saves time because you don't have to repeatedly perform addition and subtraction on both xMin and xMax or yMin and yMax values.

Usage

Place this script in YourProject/Assets/Editor/NudgeGUITexture.cs and menu items will automatically appear in the Custom menu after it is compiled. Then select a GUITexture using pixel positioning and select one of the Nudge menu items.

Problems

Sometimes the key combinations do not work. It is not clear why. Also, you must coerce Unity to update the display after nudging.

C# - NudgeGUITexture.cs

<csharp>using UnityEngine; using UnityEditor;

public class NudgeGUITexture : ScriptableObject {

   [MenuItem ("Custom/Nudge GUITexture/Left ^j")]
   static void NudgeLeft()
   {
       Nudge(-1f, 0f);
   }
   [MenuItem ("Custom/Nudge GUITexture/Left Fast ^#j")]
   static void NudgeLeftFast()
   {
       Nudge(-10f, 0f);
   }
   [MenuItem ("Custom/Nudge GUITexture/Right ^l")]
   static void NudgeRight()
   {
       Nudge(1f, 0f);
   }
   [MenuItem ("Custom/Nudge GUITexture/Right Fast ^#l")]
   static void NudgeRightFast()
   {
       Nudge(10f, 0f);
   }
   [MenuItem ("Custom/Nudge GUITexture/Up ^i")]
   static void NudgeUp()
   {
       Nudge(0f, 1f);
   }
   [MenuItem ("Custom/Nudge GUITexture/Up Fast ^#i")]
   static void NudgeUpFast()
   {
       Nudge(0f, 10f);
   }
   [MenuItem ("Custom/Nudge GUITexture/Down ^k")]
   static void NudgeDown()
   {
       Nudge(0f, -1f);
   }
   
   [MenuItem ("Custom/Nudge GUITexture/Down Fast ^#k")]
   static void NudgeDownFast()
   {
       Nudge(0f, -10f);
   }
   
   static void Nudge(float x, float y)
   {
       // this probably could be thought out better
       Object[] objects = Selection.GetFiltered(typeof(GUITexture), SelectionMode.Deep | SelectionMode.Editable);
       
       foreach (GUITexture guiTexture in objects)
       {
           Rect pixelInset = guiTexture.pixelInset;
           pixelInset.xMin += x;
           pixelInset.xMax += x;
           pixelInset.yMin += y;
           pixelInset.yMax += y;
           guiTexture.pixelInset = pixelInset;
       }
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox