Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Andrew.Lukasik on May 20, 2013, 12:01:05 PM

Title: Draw Line 1.1 [last update: 18.05.2015]
Post by: Andrew.Lukasik on May 20, 2013, 12:01:05 PM
DrawLine.cs

 Draws line between two objects or points using LineRenderer.

Quote from: version history
1.01 - released
1.02 - <Align In Space Mode Self> now also works with only one target object at hand.
1.021 - bugfix
1.1 - Proper maintenance update. No features added but expect this action to be more performance friendly and a lot more robust.


(http://i.imgur.com/cRhsZvk.gif)

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

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;
_lineRenderer.SetVertexCount( 2 );
_lineRenderer.SetWidth( startWidth.Value , endWidth.Value );
DoUpdatePositions();
if( !everyFrame.Value ) {
Finish();
}
}

// ON UPDATE //
public override void OnUpdate () {
if( everyFrame.Value ) {
DoUpdatePositions();
_lineRenderer.SetWidth( startWidth.Value , endWidth.Value );
_lineRenderer.SetColors( startColor.Value , endColor.Value );
_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;
}
//
}

}
}
Title: Re: Draw Line
Post by: Lane on May 20, 2013, 12:38:55 PM
Wow, that's one seriously elaborate line renderer!

Very cool, thanks. I'm going to use this a lot for testing and debugging.
Title: Re: Draw Line
Post by: jeanfabre on May 20, 2013, 12:42:38 PM
Hi,

 Why not using Vectrosity? maybe I am missing something with line renderers...? I guess it implements better as "Physical" object in the scene than vectrosity right?

where is your struggle to expand this to a poly? I think you could inspire from Vectrosity here too cause It features an editor script that parse a poly and extracts all the edges to build the mesh as a wireframe.

 Bye,

 Jean
Title: Re: Draw Line
Post by: Andrew.Lukasik on May 20, 2013, 01:03:19 PM
@Jeanfabre
I never used Vectrosity and I believe it's great for complex things. But when I want just to experiment and draw a line between things I would like to have something built-in and unity-native.

Well this was just intense improvisation, trail and error till it worked. I know that it probably should use some kind of array but I'm not yet sure if I will be able to implement it. In any case I will definitely check your Vectrosity's actions to research that.
Title: Re: Draw Line
Post by: Lane on May 20, 2013, 01:09:15 PM
Personally, I just wanted to be able to draw some lines for debugging and experimenting. Vectrosity is a paid asset and more elaborate than I need.
Title: Re: Draw Line
Post by: Andrew.Lukasik on May 20, 2013, 01:29:57 PM
@Lane I agree totally. I don't want to import/buy Vectrosity when I just want to draw single raycast (shot) trail for example.
Title: Re: Draw Line
Post by: Andrew.Lukasik on May 21, 2013, 02:43:30 PM
Quote from: update note
1.02 - <Align In Space Mode Self> now also works with only one target object at hand.
Title: Re: Draw Line
Post by: Drakon on May 23, 2013, 10:31:57 AM
Super! Works really well!
Title: Draw Line 1.021 (bugfix)
Post by: Andrew.Lukasik on July 08, 2013, 02:44:15 PM
Quote from: update note
1.021 - Bugfix in OnExit(), "if (destroyOnExit.Value)" changed to "if (destroyOnExit.Value && goLineRenderer != null)".
Line 137 was giving me errors lately so this simple addition tests if Line Renderer object exist when destroying it OnExit.
Title: Re: Draw Line
Post by: aLDime on October 26, 2013, 10:14:28 AM
Thank you very much, Andrew!
Quickly and simply made ​​an electric discharge between 2 objects!
Title: Re: Draw Line
Post by: henrygordon on December 20, 2014, 02:08:37 AM
This has been an old post, yet this resolves my concern, thanks, still working well. Anyway, soon I will try to use this on upcoming game that I am doing, you can soon check it at http://www.iphysicsgames.com/top-rated (http://www.iphysicsgames.com/top-rated). Thanks,
Title: Re: Draw Line
Post by: KozTheBoss on February 02, 2015, 06:22:55 PM
This is exactly what I needed and still works ^^ thanks! just had to remember to set the material, otherwise it is invisible!

Great work, thanks :)
Title: Re: Draw Line
Post by: FritsLyn on April 03, 2015, 05:05:06 AM
Jean: Bump: This should IMO be in the Ecosystem (Or straight up native PlayMaker Package)

Andrew: Very, very nice work, works extremely well!!

Thanks!
Title: Re: Draw Line
Post by: mitchelq on May 17, 2015, 07:28:25 AM
I was looking for this!

Thanks, well done!

Works in playmaker 1.8
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Andrew.Lukasik on May 18, 2015, 08:54:23 AM
Quote from: version history
1.1 - Proper maintenance update. No features added but expect this action to be more performance friendly and a lot more robust.

Hi!
 I noticed that you guys are still using this action so I made a proper maintenance update 1.1 today! :)

ps: post bugs reports here when encountered any
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Thyriax on June 24, 2015, 10:03:45 AM
Hi !
This is a great action and easy to use !
But, i've got a little bug.
When i use "Destroy on exit" option, and reactivate the FSM who have this action, it creates a default "line renderer" component . The options in the action are still here but not applied.

