playMaker

Author Topic: Draw Line 1.1 [last update: 18.05.2015]  (Read 18655 times)

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 990
    • View Profile
    • Fat Pug Studio
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #30 on: May 30, 2017, 04:11:45 AM »
Hmm, i tried updating the action, but i get this error:

Assets/PlayMaker Custom Actions/Effects/DrawLine.cs(32,35): error CS0118: `UnityEngine.LineRenderer.textureMode' is a `Unresolved' but a `type' was expected

This is all i added, nothing much really:

31   [Tooltip( "Texture Mode" )]
32   public UnityEngine.LineRenderer.textureMode textureMode;

91   textureMode = UnityEngine.LineRenderer.textureMode.Stretch;
126 _lineRenderer.textureMode = textureMode;
143 _lineRenderer.textureMode = textureMode;

Any ideas, haven't seen this mistake.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 730
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #31 on: May 30, 2017, 05:14:11 AM »
Double reply. I created a new action to set the line renderer texture mode. As well my github account has one to set a gradient for the line renderer.

https://github.com/dumbgamedev/general-playmaker/tree/master/lineRenderer

cel

  • Junior Playmaker
  • **
  • Posts: 96
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #32 on: July 21, 2017, 06:33:53 AM »
I am having trouble with this... I have an object that rotates with the mouse, and I want the line to rotate on the y axis with the object, but can't get it to work, tried all the settings with space mode and align to is space mode self and still nothing... could you guys cook up an example, please?

thanks in advance

