playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - GonerGames

Pages: [1]
1
Playmaker Help / Re: Creating a .txt file? [SOLVED]
« on: February 09, 2018, 02:13:45 PM »
After much testing I noticed that there was a long delay between when the file was created until it would actually be available. So i modified the script to remove this issue.

Here is the complete script including a check to see if the new file is created.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using UnityEngine;
using System.IO;
using UnityEditor; //<- added to make the AssetDatabase available.

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Files")]
[Tooltip("Write string to a File")]
public class WriteToFile : FsmStateAction
{
[RequiredField]
[Tooltip("Set the file path, for example : Assets/myfile.txt")]
public FsmString filePath;

[RequiredField]
        [UIHint(UIHint.TextArea)]
        [Tooltip("The text")]
public FsmString text;

        public FsmEvent successEvent;
        public FsmEvent failureEvent;


        public override void Reset()
{
filePath = null;
text = null;

}


public override void OnEnter()
{
            if (File.Exists(filePath.Value))
            {
                // Create an instance of StreamWriter to write text to a file.
                StreamWriter sw = new StreamWriter(filePath.Value, true);
                sw.Write(text.Value);
                sw.Close();
                Fsm.Event(successEvent);
                Finish();
            }
            else
            {
                //Stream Writer will create the file automatically
                StreamWriter sw = new StreamWriter(filePath.Value, true);
                sw.Write(text.Value);
                sw.Close();

                //re-import file and reference in editor
                AssetDatabase.ImportAsset(filePath.Value);

                //Check to see if file was created successfully
                if (File.Exists(filePath.Value))
                {
                    Debug.Log("New File Made");
                    Fsm.Event(successEvent);
                    Finish();
                }
                else
                {
                    Debug.Log("Error: File not created");
                    Fsm.Event(failureEvent);
                }
                               
            }
        }
}
}

2
Playmaker Help / Re: Activate gameobject based on a string name variable?
« on: February 07, 2018, 10:32:24 AM »
The Action Find Game Object will not return a result if the Parent object is deactivated.
One way to handle this is to create and empty game object that is always active and then put the items you want to activate/deactivate as children of this object.
eg. Parent Empty "Items"
Children - "GameObj01", "GameObj02" etc.

Then your FSM will look like

Find Game Object:
Object Name -> "Items"
With Tag -> (your tag here)
Store as "Parent_Object"

Find Child:
Game Object -> Specify -> Parent_Object
Child Name -> "Gameobj01" (or from a custom combine string)
Store -> Child_object

Activate Game Object:
Game Object -> Specify Object -> Child_Object
Activate -> On or off

3
Playmaker Help / Re: Creating a .txt file?
« on: February 03, 2018, 11:10:28 AM »
The Write to File script does not allow for creating a file.
Edit the Writeto File script to the below in the OnEnter Function
Note: This is just specific for creating a .txt file if not found and is not universal
Code: [Select]
public override void OnEnter()
{
            if (System.IO.File.Exists(filePath.Value))
            {
                // Create an instance of StreamWriter to write text to a file.
                StreamWriter sw = new StreamWriter(filePath.Value, true);
                sw.Write(text.Value);
                sw.Close();
                Fsm.Event(successEvent);
                Finish();
            }
            else
            {
                //create a .txt file if file does not exist
                File.CreateText(filePath.Value);
                //Now add in your data
                StreamWriter sw = new StreamWriter(filePath.Value, true);
                sw.Write(text.Value);
                sw.Close();
                Fsm.Event(successEvent);
                Finish();
            }
        }

4
General Discussion / Re: Activating objects between scenes
« on: January 06, 2018, 11:27:11 AM »
Use a global variable in Playmaker.
eg. Weapon 1 - Bool - True or false. (true unlocked)

You can reference global variables from any scene.


5
Playmaker Help / Re: High precision numbers with PlayMaker
« on: January 05, 2018, 08:06:02 AM »
Moving to a float would also get you a higher value allowable.
int = 2.1e+09 or 2,100,000,000
float= 3.4e+38 or 340,000,000,000,000,000,000,000,000,000,000,000,000

Converting float to string with a format 0 will remove the decimal places from showing. You can also format the string to allow the number to more human readable.

eg. 3 Billion -> 300 billion -> 3 trillion etc. instead of 3,000,000,000 -> 300,000,000,000 -> 3,000,000,000,000

If you are tracking scores above a trillion I, personally, wouldn't be too concerned that float may not give the precision you need as you are getting into massive numbers that start to lose meaning. Not a lot of people even know what comes after a Trillion  :)

Thanks

6
Playmaker Help / Re: Changing backgrounds
« on: December 23, 2017, 06:10:59 AM »
Simplest way I found to change sprites at runtime is make a c# script and use the Playmaker Call Method to access when needed. You will need to make a Resources Folder and then a sub-folder to hold your sprites. In the example we called our sub-folder test.

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

public class SpriteTest : MonoBehaviour {
   
