* Implements IObject.OnTouch += delegate(IObject sender, TouchEventArgs e)
* This is equivalent to LSL 'touch(int senders)'0.6.5-rc1
parent
99bf4ce72f
commit
232241ab25
|
@ -32,8 +32,30 @@ using OpenSim.Region.OptionalModules.Scripting.Minimodule.Object;
|
|||
|
||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||
{
|
||||
public class TouchEventArgs : EventArgs
|
||||
{
|
||||
public IAvatar Avatar;
|
||||
|
||||
public Vector3 TouchBiNormal;
|
||||
public Vector3 TouchNormal;
|
||||
public Vector3 TouchPosition;
|
||||
|
||||
public Vector2 TouchUV;
|
||||
public Vector2 TouchST;
|
||||
|
||||
public int TouchMaterialIndex;
|
||||
}
|
||||
|
||||
public delegate void OnTouchDelegate(IObject sender, TouchEventArgs e);
|
||||
|
||||
public interface IObject
|
||||
{
|
||||
#region Events
|
||||
|
||||
event OnTouchDelegate OnTouch;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether or not this object is still in the world.
|
||||
/// Eg, if you store an IObject reference, however the object
|
||||
|
|
|
@ -59,6 +59,57 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
|||
return null;
|
||||
}
|
||||
|
||||
#region OnTouch
|
||||
|
||||
private event OnTouchDelegate _OnTouch;
|
||||
private bool _OnTouchActive = false;
|
||||
|
||||
public event OnTouchDelegate OnTouch
|
||||
{
|
||||
add
|
||||
{
|
||||
if(!_OnTouchActive)
|
||||
{
|
||||
_OnTouchActive = true;
|
||||
m_rootScene.EventManager.OnObjectGrab += EventManager_OnObjectGrab;
|
||||
}
|
||||
|
||||
_OnTouch += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_OnTouch -= value;
|
||||
|
||||
if (_OnTouch == null)
|
||||
{
|
||||
_OnTouchActive = false;
|
||||
m_rootScene.EventManager.OnObjectGrab -= EventManager_OnObjectGrab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager_OnObjectGrab(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
|
||||
{
|
||||
if (_OnTouchActive && m_localID == localID)
|
||||
{
|
||||
TouchEventArgs e = new TouchEventArgs();
|
||||
e.Avatar = new SPAvatar(m_rootScene, remoteClient.AgentId);
|
||||
e.TouchBiNormal = surfaceArgs.Binormal;
|
||||
e.TouchMaterialIndex = surfaceArgs.FaceIndex;
|
||||
e.TouchNormal = surfaceArgs.Normal;
|
||||
e.TouchPosition = surfaceArgs.Position;
|
||||
e.TouchST = new Vector2(surfaceArgs.STCoord.X, surfaceArgs.STCoord.Y);
|
||||
e.TouchUV = new Vector2(surfaceArgs.UVCoord.X, surfaceArgs.UVCoord.Y);
|
||||
|
||||
IObject sender = this;
|
||||
|
||||
if (_OnTouch != null)
|
||||
_OnTouch(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool Exists
|
||||
{
|
||||
get { return GetSOP() != null; }
|
||||
|
|
Loading…
Reference in New Issue