arkdzo

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #33 on: August 04, 2017, 02:55:23 PM »
Unity 2017.1.0p2.. Start, End Colors not working.. Always brown color  :-[

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #34 on: February 16, 2019, 04:42:15 AM »
I encountered the same problem that NateGallardo explained:

I am using the DrawLine action from the Ecosystem in a state, then change the start and end positions in the next state and cycling around to the draw line state again, I was expecting it to draw another line and leave the previous one, but instead the previous one is removed OR modified with the new positions: the line jumps to the new positions.
In the end there is only one line not many as I expected it to work.
If I add a short delay to my cycle of creating the lines then I can perfectly see the line being created and moved to new positions as the cycle goes on.

Of course I don't have DestroyOnExit checked.

Since you are able to store the line as a GameObject, so can destroy it any time, I believe it should work as I expected it to instead of being able to draw just one line.
OR am I doing something wrong?

Also an action to modify the thickness of the start and end would be very much appreciated so Get-Set Property does not have to be used for this.

Thanks in advance,
szomaza

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #35 on: February 22, 2019, 09:43:55 AM »
The DrawLine action looks like so:

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

// DrawLine.cs version 1.1
// http://hutonggames.com/playmakerforum/index.php?topic=3943.0
// custom action by andrew r lukasik gmail com
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using UnityEngine;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory( ActionCategory.Effects )]
[Tooltip( "Draws line between two objects or points using LineRenderer." )]
public class DrawLine : FsmStateAction {

[Tooltip( "Line start." )]
public FsmGameObject startObject;
[Tooltip( "Line end." )]
public FsmGameObject endObject;
[Tooltip( "Start offset or world position." )]
public FsmVector3 startOffset;
[Tooltip( "End offset or world position." )]
public FsmVector3 endOffset;
[Tooltip( "Space." )]
public Space spaceMode;
[Tooltip( "When Space Mode Self is selected Start Object and End Object will execute LookAt each other to align their Z axes" )]
public FsmBool alignInSpaceModeSelf;

[Tooltip( "Material" )]
public FsmMaterial material;
[Tooltip( "Shadow Casting Mode" )]
public UnityEngine.Rendering.ShadowCastingMode shadowCastingMode;
[Tooltip( "Receive Shadows" )]
public FsmBool receiveShadows;

[Tooltip( "start width" )]
public FsmFloat startWidth;
[Tooltip( "end width" )]
public FsmFloat endWidth;

[Tooltip( "Start Color" )]
public FsmColor startColor;
[Tooltip( "End Color" )]
public FsmColor endColor;

[UIHint( UIHint.Variable )]
[Tooltip( "Store GameObject with LineRenderer." )]
public FsmGameObject storeGameobject;

[Tooltip( "Updates positions every frame" )]
public FsmBool everyFrame;
[Tooltip( "Destroy drawn line on exit" )]
public FsmBool destroyOnExit;

//
private FsmGameObject goLineRenderer;
private LineRenderer _lineRenderer;
private Transform _lineRendererTransform;
//
private FsmGameObject localStart;
private Transform _localStartTransform;
//
private FsmGameObject localEnd;
private Transform _localEndTransform;
//
private FsmGameObject startObjectPosition;
private Transform _startObjectPositionTransform;
//
private FsmGameObject endObjectPosition;
private Transform _endObjectPositionTransform;
//
private Transform _startObjectTransform;
private Transform _endObjectTransform;
//

// RESET //
public override void Reset () {
//
startObject = null;
_startObjectTransform = null;
//
endObject = null;
_endObjectTransform = null;
//
alignInSpaceModeSelf = false;
startOffset = new FsmVector3 { UseVariable = true };
endOffset = new FsmVector3 { UseVariable = true };
spaceMode = Space.World;
material = null;
shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
receiveShadows = false;
startWidth = 1.0F;
endWidth = 1.0F;
startColor = Color.white;
endColor = Color.white;
everyFrame = true;
destroyOnExit = false;
//
goLineRenderer = null;
storeGameobject = null;
_lineRenderer = null;
_lineRendererTransform = null;
//
_localStartTransform = null;
_localEndTransform = null;
_startObjectPositionTransform = null;
_endObjectPositionTransform = null;

}

// ON ENTER //
public override void OnEnter () {
if( goLineRenderer!=null ) {
Object.Destroy( goLineRenderer.Value );
}
//
goLineRenderer = new GameObject( "FSM draw line ("+this.Name+")" );
storeGameobject.Value = goLineRenderer.Value;
_lineRendererTransform = goLineRenderer.Value.transform;
//
_lineRenderer = goLineRenderer.Value.AddComponent<LineRenderer>();
_lineRenderer.material = material.Value;
//
_lineRenderer.shadowCastingMode = shadowCastingMode;
_lineRenderer.receiveShadows = receiveShadows.Value;

#if UNITY_5_6_OR_NEWER
_lineRenderer.positionCount =  2 ;
_lineRenderer.startWidth = startWidth.Value ;
_lineRenderer.endWidth = endWidth.Value;
_lineRenderer.startColor = startColor.Value;
_lineRenderer.endColor = endColor.Value;
#else
_lineRenderer.SetVertexCount( 2 );
_lineRenderer.SetWidth( startWidth.Value , endWidth.Value );
_lineRenderer.SetColors( startColor.Value , endColor.Value );
#endif


DoUpdatePositions();
if( !everyFrame.Value ) {
Finish();
}
}

// ON UPDATE //
public override void OnUpdate () {
if( everyFrame.Value ) {
DoUpdatePositions();

#if UNITY_5_6_OR_NEWER
_lineRenderer.startWidth = startWidth.Value ;
_lineRenderer.endWidth = endWidth.Value;
_lineRenderer.startColor = startColor.Value;
_lineRenderer.endColor = endColor.Value;
#else
_lineRenderer.SetWidth( startWidth.Value , endWidth.Value );
_lineRenderer.SetColors( startColor.Value , endColor.Value );
#endif


_lineRenderer.shadowCastingMode = shadowCastingMode;
_lineRenderer.receiveShadows = receiveShadows.Value;
_lineRenderer.material = material.Value;
}
}

// ON EXIT //
public override void OnExit () {
if( destroyOnExit.Value && goLineRenderer!=null ) {
Object.Destroy( goLineRenderer.Value );
}
}

// DO UPDATE POSITIONS //
void DoUpdatePositions () {
//
if( spaceMode==Space.Self ) MakeSureSpaceSelfHelpersAreOk();
//calculate Start pos:
if( startObject.Value!=null ) {
_startObjectTransform = startObject.Value.transform;
if( spaceMode==Space.World ) {
_lineRenderer.SetPosition( 0 , (_startObjectTransform.position+startOffset.Value) );
}
else {
if( startObject.Value!=null ) {
_startObjectPositionTransform.position = _startObjectTransform.position;
if( alignInSpaceModeSelf.Value ) {
_startObjectPositionTransform.LookAt( _endObjectPositionTransform );
_localStartTransform.localPosition = startOffset.Value;
}
else {
_startObjectPositionTransform.rotation = _startObjectTransform.rotation;
_localStartTransform.localPosition = startOffset.Value;
}
_lineRenderer.SetPosition( 0 , _localStartTransform.position );
}
else {
_startObjectPositionTransform.position = startOffset.Value;
if( alignInSpaceModeSelf.Value ) {
_startObjectPositionTransform.LookAt( _endObjectPositionTransform );
_localStartTransform.localPosition = startOffset.Value;
}
else {
_localStartTransform.localPosition = startOffset.Value;
}
_lineRenderer.SetPosition( 0 , _localStartTransform.position );
}
}
}
else {
_lineRenderer.SetPosition( 0 , startOffset.Value );
}

//calculate End pos:
if( endObject.Value!=null ) {
_endObjectTransform = endObject.Value.transform;
if( spaceMode==Space.World ) {
_lineRenderer.SetPosition( 1 , (_endObjectTransform.position+endOffset.Value) );
}
else {
if( endObject.Value!=null ) {
_endObjectPositionTransform.position = _endObjectTransform.position;
if( alignInSpaceModeSelf.Value ) {
_endObjectPositionTransform.LookAt( _startObjectPositionTransform );
_localEndTransform.localPosition = endOffset.Value;
}
else {
_endObjectPositionTransform.rotation = _endObjectTransform.rotation;
_localEndTransform.localPosition = endOffset.Value;
}
_lineRenderer.SetPosition( 1 , _localEndTransform.position );
}
else {
_endObjectPositionTransform.position = endOffset.Value;
if( alignInSpaceModeSelf.Value ) {
_endObjectPositionTransform.LookAt( _startObjectPositionTransform );
_localEndTransform.localPosition = endOffset.Value;
}
else {
_localEndTransform.localPosition = endOffset.Value;
}
_lineRenderer.SetPosition( 1 , _localEndTransform.position );
}
}
}
else {
_lineRenderer.SetPosition( 1 , endOffset.Value );
}
}

//
private void MakeSureSpaceSelfHelpersAreOk () {
if( startObjectPosition==null ) {
startObjectPosition = new GameObject( "tracking startObject" );
_startObjectPositionTransform = startObjectPosition.Value.transform;
_startObjectPositionTransform.parent = _lineRendererTransform;
}
else {
_startObjectPositionTransform.parent = _lineRendererTransform;
}
//
if( localStart==null ) {
localStart = new GameObject( "local start" );
_localStartTransform = localStart.Value.transform;
_localStartTransform.parent = _startObjectPositionTransform;
_localStartTransform.localEulerAngles = new Vector3( 0 , 0 , 0 );
}
else {
_localStartTransform.parent = _startObjectPositionTransform;
}
//
if( endObjectPosition==null ) {
endObjectPosition = new GameObject( "tracking endObject" );
_endObjectPositionTransform = endObjectPosition.Value.transform;
_endObjectPositionTransform.parent = _lineRendererTransform;
}
else {
_endObjectPositionTransform.parent = _lineRendererTransform;
}
//
if( localEnd==null ) {
localEnd = new GameObject( "local end" );
_localEndTransform = localEnd.Value.transform;
_localEndTransform.parent = _endObjectPositionTransform;
_localEndTransform.localEulerAngles = new Vector3( 0 , 0 , 0 );
}
else {
_localEndTransform.parent = _endObjectPositionTransform;
}
//
}

}
}

