Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on September 16, 2012, 07:26:29 AM

Title: Mesh UV offset
Post by: jeanfabre on September 16, 2012, 07:26:29 AM
Hi,

 Following a request,
http://hutonggames.com/playmakerforum/index.php?topic=2257.0 (http://hutonggames.com/playmakerforum/index.php?topic=2257.0)

Please find an action that will offset the mesh UV ( NOT THE MATERIAL UV).

it works as well everyframe if you want to animate the UV.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;
using System;
using HutongGames.PlayMaker;

[ActionCategory("Meshes")]
[Tooltip("Offset Mesh UV")]
public class OffsetUV : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(MeshFilter))]
public FsmOwnerDefault gameObject;

public FsmVector2 offset;

public FsmFloat offsetX;
public FsmFloat offsetY;


public bool everyFrame;

Mesh _mesh;
Vector2[] _uvs;



public override void Reset()
{
gameObject = null;
offset = null;
offsetX = null;
offsetY = null;
everyFrame = false;
}

public override void OnEnter ()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
Finish();
return;
}

_mesh = (go.GetComponent<MeshFilter>() as MeshFilter).mesh;


if (_mesh == null)
{
LogError("Missing Mesh!");
Finish();
return;
}

  // Build the uvs
    _uvs = new Vector2[_mesh.vertices.Length];
    _uvs = _mesh.uv; // Take the existing UVs



DoOffsetUV();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate ()
{
DoOffsetUV();
}

private float _xOffset = 0f;
private float _yOffset = 0f;

void DoOffsetUV()
{
if (_mesh == null)
{
return;
}

Vector2[] _new_uvs = new Vector2[_uvs.Length];

float xOffset = offsetX.Value;
float yOffset = offsetY.Value;
if (! offset.IsNone)
{
xOffset += offset.Value.x;
yOffset += offset.Value.y;
}

if (xOffset.Equals(_xOffset) && yOffset.Equals(_yOffset))
{
// no change.
return;
}
_xOffset = xOffset;
_yOffset = yOffset;

    for(int i = 0; i < _uvs.Length; i++)
{
_new_uvs[i] = new Vector2 (_uvs[i].x + _xOffset, _uvs[i].y + _yOffset); // Offset all the UV's
}

   // Apply the modded UV's
   _mesh.uv = _new_uvs;
}
}


bye,

 Jean
Title: Re: Mesh UV offset
Post by: Groo Gadgets on September 19, 2012, 07:23:05 PM
Hey Jean,

Thank you very much for this custom action, I just tested it out and it works perfectly!

You're a lifesaver and a real credit to the PlayMaker comunity  :-)

Cheers,

Simon
Title: Re: Mesh UV offset
Post by: clandestine on October 20, 2014, 10:00:40 AM
Hey guys, i know this is old, but i need this action so i downloaded and it gives me the following error (i'm using U4.5):

Assets/PlayMaker/Actions/OffsetUV.cs(8,2): error CS0246: The type or namespace name `Tooltip' could not be found. Are you missing a using directive or an assembly reference?

Assets/PlayMaker/Actions/OffsetUV.cs(8,2): error CS0104: `TooltipAttribute' is an ambiguous reference between `UnityEngine.TooltipAttribute' and `HutongGames.PlayMaker.TooltipAttribute'

Is there a workaround or a fix for that?
Do you have an updated action or an alternative? (for scrolling the texture or normal map)

Thanks a lot for your time!
Title: Re: Mesh UV offset
Post by: clandestine on October 28, 2014, 03:23:36 AM
Please.
Title: Re: Mesh UV offset
Post by: mdotstrange on November 02, 2014, 01:52:47 AM
After seeing your post I was curious about this action- it is available through Ecosystem and it generates the same error when you download/install it from there as well.
Title: Re: Mesh UV offset
Post by: terri on January 18, 2015, 10:33:49 AM
Hey guys, i know this is old, but i need this action so i downloaded and it gives me the following error (i'm using U4.5):

Assets/PlayMaker/Actions/OffsetUV.cs(8,2): error CS0246: The type or namespace name `Tooltip' could not be found. Are you missing a using directive or an assembly reference?

Assets/PlayMaker/Actions/OffsetUV.cs(8,2): error CS0104: `TooltipAttribute' is an ambiguous reference between `UnityEngine.TooltipAttribute' and `HutongGames.PlayMaker.TooltipAttribute'

Is there a workaround or a fix for that?
Do you have an updated action or an alternative? (for scrolling the texture or normal map)

Thanks a lot for your time!

check this out:
http://hutonggames.com/playmakerforum/index.php?topic=7454.msg36892
Title: Re: Mesh UV offset
Post by: clandestine on January 18, 2015, 11:15:04 AM
Quote from: terri
check this out:
http://hutonggames.com/playmakerforum/index.php?topic=7454.msg36892

Hey thanks Terri, i didnt understand much, but will give it a shot and see what happens.
Title: Re: Mesh UV offset
Post by: clandestine on March 05, 2015, 09:29:29 AM
I had the chance to check out the solution and its extremely simple to fix.
But how do i use the action, nothing seems to happen?
Title: Re: Mesh UV offset
Post by: pandachilli on October 01, 2015, 06:13:42 AM
As a Playmaker / Unity N00b and at the risk of stating the obvious the way it seems to work for me was to:
1. Add a preceding Animated Float(?) action + setting the Anim Curve to loop (adjusted by clicking the cog icons in the mini-curve editor)
2. Create & assign a (float) variable as the 'Float Variable'.
3. Passing that into the UV Offset by using that new variable on the required axis.

Hope this helps someone. Great action BTW..thanks!