Saturday, May 25, 2013

Cut Paste option in Assets context menu for Unity3D

I have been working with Unity3D from a long time. Its a good engine. I wish I could say its a great engine  but before that I want unity to add a bunch of stuff. One of them is to be able to move assets easily. This simple task becomes very difficult when you are dealing with big project where you have too many assets.

Instead of waiting for unity to do it for me, I wrote a editor script that makes my life easy. This editor script adds Cut & Paste option to Assets context menu.

How to use : Create a c sharp file in editor folder & copy paste the code below. Right click on the asset in Project pane & click on Cut. Then choose the location where you want to paste the asset , right click & select paste.


Code is as follows,,

using UnityEngine;
using UnityEditor;
using System.Collections;

/* Author : Altaf
 * Date : May 20, 2013
 * Purpose : Context menu to copy, cut & paste items
*/

public class AssetHelper : ScriptableWizard
{
    static string _AssetPath = string.Empty;
   
    [MenuItem("Assets/Cut", false, 80)]
    static void MoveAsset ()
    {
        _AssetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
        Debug.Log("Copied asset at path : " + _AssetPath);
    }

    [MenuItem("Assets/Cut", true)]
    static bool MoveAssetValidate ()
    {
        return (Selection.activeObject != null);
    }

    [MenuItem("Assets/Paste", false, 80)]
    static void PasteAsset ()
    {
        string dstPath = AssetDatabase.GetAssetPath(Selection.activeObject);
        string fileExt = System.IO.Path.GetExtension(dstPath);
        if(!string.IsNullOrEmpty(fileExt))
            dstPath = System.IO.Path.GetDirectoryName(dstPath);
        string fileName = System.IO.Path.GetFileName(_AssetPath);
        string msg = AssetDatabase.MoveAsset(_AssetPath, dstPath + "/" + fileName);
        if(string.IsNullOrEmpty(msg))
        {
            _AssetPath = null;
            Debug.Log("Pasted asset at path : " + _AssetPath);
        }
        else
            Debug.LogError("Failed to paste asset : " + msg);
    }

    [MenuItem("Assets/Paste", true)]
    static bool PasteAssetValidate ()
    {
        //Have we copied anything?
        if(string.IsNullOrEmpty(_AssetPath))
            return false;
        //Try to paste no where?
        if(Selection.activeObject == null)
            return false;
        //Trying to paste on same asst again?
        if(AssetDatabase.GetAssetPath(Selection.activeObject) == _AssetPath)
            return false;

        return true;
    }
}



Hope it helps...

Tuesday, March 15, 2011

Search Objects based on Layer in Unity3D

This is an editor script for Unity3D.
This tool will help you, if you are working on a large scale project & you often need to search for objects with specific layer. Unity3D searches objects based on Name & Type. This helps you search for objects based on Layer.

How To Use:
  • Press CTRL+SHIFT+L to launch the tool on PC. On MAC use CMD+SHIFT+L.
  • You can also find it in MyTools->Layer Search.
  • Choose Layer name from the drop down list.
  • The objects with the selcted layer are listed.
  • Click on the object, it will frame the object.
You can download the files from here.

Hope it helps someone.

Wednesday, January 13, 2010

Quick Find

Quick Find V1.1

This utility is a freeware for personal and commercial use. Its a very handy tool to search files.

Motivation : Recently I was working on a Wii game which had 856 files(art assets). I was having a hard time searching files. Windows searech is not handy & takes time to search. So I developed this tool to help me search my required files much faster. Hope it helps you guys as well :)











Click here to download the latest version

How To Use:

After installing the software right click on any folder and click "Open Quick Find Here".

Enter the name of file you are searching for.

Features:

  1. The Recursive Search option will search all underlying directories for the given file. This option is disabled by default.
  2. If Instant Search is enabled, the tool will start searching the file as soon as you start typing the file name. It is recommended to disable it in case if you have too many files in the given directory. This feature is enabled by default.
  3. Right click on the seached file to activate the context menu. From this context menu you can either Open, Cut, Copy, Delete, Open Containing Folder or Choose application to use to open the selected file(s).

If you find any bug or crash, or if you have any feature request please do mail me on altaf.navalur@gmail.com

Note:

Use this software on your own risk. I am not responsible for any loss of data or what so ever.

Tuesday, July 7, 2009

Visual Studio Add-In : OpenFiles