Good job !
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Matthew on November 17, 2015, 08:26:34 AM
Any suggestions for how to get the line renderer to show up in the UI Canvas?  I tried setting the line to parent the canvas and adding UI components but had no luck.  I really need a tool like this for a game that uses state machine interface.

Thanks,
Matthew
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Andrew.Lukasik on November 19, 2015, 04:40:16 AM
Hi @Matthew. To make line renderer show up above the UI Canvas you need to:
1. Change your Canvas component's Render Mode setting from "Screen Space - Overlay" to "Screen Space - Camera"
2. Set "Render Camera" below to you main camera
3. If line renderer is still obstructed by Ui Elements just move it closer to camera OR change Canvas Component's "Plane Distance" value

Hope it helps,
Andrew
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Matthew on November 21, 2015, 08:55:56 AM
Thanks Andrew!!
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Pandur on February 09, 2016, 02:50:27 PM
Big Thx Andrew you save a lot of my Time :D
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Fat Pug Studio on August 04, 2016, 01:14:53 PM
I have to ask, why this fantastic action is not in the ecosystem? Please make it so :D
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: djaydino on August 05, 2016, 09:41:17 AM
Hi,
The Action can now be found on the Ecosystem.  ;)
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: NateGallardo on September 25, 2016, 01:31:23 PM
Hi Andrew,

I'm using your great Draw Line action, but I'm not sure if I've run into a bug, or if I'm just misunderstanding a particular aspect of it.

I have a state in which I use Draw Line to create a line between two game objects, and parent it to one of those objects. When I leave the state, the line persists in the scene. However, when I re-enter this same state, the previous line is destroyed, and a new one is created. I don't have Destroy On Exit checked, and I'm not sure what I need to do to ensure the line persists.

I've attached a screenshot to illustrate my FSM setup.

I found that if I went into the action code and commented out line 113, that the line does then persist as I expect. That line is:
"Object.Destroy( goLineRenderer.Value );"

I've attached another screenshot to illustrate where in the code that occurs.

So, am I just not using the action correctly, or have I found a bug?

Cheers :)
Nate
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: cwmanley on September 26, 2016, 05:04:10 AM
Hello,

I don't think it is a bug.

You might need to edit the DrawLine Action.

Actions that create and destroy can be a pain.

I would prefer a FSM variable so I can handle creating and destroying things myself, but it is not a big deal.

You can learn a lot from tweaking actions, don't be afraid to make things work the way you need them to.

Just make a new FSMGameObject Variable for the LineRenderer.

If you have any problems look at similar actions or pm me.

Thanks
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: NateGallardo on October 02, 2016, 04:22:42 PM
Yep you're right, I got stuck in and made a few tweaks.

I added the ability to specify whether or not to use world space for the line, so you can parent it to another object and it'll move with it. I also modified it to fix the behaviour I mentioned in my previous post.

I've attached my modified version of the script in case it helps anyone :)
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: spektron on February 19, 2017, 08:05:21 AM
Thanks for the action!
Encountered an error with these settings:
spaceMode=self
AlightInSpaceModeSelf=true
DestroyOnExit=true


when I return to the state with the drawline action, I got this error:
"missing reference exption the object of type transform has been destroyed but you are still trying to access it".

with the following doesnt happen.
spaceMode=world
AlightInSpaceModeSelf=false


suggestions?
thanks
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: LordHorusNL on April 12, 2017, 02:49:05 PM
I have 2 problems with this action when using with VR controllers.

I'm trying to simulate a laser pointer from my controller to a target 20 meters away, this works but when i move the controller the line laggs behind and looks all wobbley. (like if it where attached to a joint or something)

Second: when using a material it always shows up as black and if i only use a color it never matches with the color i pick in the editor.

Anybody else have these problems?
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: jeanfabre on April 13, 2017, 03:44:05 AM
Hi,

 - use actions that works on lateUpdate else you will get this lag. so for example use "SetPositionAdvanced" on the Ecosystem, each "advanced" version will give you this possibility to set when to executed the action, not just on update, but on fixed and late too. IF you need an action that doesn't support this, let me know, I'll do it.

 Bye,

 Jean
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: LordHorusNL on April 13, 2017, 09:24:47 AM
Thats not an option, i have this action running directly on my Vive controller, so i'm not using any other actions to move the object (controller)

I'll try parenting a seperate object to the controller and put the action on that (using advanced set position)
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Fat Pug Studio on May 29, 2017, 06:07:26 PM
Hello guys,

from Unity 5.5 it's possible to choose between Stretch or Tile in the Line Renderers Texture Mode. Any chance of implementing that choice in the action? It's really useful and a solution to a problem that's been troubling many users for a long time (dynamic stretching needed to be done on runtime if you want it tiled).

As far as i can see, nothing too hard (_lineRenderer.textureMode = ...) but i don't want to mess someone else's actions :)
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: Fat Pug Studio on May 30, 2017, 07: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.
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: tcmeric on May 30, 2017, 08: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
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: cel on July 21, 2017, 09: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
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: arkdzo on August 04, 2017, 05:55:23 PM
Unity 2017.1.0p2.. Start, End Colors not working.. Always brown color  :-[
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: szomaza on February 16, 2019, 06: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
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: szomaza on February 22, 2019, 11: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!
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: jeanfabre on February 27, 2019, 01:59:54 AM
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
Title: Re: Draw Line 1.1 [last update: 18.05.2015]
Post by: szomaza on March 09, 2019, 05: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.