playMaker

Author Topic: EditorMode automated FSM Component Copy-Paste [SOLVED]  (Read 1672 times)

RayCornea

  • Playmaker Newbie
  • *
  • Posts: 3
EditorMode automated FSM Component Copy-Paste [SOLVED]
« on: February 18, 2018, 07:45:57 AM »
Hello, i would want to ask if there's any in editor script for syncing or to quickly copy-paste thru a specified array of gameObjects.

My situation: i have 5 characters with about 10 fsms on each. I plan on having about 40 characters, and manually copy pasting each fsm throughout them all doesn't seem too wise of an option.

ExtraDetails: can't place them into a prefab, since i'm using some trigger and collision events which must stay with the rigidbody gameObject, which has to be on the main parent

Sadly i'm not that good with in editor scripts, so any help is appreciated.
Of course it'd be best to have both options (synch current fsm, synch all fsms from this gameobject to the ones in the array), yet i'd be happy to get at least one of them working.

Progress so far:
As of now i'm only able to select current fsm via "FsmEditor.SelectedFsmComponent", however accesing variables such as arrays, or even doing a "PlayMakerFSM.FindFsmOnGameObject" always has a null result. Is there a certain way to find and access fsms while in Editor mode?

My Code
Code: [Select]
[MenuItem("Tools/Chars FsmSynch")]
public static void FsmSynchCh()
{
if (ArrHolder == null) ArrHolder = GameObject.Find("SaveLoad");

PlayMakerFSM fsmC = FsmEditor.SelectedFsmComponent;
GameObject gOwner = fsmC.gameObject;

FsmArray gList =  PlayMakerFSM.FindFsmOnGameObject(ArrHolder, ArrFsmname).FsmVariables.GetFsmArray("PrefChars");
if (fsmC != null && gOwner != null && gList.Length > 0) {
FsmS (fsmC, gList, gOwner);
}
}

static void FsmS(PlayMakerFSM fsmC, FsmArray gList, GameObject gOwner){
ComponentUtility.CopyComponent (fsmC);
for (int i = 0; i < gList.Length; i++) {
if (gList.Values [i] == null) continue;
if ((gList.Values[i] as GameObject).name == gOwner.name) continue;

PlayMakerFSM fsmT = PlayMakerFSM.FindFsmOnGameObject (gList.Values [i] as GameObject, fsmC.FsmName);
if (fsmT != null) ComponentUtility.PasteComponentValues (fsmT);
}
}
« Last Edit: February 19, 2018, 03:11:17 AM by RayCornea »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: EditorMode automated FSM Component Copy-Paste
« Reply #1 on: February 19, 2018, 02:29:19 AM »
Hi,

 what do you want to copy around this way? It sounds to me that instead what you want is an external description of your characters, where then each character would get their description file and run with it.

 If you have 5 characters, with 10 fsm each, and they are all identiccal, then you shouls use Templates, they will be shared amongst your characters.

the other solution is to have one character only, that loads its visuals and specifics on demand. This is where I would tend to.

 Bye,

 Jean

RayCornea

  • Playmaker Newbie
  • *
  • Posts: 3
Re: EditorMode automated FSM Component Copy-Paste
« Reply #2 on: February 19, 2018, 03:10:08 AM »
Why did i never used templates before

Thnx, works like a charm