Example #1
0
        private void DoSendEvents()
        {
            if (sendEvent == null)
            {
                UnityEngine.Debug.LogError("'Send Event' is empty in " + LogPath() + "!");
                return;
            }

            switch (eventTarget)
            {
            case FsmEventTarget.EventTarget.Self:
                Send(Fsm.FsmComponent, sendEvent);
                break;

            case FsmEventTarget.EventTarget.GameObject:

                if (gameObjects.Length == 0)
                {
                    UnityEngine.Debug.LogError("No GameObjects set in " + LogPath() + "!");
                    return;
                }

                foreach (var item in gameObjects)
                {
                    if (item.IsNone)
                    {
                        continue;
                    }

                    if (!item.Value)
                    {
                        UnityEngine.Debug.LogError("Some GameObjects are null in " + LogPath() + "!");
                        return;
                    }

                    if (!item.Value.GetComponent <PlayMakerFSM>())
                    {
                        UnityEngine.Debug.LogError("GameObject " + item.Value.name + " in " + LogPath()
                                                   + " doesn't have a PlayMakerFSM component to send to!");
                        return;
                    }

                    Fsm.BroadcastEventToGameObject(item.Value, sendEvent.ToString(), sendToChildren.Value);
                }
                break;

            case FsmEventTarget.EventTarget.GameObjectFSM:

                if (gameObjects.Length == 0)
                {
                    UnityEngine.Debug.LogError("No GameObjects set in " + LogPath() + "!");
                    return;
                }

                foreach (var item in gameObjects)
                {
                    if (item.IsNone)
                    {
                        continue;
                    }

                    if (!item.Value)
                    {
                        UnityEngine.Debug.LogError("Some GameObjects are null in " + LogPath() + "!");
                        return;
                    }

                    if (!item.Value.GetComponent <PlayMakerFSM>())
                    {
                        UnityEngine.Debug.LogError("GameObject " + item.Value.name + " in " + LogPath()
                                                   + " doesn't have a PlayMakerFSM component to send to");
                        return;
                    }

                    foreach (var currComponent in item.Value.GetComponents <PlayMakerFSM>())
                    {
                        if (FSMName.Value != "")
                        {
                            if (currComponent.FsmName != FSMName.Value)
                            {
                                continue;
                            }
                        }

                        Send(currComponent, sendEvent);
                    }
                }
                break;

            case FsmEventTarget.EventTarget.FSMComponent:

                if (fsmComponents.Length == 0)
                {
                    UnityEngine.Debug.LogError("No FSMComponents in " + LogPath() + "set!");
                    return;
                }

                int i = 0;
                foreach (var item in fsmComponents)
                {
                    if (item.IsNone)
                    {
                        continue;
                    }

                    i++;
                    if (item != null)
                    {
                        Send(item.Value as PlayMakerFSM, sendEvent);
                    }
                    else
                    {
                        UnityEngine.Debug.LogError("FSM-Component #" + (i + 1).ToString()
                                                   + " in " + LogPath() + " is Null!");
                    }
                }
                break;

            case FsmEventTarget.EventTarget.BroadcastAll:
                if (!sendEvent.IsGlobal)
                {
                    UnityEngine.Debug.LogError("You are trying to broadcast an event that isn't global in "
                                               + LogPath() + "!");
                    return;
                }

                Fsm.BroadcastEvent(sendEvent, excludeSelf.Value);
                break;

            case FsmEventTarget.EventTarget.HostFSM:
                if (Fsm.Host == null)
                {
                    UnityEngine.Debug.LogError("Current FSM from "
                                               + LogPath() + " isn't a SubFSM!");
                    return;
                }

                Send(Fsm.Host.FsmComponent, sendEvent);
                break;

            case FsmEventTarget.EventTarget.SubFSMs:
                if (Fsm.GetSubFsm(subFSMName.Value) == null)
                {
                    UnityEngine.Debug.LogError("Current FSM from "
                                               + LogPath() + " doesn't have a SubFSM called "
                                               + subFSMName.Value + "!");
                    return;
                }

                Send(Fsm.GetSubFsm(subFSMName.Value).FsmComponent, sendEvent);
                break;

            default:
                break;
            }
        }