Skip to content

Commit

Permalink
Fix for toolscript input events
Browse files Browse the repository at this point in the history
[CI BUILD]
  • Loading branch information
andybak committed Jul 19, 2023
2 parents 294e77f + ad4a03f commit 373d2f8
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 16 deletions.
11 changes: 8 additions & 3 deletions Assets/Resources/LuaScriptExamples/ToolScript.ReplayStroke.lua
Expand Up @@ -4,8 +4,13 @@ Settings = {

function Main()
if Brush.triggerReleasedThisFrame then
path = Sketch.strokes.last.path
path:Resample(0.1)
return path
stroke = Sketch.strokes.last
if stroke == nil then
App.Error("Please draw a stroke with the brush and then try again")
else
path = stroke.path
path:Resample(0.1)
return path
end
end
end
20 changes: 18 additions & 2 deletions Assets/Resources/LuaScriptExamples/ToolScript.ScatterCubes.lua
Expand Up @@ -9,13 +9,18 @@ Parameters = {
amount={label="Amount", type="float", min=0.001, max=1, default=0.25},
}

function Start()
originalBrushType = Brush.type
originalBrushSize = Brush.size
Brush.type = "Shiny Hull"
Brush.size = 0.1
end

function Main()

if Brush.triggerIsPressed then

Brush.colorRgb = Color:New(Random.value, Random.value, Random.value)
Brush.type = "ShinyHull"
Brush.size = 0.1
origin = Brush.position

if Random.value < amount then
Expand All @@ -30,6 +35,17 @@ function Main()

end

function End()
-- If the user hasn't changed settings then restore the previous values
if Brush.type == "Shiny Hull" then
Brush.type = originalBrushType
end
if Brush.size == 0.1 then
Brush.size = originalBrushSize
end
end


function drawCube(center, size)

points = Path:New()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/BrushController.cs
Expand Up @@ -52,7 +52,7 @@ public void SetActiveBrush(BrushDescriptor brush)
// Reset our tool when the user picks a new brush unless it is repainting.
if (SketchSurfacePanel.m_Instance.GetCurrentToolType() != BaseTool.ToolType.RepaintTool &&
SketchSurfacePanel.m_Instance.GetCurrentToolType() != BaseTool.ToolType.ScriptedTool &&
SketchSurfacePanel.m_Instance.m_LastCommand.GetType() != typeof(RepaintStrokeCommand))
SketchSurfacePanel.m_Instance.m_LastCommand?.GetType() != typeof(RepaintStrokeCommand))
{
SketchSurfacePanel.m_Instance.EnableDefaultTool();
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Tools/BaseTool.cs
Expand Up @@ -191,7 +191,7 @@ virtual public void UpdateTool()
}
}

void Update()
protected virtual void Update()
{
// Can't do it in UpdateTool as it happens too late
// Symmetry scripts were seeing m_IsActiveThisFrame for two consecutive frames
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/DropperTool.cs
Expand Up @@ -100,8 +100,9 @@ override public void EnableTool(bool bEnable)
SnapIntersectionObjectToController();
}

void Update()
protected override void Update()
{
base.Update();
//update animations
switch (m_CurrentState)
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/FlyTool.cs
Expand Up @@ -269,8 +269,9 @@ void ApplyVelocity(Vector3 velocity)
App.Scene.Pose = newScene;
}

void Update()
protected override void Update()
{
base.Update();
ApplyVelocity(m_Velocity);
if (!m_LockToController)
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/JoinTool.cs
Expand Up @@ -90,8 +90,9 @@ override public void EnableTool(bool bEnable)
SnapIntersectionObjectToController();
}

void Update()
protected override void Update()
{
base.Update();
//update animations
switch (m_CurrentState)
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/MultiCamTool.cs
Expand Up @@ -926,8 +926,9 @@ override public void UpdateTool()
}
}

void Update()
protected override void Update()
{
base.Update();
switch (m_CurrentState)
{
case State.Enter:
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/SaveIconTool.cs
Expand Up @@ -301,8 +301,9 @@ override public bool LockPointerToSketchSurface()
return false;
}

void Update()
protected override void Update()
{
base.Update();
switch (m_CurrentState)
{
case State.Enter:
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/ScriptedTool.cs
Expand Up @@ -238,8 +238,9 @@ private void SetApiProperty(string key, object value)
}

//The actual Unity update function, used to update transforms and perform per-frame operations
void Update()
protected override void Update()
{
base.Update();
// If we're not locking to a controller, update our transforms now, instead of in LateUpdate.
if (!m_LockToController)
{
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Tools/SketchSurfaceTool.cs
Expand Up @@ -57,6 +57,11 @@ override public void UpdateTool()
bool bEnableLine = InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate);
bEnableLine = bEnableLine && !m_EatInput && m_AllowDrawing && m_SketchSurface.IsSurfaceDrawable();

if (bEnableLine)
{
PointerManager.m_Instance.HandleColorJitter();
}

// Allow API command to override painting mode
bEnableLine = ApiManager.Instance.ForcePainting switch
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/SnipTool.cs
Expand Up @@ -90,8 +90,9 @@ override public void EnableTool(bool bEnable)
SnapIntersectionObjectToController();
}

void Update()
protected override void Update()
{
base.Update();
//update animations
switch (m_CurrentState)
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/StrokeModificationTool.cs
Expand Up @@ -145,8 +145,9 @@ protected override int AdditionalGpuIntersectionLayerMasks()
return LayerMask.NameToLayer("SelectionCanvas");
}

void Update()
protected override void Update()
{
base.Update();
// Note this isn't in UpdateAudioVisuals() because we want it to run while the
// tool is deactivated.
if (m_ToolAudio)
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Tools/TeleportTool.cs
Expand Up @@ -420,8 +420,9 @@ override public void UpdateTool()
PointerManager.m_Instance.SetMainPointerPosition(rAttachPoint.position);
}

void Update()
protected override void Update()
{
base.Update();
// Update bounds transitions.
switch (m_BoundsState)
{
Expand Down

0 comments on commit 373d2f8

Please sign in to comment.