using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using RPGCreationKit; using RPGCreationKit.DialogueSystem; using RPGCreationKit.BehaviourTree; using RPGCreationKit.CellsSystem; using UnityEditorInternal; namespace RPGCreationKit { public class ItemSoundsSetterEditor : EditorWindow { bool isReady = false; private List allItems; public AudioClip OnPickUp; public AudioClip OnAddedInInventory; public AudioClip OnRemovedFromInventory; public Material mat; public GameObject[] ppl; public static void ShowWindow() { EditorWindow thisWindow = GetWindow(typeof(ItemSoundsSetterEditor)); // Set Title Texture icon = AssetDatabase.LoadAssetAtPath(EditorIconsPath.RPGCKEditorWindowIcon); GUIContent titleContent = new GUIContent("ItemSoundsSetterEditor ", icon); thisWindow.titleContent = titleContent; } private void Init() { FillAllLists(); } private void OnGUI() { if (!isReady) Init(); ScriptableObject target = this; SerializedObject so = new SerializedObject(target); SerializedProperty pplprop = so.FindProperty("ppl"); mat = (Material)EditorGUILayout.ObjectField(mat, typeof(Material), true); EditorGUILayout.PropertyField(pplprop, true); // True means show children /* OnPickUp = (AudioClip)EditorGUILayout.ObjectField(OnPickUp, typeof(AudioClip), true); OnAddedInInventory = (AudioClip)EditorGUILayout.ObjectField(OnAddedInInventory, typeof(AudioClip), true); OnRemovedFromInventory = (AudioClip)EditorGUILayout.ObjectField(OnRemovedFromInventory, typeof(AudioClip), true); */ if (GUILayout.Button("GOO")) { for(int i = 0; i < ppl.Length; i++) { GameObject prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(ppl[i])); var a = prefab.transform.Find("GFX"); var head = a.Find("Head"); var upperbody = a.Find("Upperbody"); var arms = a.Find("Arms"); var hands = a.Find("Hands"); var lowerbody = a.Find("Lowerbody"); var feet = a.Find("Feet"); head.gameObject.GetComponent().material = mat; upperbody.gameObject.GetComponent().material = mat; arms.gameObject.GetComponent().material = mat; hands.gameObject.GetComponent().material = mat; lowerbody.gameObject.GetComponent().material = mat; feet.gameObject.GetComponent().material = mat; EditorUtility.SetDirty(prefab); AssetDatabase.SaveAssets(); } /* for(int i = 0; i < allItems.Count; i++) { allItems[i].sOnPickUp = OnPickUp; allItems[i].sOnAddedInInventory = OnAddedInInventory; allItems[i].sOnRemovedFromInventory = OnRemovedFromInventory; } */ } } private void OnFocus() { } private void FillAllLists() { allItems = GetAllInstances(); } public static List GetAllInstances() where T : ScriptableObject { string[] guids = AssetDatabase.FindAssets("t:" + typeof(T).Name); List a = new List(guids.Length); for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); a.Add(AssetDatabase.LoadAssetAtPath(path)); } return a; } } }