示例#1
0
    private void OnChat(ChatData data)
    {
        // Parse the chat message into an array of strings and look for a "/gravity" command
        var cmds = data.Message.Split(new Char[] { ' ' });

        if (cmds[0] == "/gravity")
        {
            if (cmds.Length > 1)
            {
                // Attempt to interpret the text after the command as a number
                float value;
                if (float.TryParse(cmds[1], out value))
                {
                    ScenePrivate.Chat.MessageAllUsers("Attempting to set gravity to: " + value);
                    ScenePrivate.SetGravity(value);  // Assign the scene's gravity to the number
                }
                // Otherwise reset the scene to default gravity if specified
                else if (cmds[1] == "default")
                {
                    ScenePrivate.Chat.MessageAllUsers("Setting gravity back to default.");
                    ScenePrivate.SetGravity(ScenePrivate.DefaultGravity);
                }
            }
            // If no additional parameter was specified, print out the scene's current gravity
            else
            {
                ScenePrivate.Chat.MessageAllUsers("Gravity is set to: " + ScenePrivate.GetGravity());
            }
        }
    }
    void SubscribeToMessages()
    {
        const float OneG = 9.81f;

        // Already subscribed
        if (unsubscribes != null)
        {
            return;
        }

        unsubscribes += SubscribeToAll(SetEarthGravityEvent, (data) =>
        {
            ScenePrivate.SetGravity(OneG);
        });

        unsubscribes += SubscribeToAll(SetZeroGravityEvent, (data) =>
        {
            ScenePrivate.SetGravity(0.0f);
        });

        for (int i = 0; i < GravityValues.Count; i++)
        {
            int    index = i;
            string gravityIndexEventName = SetGravityIndexEvent.Replace("{INDEX}", index.ToString());

            unsubscribes += SubscribeToAll(gravityIndexEventName, (data) =>
            {
                ScenePrivate.SetGravity(OneG * GravityValues[index]);
            });
        }
    }
示例#3
0
    public override void Init()
    {
        ScenePrivate.Chat.Subscribe(Chat.DefaultChannel, (ChatData data) =>
        {
            if (data.Message == "/setlowgrav")
            {
                AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId);

                // If the agent is the scene owner
                if ((agent != null) && (agent.AgentInfo.AvatarUuid == ScenePrivate.SceneInfo.AvatarUuid))
                {
                    // Set the gravity to 15% of earth gravity
                    ScenePrivate.SetGravity(0.15f * 9.81f);

                    // Send a private acknowledgement message back to the user
                    agent.SendChat("You set low gravity!");
                }
            }
        });
    }