void Awake () { main = this; fsm = gameObject.AddComponent<StateMachine>(); fsm.state ("root") .add_child ( fsm.state ("field") .initial_function(()=>{ return StrawberryRowState.random_row(); }) .on_entry(new StateEvent((Automata a)=>{ StrawberryComponent sb = a.gameObject.GetComponent<StrawberryComponent>(); sb.Initialize(); })) , true ).add_child ( fsm.state ("drag") .on_entry(new StateEvent(()=>{ GameMessages.Log(LanguageController.controller.load_text("tutorial_pick_scroll")); }).Limit(1)) ).add_child ( fsm.state ("fall") .on_entry(new StateEvent((Automata a)=>{ Rigidbody body = a.GetComponent<Rigidbody>(); if (body != null){ body.useGravity = true; body.isKinematic = false; } })) ).add_child ( fsm.state ("hand") .on_entry(new StateEvent((Automata a)=>{ Rigidbody body = a.GetComponent<Rigidbody>(); if (body != null){ body.useGravity = false; body.isKinematic = true; } })) ).add_child ( fsm.state ("basket") ); fsm.new_transition("field_drag", (t)=>{ t.chain_from(fsm.state("field")) .chain_to (fsm.state("drag")) .add_test(new TransitionTest(()=>{ return player_state.can_pick(); })) .on_exit(new TransitionEvent(()=>{ GenerateStrawberries(1); })) .on_failure(new TransitionEvent(()=>{ GameMessages.Log(LanguageController.controller.load_text("tutorial_bend_to_pick_up")); })) .chain_auto_run(false) ; }).new_transition("fall_drag", (t)=>{ t.chain_from(fsm.state("fall")) .chain_to (fsm.state("drag")) .chain_auto_run(false) .add_test(new TransitionTest(()=>{ return player_state.can_drag(); })) ; }).new_transition("hand_drag", (t)=>{ t.chain_from(fsm.state("hand")) .chain_to (fsm.state("drag")) .chain_auto_run(false) .add_test(new TransitionTest(()=>{ return player_state.can_drag(); })) ; }).new_transition("basket_fall", (t)=>{ t.chain_from(fsm.state("basket")) .chain_to (fsm.state("fall")) .chain_auto_run(false) ; }).new_transition("drag_fall", (t)=>{ t.chain_from(fsm.state("drag")) .chain_to (fsm.state("fall")) .chain_auto_run(false) ; }).new_transition("spawn_direct", (t)=>{ t.chain_from(fsm.state("root")) .chain_to (fsm.state("fall")) .chain_auto_run(false) .on_exit(new TransitionEvent((Automata a)=>{ a.GetComponent<StrawberryComponent>().Initialize(); a.GetComponent<ObjectVisibility>().visible = true; })) ; }); loaded_prefab = Resources.Load(prefab); }