I would really appreciate if somebody could take a look and tell me why there can only be one line at a time.

Is it this part?
Code: [Select]
// ON ENTER //
public override void OnEnter () {
if( goLineRenderer!=null ) {
Object.Destroy( goLineRenderer.Value );
}
Why would it do this?
Why is it a good idea to only have one line?

Do these lines take a lot of resources?
Is it a problem if one draws many 10 or hundred lines?

Thanks!
« Last Edit: February 22, 2019, 09:47:00 AM by szomaza »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14500
  • Official Playmaker Support
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #36 on: February 26, 2019, 11:59:54 PM »
Hi,

 The principle of that action is to draw one line, so at the beginning ( Onenter), it make sure of that. It had nothing to do with perfs, but just to keep things in order.

I don't know about the perf itself of the line renderer, I'd say 100 lines should be totally fine indeed, but it depends on how they are used and displayed of course.

if you want many lines, maybe ( very likely), VEctrosity is the way to go: https://assetstore.unity.com/packages/tools/particles-effects/vectrosity-82

 There is no PlayMaker support for the latest version unfortunatly.

Bye,

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Draw Line 1.1 [last update: 18.05.2015]
« Reply #37 on: March 09, 2019, 03:05:31 AM »
Thank you Jean for the info.
I won't try Vectrosity now as this simple line drawing seems to be good enough for now.

I commented out that one IF and without that it perfectly draws a bunch of lines.
(I even managed to add a boolean checkbox myself to the action to be able to toggle this behavior.  YAY!)

Code: [Select]
if( goLineRenderer!=null ) {
Object.Destroy( goLineRenderer.Value );
}

I believe it would be a good improvement to add this ability with a checkbox to the action so it can draw multiple lines, not just one at a time.