    //this is the folder in the first level of your Resources Folder
    private string spriteFolder = "test"; //<--Change this string to match folder name

    //The number in the array where the sprite is 0,1,2 etc.
    public int spriteVersion;

    //to get the sprite render component
    private SpriteRenderer spriteR;

    //to dump the sprites into an array from the folder listed above. Note that the sprites get added in order that they are in the folder. First sprite is 0, second is 1, etc.
    private Sprite[] sprites;


// Use this for initialization
void Start () {
        //Get the renderer of the sprite that this script is on.
        spriteR = this.GetComponent<SpriteRenderer>();

        //load the sprites from the Resources Folder for the folder you specified above
        sprites = Resources.LoadAll<Sprite>(spriteFolder);
       
       
            }

    //call this function to update your sprite. use 0,1,2 etc to define which sprite you want to pull from the array.
    public void ChangeBackground(int background)
    {
       
        spriteR.sprite = sprites[background];
    }

7
Playmaker Help / Re: Install playMaker manually for every project?
« on: December 20, 2017, 12:17:29 PM »
When you create a new project in the Unity window, beside the 2/3D selection there is an add asset package button. You can select the packages to install at that time.

Thanks

8
You have your value set as INT. This has the largest value allowable of 2147483647.
Changing this to a float will allow 3.40E+38 = 34 with 37 zeros behind it.
Doubles (which are not natively supported in Playmaker or PlayerPrefs) will get you 1.7E+308 = 17 with 307 zeros behind it.

It is possible to use Doubles with Playmaker. You will need to use a script to store the Double value and then convert to string to save, load and display.

You need to save the string value into PlayerPrefs and then convert it back into a double.

quick example: (just to give an outline)

Code: [Select]
//set up variables
public double scoreCounter;
public string scoreDisplay;

//get double to string value every frame
void Update()
{
//use the scoreDisplay to show value in game - use get property to dump into FSM
scoreDisplay = DoubleToString(scoreCounter);
}

//Functions for converting Double to string or string to double - C format used for currency display
    private static string DoubleToString(double doubleValue)
    {
        return doubleValue.ToString("C");
    }

    private static double StringToDouble(string stringValue)
    {
        if (string.IsNullOrEmpty(stringValue))
            return 0d;

        return double.Parse(stringValue);
    }


EDIT: Buy EasySave 2 from the asset store. This way you can keep the string in Playmaker Globals to save and load easily.
EasySave method:
FSM to save all global variables on exit or pause
FSM to load global variables then a call method to pass the StringToDouble function.
So much easier and secure than playerprefs. (Personal Opinion)

9
Playmaker Bug Reporting / Re: Compilation error
« on: December 08, 2017, 10:38:14 AM »
I know this one is a bit old, but it just happened to us.

Scenario:
I updated to Unity 2017.2.0F3.
Opened an existing small project from 5.6
Tried to build in VS 2017 - errors with Playmaker
Noticed that the namespace for Hutong was not referencing anymore/properly in VS 2017.

Solution:
In the VS 2017 solution explorer window on right hand side, double click on your project name (not the ones with the .editor etc) -> double click references -> look for Playmaker.
In my case I had a yellow triangle in the icon. Once I clicked on the Playmaker reference once it seemed to resolve itself.

Not very technical, but I have had this work on 3 different projects now. 

10
Playmaker Tutorials / Re: Playmaker Array - Truncate / Number Formatting
« on: October 12, 2017, 07:38:45 AM »
Thanks for all the help djaydino. Great support from everyone here is the reason why I try to give back to this group.

11
Playmaker Tutorials / Re: Playmaker Array - Truncate / Number Formatting
« on: October 12, 2017, 05:04:11 AM »
Link fixed now (I hope).
just in case http://www.youtube.com/watch?v=f0CEykKZoXA

12
Playmaker Tutorials / Re: Playmaker Array - Truncate / Number Formatting
« on: October 11, 2017, 01:26:28 PM »
Just re-uploaded with better sound.  Thanks


13
Playmaker Tutorials / Playmaker Array - Truncate / Number Formatting
« on: October 11, 2017, 08:26:18 AM »
Howdy Folks,

Was working on an tap/auto increment game. Here is a simple way to format the numbers using playmaker array.  Hope you all find it helpful.


14
Playmaker Tutorials / Simple IAP and Playmaker Add Funds Button
« on: September 19, 2017, 09:33:29 AM »
Howdy Folks,

Just a quick and simple way to use Playmaker Call Method to add funds in Simple IAP.

https://youtu.be/CR54HUOrvPw


Thanks


15
Playmaker Tutorials / Simple nGUI and Playmaker Timer Related Progress Bar
« on: November 17, 2016, 11:55:27 AM »
Here is a fairly quick (10 min) tutorial on how to make a nGUI progress bar go from 0 - 100 % tracking a countdown timer without scripts.



Hope it helps some of you out

Pages: [1]