public void Invoke()
        {
            if (callState == UnityEventCallState.RuntimeOnly && !Application.isPlaying)
            {
                return;
            }
            if (callState == UnityEventCallState.Off)
            {
                return;
            }

            if (!methodDeleted)
            {
                if (methodInvoker != null)
                {
                    methodInvoker.Invoke(targetObject, argumentList);
                }
                else
                {
                    fieldSetter.Invoke(targetObject, argumentList[0]);
                }
            }
            else
            {
                Debug.LogWarning("Trying to invoke SerializableAction, but the serialized action target " + target.Name + " has been deleted!");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// "SuperUser DO"; debug-only message used to forcefully set attributes of a connected ship.
        /// </summary>
        public void OnSudo(NetPeer peer, Messages.Sudo data)
        {
            Console.WriteLine("Sudo: {0}", data.Json.ToString());

            LocalSpaceship ship = null;

            if (data.Json.ContainsKey("token"))
            {
                var token = (string)data.Json["token"];
                ship = QuadTreeNode.ShipsByToken.GetValueOrDefault(token, null);
                if (ship == null)
                {
                    return;
                }
            }

            foreach (var kv in data.Json)
            {
                if (kv.Key == "token")
                {
                    continue;
                }

                AttributeSetter setter = SUDO_SETTER_MAP.GetValueOrDefault(kv.Key, null);
                if (setter == null)
                {
                    Console.Error.WriteLine("Sudo: Unrecognized attribute `" + kv.Key + "`");
                    return;
                }

                try
                {
                    setter.Invoke(this, ship, kv.Value);
                }
                catch (Exception exc)
                {
                    Console.Error.WriteLine("Sudo: Failed to set attribute `" + kv.Key + "`: " + exc.ToString());
                    return;
                }
            }

            // Send the same sudo back to the arbiter as ACK
            Bus.SendMessage(data, ArbiterPeer, LiteNetLib.DeliveryMethod.ReliableOrdered);
        }