Пример #1
0
    /// <summary>
    /// Creates a game object property for a <see cref="UIControl"/>. (This method replaces
    /// <see cref="GameObject.CreateProperty{T}"/> of the <see cref="GameObject"/> class.)
    /// </summary>
    /// <typeparam name="T">The type of the property value.</typeparam>
    /// <param name="ownerType">The control type.</param>
    /// <param name="name">The name of the property.</param>
    /// <param name="category">The category of the property.</param>
    /// <param name="description">The description of the property.</param>
    /// <param name="defaultValue">The default value.</param>
    /// <param name="options">The <see cref="UIPropertyOptions"/>.</param>
    /// <returns>The ID of the created property</returns>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="ownerType"/> is <see langword="null"/>.
    /// </exception>
    public static int CreateProperty<T>(Type ownerType, string name, string category,
      string description, T defaultValue, UIPropertyOptions options)
    {
      if (ownerType == null)
        throw new ArgumentNullException("ownerType");

      // Create normal GameProperty<T>.
      int propertyId = CreateProperty(name, category, description, defaultValue).Id;

      // Get stored properties (or default value).
      UIPropertyOptions existingOptions = _uiPropertyOptions.Get(propertyId);

      // To keep it simple: We store the "sum" of all options. If ControlA sets "X" to 
      // AffectMeasure, and ControlB sets "X" to AffectArrange, then "X" will be set 
      // AffectMeasure|AffectArrange for all controls.
      _uiPropertyOptions.Set(propertyId, existingOptions | options);

      // Get property list for ownerType.
      List<IUIProperty> properties;
      if (!_propertiesPerType.TryGetValue(ownerType, out properties))
      {
        // ownerType is not yet registered.
        properties = new List<IUIProperty>();
        _propertiesPerType.Add(ownerType, properties);
      }

      // Add property to list of ownerType's properties.
      properties.Add(new UIProperty<T> { Name = name });

      return propertyId;
    }
Пример #2
0
 /// <summary>
 /// Sets the <see cref="UIPropertyOptions"/> of a game object property.
 /// </summary>
 /// <param name="propertyId">The ID of the game object property.</param>
 /// <param name="options">The options.</param>
 public static void SetPropertyOptions(int propertyId, UIPropertyOptions options)
 {
   _uiPropertyOptions.Set(propertyId, options);
 }