Finally...
Last year I was working on Flex Builder. This IDE had a very cool feature. Using this tool you can browse through files & resources in the project. I wanted this feature In Visual Studio badly. The reason being in my game engine I had more than 700 files. If I want to open a file I have to navigate through the solution file. Which is extrmely boring. If we have filetrs, this gets worse. So I decided to write one for me. Initially I thought of writing a MACRO. But MACRO`s in Visual Studio have certain limitation. A MACRO cannot have UI. So I started writing an Add-In. I call this Add-In as "OpenFiles".

What this Add-In does is, It Pop`s in a dialog box, Where in you can type the initial characters of the file you are looking for.
The list gets filled with the matching file(s) in the solution. Navigate through the files using Up & down arrow keys. Either hit Enter key or Double click to open the selected file.
Press CTRL + Click to select multiple files. Pretty Simple is`nt it...

Now lets see how to use this. The Add-In supports VS 2005 & VS 2008 IDE`s.
Download Installers : VS 2005, VS 2008.

When you run the installer, it will warn you for security iossues. Just click next, there is no rik in any way. If you are still not sure, click on "View files in Windows Explorer..." button. It will show you the file that are going to be installed.

Once you are done with the installation,
Start visual studio, Create/Open any project you want.
To use the Add-In, go to Tool. Here you will see a Smiley face Icon with the Text "OpenFiles".
Click on it, a dialog box will pop up, type in the first few characters of the file you are looking for.

If you are a kind of programmer who hates using mouse. I suggest you assign a short cut key for it.
To Assign a short cut key, do the following,
> Tools->Options->Environment->Keyboard.
> In the text box type : OpenFiles.
> In the list select : openFiles.Connect.OpenFiles.
> Choose any short cut key you want & click Assign.

I have set it to : Ctrl + Shift + Alt + O.

Hope you guys like it. Drop me a mail or write a comment if you have any suggestions.
Have fun Coding...

Note: Add-In are not supported by Express Editions.

Tuesday, June 30, 2009

Visual Studio Macro to open Partner files.

From past one year I have been working on Wii games. I was using CodeWarrior IDE. This IDE was not as good as Visual Studio, I used to hate it. But things changed. As I started using it more and more I got to see some really good features like. Pre-Processing a file by context menu. Class hierarchy diagram & few other features. Ofcourse we can Pre-Process a file in VS as well, but we have to go to project settings tab for that. Also, it Pre-Processes all files in the project. Another features which is "open the partner file". You can open c, cpp or cc file if you are in a header file and vice-verse. This small feature is really handy. So I wrote a MACRO for it.

Steps to add this MACRO to your VS IDE,
  • Open VS IDE.
  • Press Alt+F11 or go to Tools->Macros->Macros IDE.
  • Right click on MyMacros->Add->Add New Item.
  • Select Module in the dialog box and name it OpenPartnerFile.
  • Paste the following code.

Public Module OpenPartnerFile
' if this file is a .cpp then open up the .h

' or vice versa

Sub OpenPartnerFile()

Dim filename As String

Dim partnerFilename As String

filename = DTE.ActiveDocument.FullName

If (filename.EndsWith(".h")) Then

partnerFilename = filename.Substring(0, filename.Length() - 2) ' + ".cpp"

If System.IO.File.Exists(
partnerFilename + ".cpp") Then

partnerFilename += ".cpp"

End If

If System.IO.File.Exists(partnerFilename + ".cc") Then

partnerFilename += ".cc"

End If

If System.IO.File.Exists(partnerFilename + ".c") Then

partnerFilename += ".c"

End If



End If

If (filename.EndsWith(".cpp")) Then

partnerFilename = filename.Substring(0, filename.Length() - 4) + ".h"

End If

If (filename.EndsWith(".cc")) Then

partnerFilename = filename.Substring(0, filename.Length() - 3) + ".h"

End If

If (filename.EndsWith(".c")) Then

partnerFilename = filename.Substring(0, filename.Length() - 2) + ".h"

End If

'MsgBox(partnerFilename)


'See if the file exists & open it
If System.IO.File.Exists(partnerFilename) Then
DTE.ItemOperations.OpenFile(partnerFilename)
End If

End Sub

End Module


You are done with the MACRO now. Save and exit the Macro IDE. Now its the time to execute the macro on a keyboard shortcut. Steps are,
  1. Tools->Options->Environment->Keyboard.
  2. Select Visual C++ 6 in the first drop down list.
  3. In the next input box, type : OpenPartnerFile.
  4. You will get a Macro in the list box below, Click on it.
  5. Type a short cut of your choice & click assign. I feel "ctrl+` " more convenient.
Hope you guys like it.