/// <summary>
 /// ReceiveDirectMessage is a message that can be sent directly between AI rather than broadcast to the
 /// entire channel
 /// </summary>
 /// <param name="aElement">The CommunicationElement of the sender</param>
 /// <param name="aChannel">The channel on which the communication is sent</param>
 /// <param name="aVariableName">A memory variable to assign</param>
 /// <param name="aValue">The value to assign to the memory variable</param>
 public virtual void ReceiveDirectMessage(CommunicationElement aElement, string aChannel, string aVariableName, object aValue)
 {
     AI.WorkingMemory.SetItem<object>(aVariableName, aValue);
 }
示例#2
0
    /// <summary>
    /// Grab the Entity on the AI, or create one if none exists.  Grab the team Aspect on the AI, or create
    /// one if none exists.  Grab the communication element on the AI, or create one if none exists.  Then
    /// set up the team.
    /// </summary>
    public override void Start()
    {
        base.Start();

        localEntity = AI.Body.GetComponentInChildren<EntityRig>();
        if (localEntity == null)
            localEntity = EntityRig.AddRig(AI.Body);

        teamAspect = localEntity.Entity.GetAspect("team") as TeamAspect;
        if (teamAspect == null)
        {
            teamAspect = new TeamAspect() { AspectName = "team" };
            if (aspectMountPoint != null)
                teamAspect.MountPoint = aspectMountPoint.transform;
            else
                teamAspect.Position += Vector3.up; //move it up off the ground

            localEntity.Entity.AddAspect(teamAspect);
        }

        commElement = AI.GetCustomElement<CommunicationElement>();
        if (commElement == null)
        {
            commElement = new CommunicationElement();
            AI.AddCustomElement(commElement);
        }

        if (string.IsNullOrEmpty(teamCommPrefix))
            teamCommPrefix = cnstDefaultTeamCommPrefix;

        SetTeam(team, true);
    }
 /// <summary>
 /// Called by channel subscribers to stop receiving broadcasts on a channel
 /// </summary>
 /// <param name="aChannel">The name of the channel to unsubscribe from</param>
 /// <param name="aSubscriber">The CommunicationElement of the AI unsubscribing</param>
 public void Unsubscribe(string aChannel, CommunicationElement aSubscriber)
 {
     if (string.IsNullOrEmpty(aChannel) || (aSubscriber == null))
         return;
     List<CommunicationElement> tElements;
     subscribers.TryGetValue(aChannel, out tElements);
     if (tElements != null)
         tElements.Remove(aSubscriber);
 }
 /// <summary>
 /// SendTo can be used to send a message directly to a receiving AI.  When this method is called, the receiver
 /// will get a ReceiveDirectMessage callback.
 /// </summary>
 /// <param name="aSender">The CommunicationElement of the sender</param>
 /// <param name="aReceiver">The CommunicationElement of the receiver</param>
 /// <param name="aChannel">The channel to send a message on.  This is just to support context for the receiver.
 /// The receiver does not need to be a subscriber.</param>
 /// <param name="aVariableName">The name of the variable the receiver will assign values to</param>
 /// <param name="aValue">The value the receiver will assign to the variable</param>
 public void SendTo(CommunicationElement aSender, CommunicationElement aReceiver, string aChannel, string aVariableName, object aValue)
 {
     if (aReceiver != null)
         aReceiver.ReceiveDirectMessage(aSender, aChannel, aVariableName, aValue);
 }
    /// <summary>
    /// Called by subscribers to listen to all broadcasts on a channel
    /// </summary>
    /// <param name="aChannel">The name of the channel to susbscribe to.  These can be totally ad-hoc.</param>
    /// <param name="aSubscriber">The CommunicationElement of the subscriber</param>
    public void Subscribe(string aChannel, CommunicationElement aSubscriber)
    {
        if (string.IsNullOrEmpty(aChannel) || (aSubscriber == null))
            return;

        List<CommunicationElement> tElements;
        subscribers.TryGetValue(aChannel, out tElements);

        if (tElements == null)
            tElements = new List<CommunicationElement>();

        if (!tElements.Contains(aSubscriber))
            tElements.Add(aSubscriber);

        subscribers[aChannel] = tElements;
    }