Hi,
I try to convert my game for playmaker and i find the best way to initialize a state with a complex behaviour.
I have used another FSM System before playmaker and this is my init code for my shop :
public override void InitState()
{
base.InitState();
// Init shop elements
shopElements = new Dictionary<tk2dUIItem, ShopElement>();
// Retrieve buttons
middleCenterAnchor = GameObject.Find("MiddleCenterAnchor");
shopObject = GameObject.Find("Shop");
closeButton = shopObject.transform.Find ("ShopCloseButton").GetComponent<tk2dUIItem>();
scrollableArea = shopObject.GetComponentInChildren<tk2dUIScrollableArea>();
scrollContent = scrollableArea.transform.Find("Content");
// Store initial position
initialPosition = shopObject.transform.localPosition;
// Load Buildings
int i = 0;
foreach (string prefabName in DungeonParkGame.Data.BuildingPrefabNames)
{
// Retrieve each positions
GameObject buildingObject = ((GameObject)GameObject.Instantiate(Resources.Load(DungeonParkGame.Config.BuildingsPrefabDirectory + prefabName)));
tk2dUIItem buildingButton = CreateBuildingButton(prefabName, i, buildingObject);
// Register event
buildingButton.OnClickUIItem += OnBuildingClick;
// Register the index associated to the item
shopElements.Add(buildingButton, new ShopElement() { prefab = prefabName });
// Update i
i++;
}
// Update the scroll bar area
scrollableArea.ContentLength = i * 300;
}
private tk2dUIItem CreateBuildingButton(string name, int buttonIndex, GameObject buildingObject)
{
// Instanciate a radio button
tk2dUIItem buildingButtonInstance = ((GameObject)GameObject.Instantiate(Resources.Load(DungeonParkGame.Config.ShopPrefabDirectory + "BuildingButton"))).GetComponent<tk2dUIItem>();
buildingButtonInstance.name = "BuildingButton" + buttonIndex;
// Attach the building object to the building button
buildingObject.name = name;
buildingObject.transform.parent = buildingButtonInstance.transform;
buildingObject.transform.localPosition = new Vector3(-96, -16, -1);
// Deactivate some rotation
for (int i = 90; i <= 270; i += 90)
{
buildingObject.transform.Find(i.ToString()).gameObject.SetActiveRecursively(false);
}
// Attach the building to the scroll content
buildingButtonInstance.transform.parent = scrollContent.transform;
buildingButtonInstance.transform.localPosition = new Vector3(300 * (buttonIndex + 1), -160, -1);
return buildingButtonInstance;
}
I use 2dtoolkit and special stuff to load my items in the shop. My question is : is it better to try to reproduce this code in the playmaker editor (i don't know if it's really possible ?) or is it better to keep my script and add this script with the AddScript actions or create a specific action for this initialization or another way ?
Thank you in advance