コード例 #1
0
    /// <summary>
    /// Sets a given stat belonging to the actor to a specific value. This triggers StatChangedEvent on the server.
    /// </summary>
    /// <param name="_name"></param>
    /// <param name="_val"></param>
    public void SetStat(string _name, int _val)
    {
        if (entity.isOwner)
        {
            //PropertyInfo property = GetType().GetProperty(_name);
            Debug.Log(_name + " set to " + _val);

            // Get the actor's stat set. Then create a Bolt Event with the name of the stat to be change and the value to change it by.
            // Will catch NulLReferenceException if an invalid _name is given.
            try
            {
                Bolt.NetworkArray_Objects <BoltActorStat> statset = state.BoltActorStatset.Statset;

                IEnumerable <BoltActorStat> query = from stat in statset
                                                    where stat.StatName == _name
                                                    select stat;

                query.First().StatValue += _val;

                StatChangedEvent evnt = StatChangedEvent.Create(entity);
                evnt.StatName = _name;
                evnt.StatMod  = _val;
                evnt.Send();
            }
            catch (System.NullReferenceException nre)
            {
                Debug.LogError(nre);
            }
        }
    }