Example #1
0
    /// <summary>
    /// Raises the passed in <see cref="IntGameEvent"/>, after confirming
    /// the name is valid.
    /// </summary>
    /// <param name="eventName">The name of the event.</param>
    /// <param name="value">The int value the event is passing in with.</param>
    public void RaiseIntEvent(string eventName, int value)
    {
        //Raise the Int event if not null, else print an error.
        IntGameEvent intEvent = this.GetIntEvent(eventName);

        if (!intEvent)
        {
            Debug.LogError("ERROR: Invalid Int Event name: " + eventName + ". Double check Event Constants/your spelling.");
        }
        else
        {
            this.GetIntEvent(eventName).Raise(value);
        }
    }
Example #2
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        EditorGUILayout.HelpBox("This Game-Event passes along a single integer value", MessageType.Info, true);
        IntGameEvent e = (IntGameEvent)target;

        GUI.enabled  = Application.isPlaying;
        e.debugValue = EditorGUILayout.IntField("Debug Value", e.debugValue);
        if (GUILayout.Button("Raise Event"))
        {
            e.Raise(e.debugValue);
            e.DebugMessage();
        }
    }
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            Rect buttonPosition  = new Rect(position.x, position.y + 5, position.width, 30);
            Rect idInputPosition = new Rect(position.x, buttonPosition.y + 35, position.width, 25);

            this.instanceId = EditorGUI.IntField(idInputPosition, this.instanceId);

            bool clicked = GUI.Button(buttonPosition, "Raise Event");

            if (clicked)
            {
                IntGameEvent gameEvent = property.objectReferenceValue as IntGameEvent;
                gameEvent?.Raise(this.instanceId);
                if (gameEvent != null)
                {
                    Debug.Log("Successfully raised event");
                }
            }

            var newPos = new Rect(idInputPosition.x, idInputPosition.y + 35, position.width, 25);

            EditorGUI.PropertyField(newPos, property, GUIContent.none);

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();
        }