Created
November 14, 2014 09:02
-
-
Save DomDomHaas/bad737591dcf51896eca to your computer and use it in GitHub Desktop.
Unity Editor Drag'n'Drop
This file contains 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; | |
using JSONPersistency; | |
[CustomEditor(typeof(DragNDrop))] | |
public class DragNDropInspector : Editor | |
{ | |
Color picked = Color.green; | |
public override void OnInspectorGUI () | |
{ | |
GUILayout.Space (20); | |
Rect colRect = GUILayoutUtility.GetRect (20, 40); | |
Rect horizontalRect = EditorGUILayout.BeginHorizontal (); | |
picked = EditorGUI.ColorField (colRect, picked); | |
EditorGUILayout.EndHorizontal (); | |
checkDragable (colRect, picked); | |
GUILayout.Space (20); | |
} | |
private void checkDragable (Rect colRect, Color col) | |
{ | |
string DragKey = "Color"; | |
if (Event.current.type == EventType.DragUpdated | |
&& colRect.Contains (Event.current.mousePosition)) { | |
// if ok show texture Color | |
//if (gotDragableWithRender (DragAndDrop.objectReferences)) { | |
DragAndDrop.visualMode = DragAndDropVisualMode.Copy; | |
if (DragAndDrop.GetGenericData (DragKey) == null) { | |
DragAndDrop.SetGenericData (DragKey, col); | |
} | |
/* } else { | |
// show a rejected sign on the mousecursor | |
DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; | |
} | |
*/ | |
Event.current.Use (); | |
} | |
if (Event.current.type == EventType.DragPerform | |
&& colRect.Contains (Event.current.mousePosition)) { | |
Color color = (Color)DragAndDrop.GetGenericData (DragKey); | |
//if (gotDragableWithRender (DragAndDrop.objectReferences)) { | |
applyColorToRenderer (DragAndDrop.objectReferences, color); | |
//} | |
Event.current.Use (); | |
} | |
} | |
private void applyColorToRenderer (Object[] objs, Color color) | |
{ | |
foreach (Object obj in objs) { | |
if (obj.GetType () == typeof(GameObject)) { | |
Renderer render = ((GameObject)obj).GetComponent<Renderer> (); | |
render.sharedMaterial.color = color; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment