Beispiel #1
0
        // This is an event handler on the hierachy view to handle dragging our objects from the browser
        void HierarchyUpdate(int instance, Rect rect)
        {
            if (Event.current.type == EventType.DragPerform && rect.Contains(Event.current.mousePosition))
            {
                if (IsDroppable(DragAndDrop.objectReferences))
                {
                    UnityEngine.Object data = DragAndDrop.objectReferences[0];

                    GameObject target = EditorUtility.InstanceIDToObject(instance) as GameObject;

                    if (data is EditorEventRef)
                    {
                        Undo.SetCurrentGroupName("Add Studio Event Emitter");

                        StudioEventEmitter emitter = Undo.AddComponent <StudioEventEmitter>(target);
                        emitter.Event = (data as EditorEventRef).Path;
                    }
                    else if (data is EditorBankRef)
                    {
                        Undo.SetCurrentGroupName("Add Studio Bank Loader");

                        StudioBankLoader loader = Undo.AddComponent <StudioBankLoader>(target);
                        loader.Banks = new List <string>();
                        loader.Banks.Add((data as EditorBankRef).Name);
                    }
                    else // data is EditorParamRef
                    {
                        Undo.SetCurrentGroupName("Add Studio Global Parameter Trigger");

                        StudioGlobalParameterTrigger trigger = Undo.AddComponent <StudioGlobalParameterTrigger>(target);
                        trigger.parameter = (data as EditorParamRef).Name;
                    }

                    Selection.activeObject = target;

                    Event.current.Use();
                }
            }
        }
Beispiel #2
0
        // This is an event handler on the scene view to handle dragging our objects from the browser
        // and creating new gameobjects
        void SceneUpdate(SceneView sceneView)
        {
            if (Event.current.type == EventType.DragPerform && IsDroppable(DragAndDrop.objectReferences))
            {
                UnityEngine.Object data = DragAndDrop.objectReferences[0];
                GameObject         newObject;

                if (data is EditorEventRef)
                {
                    string path = (data as EditorEventRef).Path;

                    string name = path.Substring(path.LastIndexOf("/") + 1);
                    newObject = new GameObject(name + " Emitter");

                    StudioEventEmitter emitter = newObject.AddComponent <StudioEventEmitter>();
                    emitter.Event = path;

                    Undo.RegisterCreatedObjectUndo(newObject, "Create Studio Event Emitter");
                }
                else if (data is EditorBankRef)
                {
                    newObject = new GameObject("Studio Bank Loader");

                    StudioBankLoader loader = newObject.AddComponent <StudioBankLoader>();
                    loader.Banks = new List <string>();
                    loader.Banks.Add((data as EditorBankRef).Name);

                    Undo.RegisterCreatedObjectUndo(newObject, "Create Studio Bank Loader");
                }
                else // data is EditorParamRef
                {
                    string name = (data as EditorParamRef).Name;

                    newObject = new GameObject(name + " Trigger");

                    StudioGlobalParameterTrigger trigger = newObject.AddComponent <StudioGlobalParameterTrigger>();
                    trigger.parameter = name;

                    Undo.RegisterCreatedObjectUndo(newObject, "Create Studio Global Parameter Trigger");
                }

                Ray    ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                object hit = HandleUtility.RaySnap(ray);

                if (hit != null)
                {
                    newObject.transform.position = ((RaycastHit)hit).point;
                }
                else
                {
                    newObject.transform.position = ray.origin + ray.direction * 10.0f;
                }

                Selection.activeObject = newObject;
                Event.current.Use();
            }
            else if (Event.current.type == EventType.DragUpdated && IsDroppable(DragAndDrop.objectReferences))
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                DragAndDrop.AcceptDrag();
                Event.current.Use();
            }
        }