playMaker

Author Topic: [CustomAction]How to create drag drop box on playmaker  (Read 5327 times)

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
[CustomAction]How to create drag drop box on playmaker
« on: May 23, 2013, 03:56:07 AM »
I'm making new custom action about posting Picture on Facebook.

So I try to make custom action for it.

Code: [Select]
[UIHint(UIHint.Variable)]
//public string  message;
public FsmTexture image;
private byte upload;
#endregion


// Code that runs on entering the state.
public override void OnEnter()
{
Texture2D image = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,false);
image.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);


image.Apply();
byte[] bytes = image.EncodeToPNG();

FacebookUnityPlugin.PostPhoto(bytes);
}

Here is my code

like attached pic what i want drag and drop on texture box. 


How to do it? I open GUI button.cs but i couldn't find it. 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #1 on: May 23, 2013, 08:00:01 AM »
Hi,

 Can  you paste the whole custom action?

 The best way to achieve this is to study an action that does this already. So you give the example of "gui button" action, simply do the same as this one, To open the script, right click on the action and select "edit script", then you can simply copy paste the line where it declare the FsmTexture for the "Image" public variable

does that help?

bye,

 Jean

 

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #2 on: May 24, 2013, 02:00:29 AM »
Hi Jean !
I already opened GUI button class before post HELP
but i couldn't find which part exactly related on drag drop part.
Lack of understanding code stuff, maybe i couldn't find it.
So please would you tell me which part related on?
Here is GUI button.

Code: [Select]
using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GUI)]
[Tooltip("GUI button. Sends an Event when pressed. Optionally store the button state in a Bool Variable.")]
public class GUIButton : GUIContentAction
{
public FsmEvent sendEvent;
[UIHint(UIHint.Variable)]
public FsmBool storeButtonState;

public override void Reset()
{
base.Reset();
sendEvent = null;
storeButtonState = null;
style = "Button";
}

public override void OnGUI()
{
base.OnGUI();

bool pressed = false;

if (GUI.Button(rect, content, style.Value))
{
Fsm.Event(sendEvent);
pressed = true;
}

if (storeButtonState != null)
{
storeButtonState.Value = pressed;
}
}
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #3 on: May 24, 2013, 02:05:27 AM »
Hi,

 yes, sorry misleading here, basically it extends another class "GUIContentAction" so you need ot look up this one.


Bye,

Jean

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #4 on: May 24, 2013, 02:43:50 AM »
I found another good example, setGUItexture so i copy and paste it.
It look like works fine just like attached screenshot, but somehow my custom action only paste blue screen on facebook instead of picture that i attached.



Here is my whole custom action stuff.
What i've tried to with this custom action is
1. attached pic in playmaker fsm, that i want to paste.
2. convert that picture into png then byte.
3. upload to face book.


Code: [Select]
using UnityEngine;
using System.Collections;
using System.IO;
using HutongGames.PlayMaker;
using System.Collections.Generic;

[ActionCategory("facebook")]
public class FB_PHOSTPIC : FsmStateAction
{
#region Fields
private static string appID = ".....";

[UIHint(UIHint.Variable)]
[RequiredField]
public FsmOwnerDefault gameObject;
public FsmTexture image;//public string  message;
private byte upload;
#endregion


// Code that runs on entering the state.
public override void OnEnter()
{
Texture2D image = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,false);
//image.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);


image.Apply();
byte[] bytes = image.EncodeToPNG();

FacebookUnityPlugin.PostPhoto(bytes);
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #5 on: May 24, 2013, 03:08:21 AM »
Hi,

 Yes, well, you don't do anything with your created texture, you need inject in your texture the image you want, or get the actual texture and save it as a png bytes.

bye,

 Jean

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #6 on: May 24, 2013, 04:33:35 AM »
Thanks you jean.

I'm really sorry about keep asking newbie question like this.

I faced another problem.
my previous custom action was that post string to FB.
Code: [Select]
public FsmString stringVariable;
FacebookUnityPlugin.PostMessage(stringVariable.Value);
This way of reading Fsm value into command works fine.

but this stuff, reading Fsmtexture value to Texture 2D seemed not working.
How could I convert Fsmtexture to Texture2D?

Anyway, Thanks you for helping me alot

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: [CustomAction]How to create drag drop box on playmaker
« Reply #7 on: May 24, 2013, 05:30:14 AM »
Hi,

 maybe you simply need this:

Texture2D _text2 = xxx.GetTexture() as Texture2D;

If that doesn't help, what is the source of the texture? bear in mind some texture are read only, and there is a trick to overcome this by using RenderTexture, but you then need Unity Pro.

http://answers.unity3d.com/questions/9969/convert-a-rendertexture-to-a-texture2d.html

bye,

 Jean