Hi guys,
For the past 2 weeks i've been trying to make a custom action for the webcam using the webcamera texture feature of unity. with help from jean we were able to get it to work within playmaker, I decided to have a set of actions for this, setup camera, get propereties, play. pause and stop...all is well we can setup the camera, play it... but stopping it doesn't work.... sometimes it does stop but then I can't get it to play again...
To try this, add an object to your scene, give it a material, attach the setupcamera (available fromthe camera section, didn't have time to change the category) cameraid should be 0 for your default camera and then use the play action in the webcamera category... if your image is mirrored scale your object to negative values (ex. if your object is 10x10x10 scale it to -10x-10x-10)
Have a look at the code below... it's a mess I know... I'm just trying to learn at the moment... and if you can fix it or come up with a solution please do....
setupcamera:
import System;
import HutongGames.PlayMaker;
@ActionCategory(ActionCategory.Camera)
@Tooltip("Sets up the Webcamera")
public class setupWebcamera extends FsmStateAction{
@UIHint(UIHint.Variable)
public var gameobject : FsmOwnerDefault;
@UIHint(UIHint. Variable)
public var cameraId : FsmInt;
@UIHint(UIHint. Variable)
public var width : FsmInt;
@UIHint(UIHint. Variable)
public var height : FsmInt;
@UIHint(UIHint. Variable)
public var framesPerSecond : FsmInt;
public function Reset(){
gameobject = null;
cameraId = null;
width = null;
height = null;
framesPerSecond = null;
}
public function OnEnter(){
var dev : WebCamDevice[];
var deviceName : String;
var wct : WebCamTexture;
var resultString : String;
dev = WebCamTexture.devices;
deviceName = dev[cameraId.Value].name;
wct = new WebCamTexture(deviceName, width.Value, height.Value, framesPerSecond.Value);
var go : GameObject = Fsm.GetOwnerDefaultTarget(gameobject);
if (go == null)
{
return;
}
go.renderer.material.mainTexture = wct;
}
}
Play camera:
import System;
import HutongGames.PlayMaker;
@ActionCategory("Webcamera")
@Tooltip("Streams video from the installed Webcamera(s)")
public class playWebcamera extends FsmStateAction{
@UIHint(UIHint.Variable)
public var gameobject : FsmOwnerDefault;
@UIHint(UIHint. Variable)
public var cameraId : FsmInt;
public function Reset(){
gameobject = null;
cameraId = null;
}
public function OnEnter(){
var dev : WebCamDevice[];
var deviceName : String;
var wct : WebCamTexture;
var resultString : String;
dev = WebCamTexture.devices;
deviceName = dev[cameraId.Value].name;
wct = WebCamTexture(deviceName);
var go : GameObject = Fsm.GetOwnerDefaultTarget(gameobject);
if (go == null)
{
return;
}
go.renderer.material.mainTexture = wct;
wct.Play();
}
}
Stop camera:
import System;
import HutongGames.PlayMaker;
@ActionCategory("Webcamera")
@Tooltip("Stops video from the installed Webcamera(s)")
public class stopWebcamera extends FsmStateAction{
@UIHint(UIHint.Variable)
public var gameobject : FsmOwnerDefault;
public var cameraId : FsmInt;
public function Reset(){
gameobject = null;
cameraId = null;
}
public function OnEnter(){
var dev : WebCamDevice[];
var deviceName : String;
var wct : WebCamTexture;
var resultString : String;
dev = WebCamTexture.devices;
deviceName = dev[cameraId.Value].name;
wct = WebCamTexture(deviceName);
var go : GameObject = Fsm.GetOwnerDefaultTarget(gameobject);
if (go == null)
{
LogError("Missing gameobject");
return;
}
wct.Stop();
The pause code is the same as the stop camera action except that the last line is wct.Pause():
thanks for your help