Exemplo n.º 1
0
 /// <summary>
 /// Draws a field for each instance of the asset in the project.
 /// Adds buttons to add missing or remove existing values.
 /// With each asset instance a single double is assosiated.
 /// </summary>
 public static void AssetDoubleFieldAll <TAsset>(
     Func <TAsset, String> prefix,
     Func <TAsset, bool> has,
     Func <TAsset, double> get,
     Action <TAsset, double> set,
     Action <TAsset> remove,
     double newVal
     ) where TAsset : ScriptableObject
 {
     AssetPairField(
         AssetsHelpers.GetAllAssetsOfType <TAsset>(),
         prefix,
         has,
         get,
         set,
         remove,
         newVal
         );
 }
Exemplo n.º 2
0
    /// <summary>
    /// Draws a field for each instance of the asset in the project.
    /// Adds buttons to add missing or remove existing values.
    /// With each asset instance a single value is assosiated.
    /// </summary>
    public static void AssetValueDictionaryFieldAll <TAsset, TValue>(
        Dictionary <TAsset, TValue> dictionary, // the dictionary with all known associations between an asset and value
        Func <TAsset, String> prefix,           // a method to get the prefix to be used with the asset
        TValue defaultValue
        ) where TAsset : ScriptableObject
    {
        IEnumerable <TAsset> assets = AssetsHelpers.GetAllAssetsOfType <TAsset>();

        foreach (TAsset asset in assets)
        {
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PrefixLabel(prefix(asset));

            if (dictionary.ContainsKey(asset))
            {
                TValue curVal = dictionary[asset];
                TValue newVal = GenericField(curVal);
                if (!EqualityComparer <TValue> .Default.Equals(curVal, newVal))
                {
                    dictionary[asset] = newVal;
                }

                if (GUILayout.Button("-"))
                {
                    dictionary.Remove(asset);
                }
            }
            else
            {
                if (GUILayout.Button("No value, add +"))
                {
                    dictionary[asset] = defaultValue;
                }
            }
            GUILayout.EndHorizontal();
        }
    }