Esempio n. 1
0
 public static void RefreshSoundCatalogue()
 {
     AddressablePicker.Refresh();
 }
Esempio n. 2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        float width = position.width - x;

        EditorGUI.LabelField(new Rect(x, position.y * (Height * 0), width, Height), label);
        string labelText = label.text;

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        string AddressableType = "";

        if (property.name == "AddressableAudioSource")
        {
            AddressableType = "SoundAndMusic";
        }
        else
        {
            AddressableType = "SoundAndMusic";
        }

        bool Refresh = GUILayout.Button("Refresh catalogue");

        if (Refresh)
        {
            AddressablePicker.Refresh();
        }
        //EditorGUI.indentLevel++;
        EditorGUI.BeginChangeCheck();
        var Path           = property.FindPropertyRelative("AssetAddress");
        var AssetReference = property.FindPropertyRelative("AssetReference");

        EditorGUI.PropertyField(new Rect(x, position.y + (Height * 1), width, Height),
                                property.FindPropertyRelative("SetLoadSetting"), new GUIContent("Dispose Mode"));

        //EditorGUI.BeginDisabledGroup(true);
        EditorGUI.PropertyField(new Rect(x, position.y + (Height * 2), width, Height), Path,
                                new GUIContent("Addressable Path"));
        //EditorGUI.EndDisabledGroup();

        //UnityEngine.Object oldAssetReference = AssetReference.objectReferenceValue;
        EditorGUI.indentLevel++;
        var newsearchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));

        if (newsearchString != searchString)
        {
            //searchChange = true;
            searchString = newsearchString;
        }


        if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
        {
            // Remove focus if cleared
            searchString = "";
            GUI.FocusControl(null);
        }

        var inint = 0;

        if (searchString != "")
        {
            temarry = (AddressablePicker.options[AddressableType].Where(x =>
                                                                        x.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) >= 0)).ToArray();
            inint = temarry.ToList().IndexOf(Path.stringValue);
        }
        else
        {
            inint = AddressablePicker.options[AddressableType].ToList().IndexOf(Path.stringValue);
        }

        if (inint == -1)
        {
            inint = 0;
        }

        if (searchString != "")
        {
            _choiceIndex = EditorGUILayout.Popup(inint, temarry);
        }
        else
        {
            _choiceIndex = EditorGUILayout.Popup(inint, AddressablePicker.options[AddressableType]);
        }



        EditorGUI.indentLevel--;
        if (searchString != "")
        {
            if (temarry.Length <= _choiceIndex)
            {
                if (temarry.Length > 0)
                {
                    Path.stringValue = temarry[0];
                }
                else
                {
                    Path.stringValue = "None";
                }
            }
            else
            {
                Path.stringValue = temarry[_choiceIndex];
            }
        }
        else
        {
            Path.stringValue = AddressablePicker.options[AddressableType][_choiceIndex];
        }

        EditorGUI.PropertyField(new Rect(x, position.y + (Height * 3), width, Height), AssetReference,
                                new GUIContent("AssetReference"));

        // Drag & Drop of AssetReference doesn't seem to trigger EndChangeCheck.  So, we verify it manually.
        if (EditorGUI.EndChangeCheck())
        {
            var m_AssetRefObject =
                SerializedPropertyExtensions.GetActualObjectForSerializedProperty <AssetReference>(AssetReference,
                                                                                                   fieldInfo, ref labelText);
            var Addressable = AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(m_AssetRefObject.AssetGUID);
            if (Addressable != null)
            {
                Path.stringValue = AddressableAssetSettingsDefaultObject.Settings
                                   .FindAssetEntry(m_AssetRefObject.AssetGUID).address;
            }
        }



        //EditorGUI.indentLevel--;
        property.serializedObject.ApplyModifiedProperties();
        EditorGUI.EndProperty();
    }