Esempio n. 1
0
        private void BuildAssetTags()
        {
            List <string> filesTag = new List <string>(PYBundleManager.GetAssetsTag());
            List <string> files    = new List <string>();

            for (int i = 0; i < filesTag.Count; i++)
            {
                string tag  = filesTag[i].Split(':')[0].TrimEnd(' ');
                string type = filesTag[i].Split(':')[1].TrimStart(' ');
                type = type.Split(new string[] { "<||>" }, StringSplitOptions.None)[0];
                files.Add(type + "_" + tag);
            }

            files.Sort();
            files = files.Distinct().ToList();

            string content = "public enum PYBundleTags {\n";

            for (int i = 0; i < files.Count; i++)
            {
                content += "\t" + files[i] + ",\n";
            }
            content += "}\n\n";

            content += "public static class PYBundlesTagsExtension\n{\n";
            content += "\tpublic static string ToStringTag(this PYBundleTags assetTag)\n\t{\n";
            content += "\t\tstring tag = assetTag.ToString();\n\t\ttag = tag.Remove(0, tag.IndexOf('_') + 1);\n";
            content += "\t\treturn tag;\n\t}\n}";

            string assetTag = Directory.GetFiles(Application.dataPath, "PYBundleTags.cs", SearchOption.AllDirectories)[0];

            File.WriteAllText(assetTag, content);
            AssetDatabase.Refresh();
        }
Esempio n. 2
0
        void BuildTags()
        {
            targetRef.Audios.Clear();
            UpdateAudioManagerGroups();

            List <string> files          = new List <string>();
            List <string> filesBundle    = new List <string>(PYBundleManager.GetAssetsTag().Where(s => s.EndsWith("Audio")));
            List <string> filesResources = new List <string>();

            try
            {
                filesResources.AddRange(Directory.GetFiles(Application.dataPath, "*.mp3", SearchOption.AllDirectories));
                filesResources.AddRange(Directory.GetFiles(Application.dataPath, "*.wav", SearchOption.AllDirectories));
                filesResources = filesResources.Where(n => n.Contains(@"Resources\" + AUDIO_RESOURCE_FOLDER) && (n.EndsWith(".mp3") || n.EndsWith(".wav"))).ToList();
            }
            catch { }

            foreach (string dir in filesResources)
            {
                // Filter paths to just relative path to Unity Resource folder
                string filePath = dir.Replace(dir.Substring(0, dir.IndexOf(@"Resources\" + AUDIO_RESOURCE_FOLDER)), "")
                                  .Replace(@"Resources\" + AUDIO_RESOURCE_FOLDER, "");

                filePath = filePath.Replace(".mp3", "").Replace(".wav", "");
                filePath = filePath.Replace(@"\", "_").Remove(0, 1);

                PYGroupTag groupTag = (PYGroupTag)System.Enum.Parse(typeof(PYGroupTag), filePath.Split('_')[0]);
                targetRef.Audios.Add(new PYAudioManager.AudioTrack(filePath, groupTag, AUDIO_RESOURCE_FOLDER + "/" + filePath.Replace("_", @"/")));

                files.Add(filePath);
            }
            filesBundle.ForEach((n) => files.Add("B_" + n.Replace(" : Audio", "")));

            // Read PYAudioTags script
            List <TagData> audioTags = GetAudioTagDataFromScript();

            // Find obsolete tags
            foreach (TagData tagData in audioTags)
            {
                tagData.IsObsolete = (!files.Contains(tagData.Tag) && tagData.Tag != "None");
            }

            // Add new tags
            foreach (string tag in files)
            {
                if (audioTags.Find(i => i.Tag == tag) == null && tag != "None")
                {
                    audioTags.Add(new TagData(tag, false));
                }
            }

            // If the None tag wasn't in list we add it
            if (audioTags.Find(i => i.Tag == "None") == null)
            {
                audioTags.Add(new TagData("None", false));
            }

            WriteAudioTagsOnScript(audioTags);
        }
Esempio n. 3
0
        void ShowPYPlayer(PYPlayer elem)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            elem.IsShowingElement = EditorGUILayout.Foldout(elem.IsShowingElement, string.Format(AUDIO_ITEM_NAME, elem.Name, elem.GetType().ToString()));
            if (GUILayout.Button("-", GUILayout.Width(40)))
            {
                Undo.RecordObject(target, "Removed Elem");
                _target.Audios.Remove(elem);

                EditorUtility.SetDirty(target);
                return;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUILayout.BeginVertical();
            if (elem.IsShowingElement)
            {
                if (elem is PYPlayerTag)
                {
                    PYPlayerTag playerTag = (PYPlayerTag)elem;
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("PYAudio Tag");
                    if (GUILayout.Button(playerTag.Tag.ToString()))
                    {
                        PYSelectorWindow.Init(_rectButtonTag, playerTag.Tag.ToString(),
                                              Enum.GetNames(typeof(PYAudioTags)), (selectedItem) =>
                        {
                            playerTag.Tag = (PYAudioTags)Enum.Parse(typeof(PYAudioTags), selectedItem.Value);
                        });
                    }

                    GUILayout.EndHorizontal();
                }
                else if (elem is PYPlayerClip)
                {
                    PYPlayerClip playerClip = (PYPlayerClip)elem;
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Asset Tag");
                    string tag = string.IsNullOrEmpty(playerClip.AssetTag.UnprocessedTag) ?
                                 "None" : playerClip.AssetTag.UnprocessedTag.Split(':')[0];
                    if (GUILayout.Button(tag))
                    {
                        string[] tags = PYBundleManager.GetAssetsTag();
                        tags = tags.Where(t => t.Contains(": Audio")).ToArray();

                        PYSelectorWindow.Init(_rectButtonTag, tag, tags, (selectedItem) =>
                        {
                            playerClip.AssetTag.UnprocessedTag = selectedItem.Value;
                        });
                    }

                    GUILayout.EndHorizontal();
                }

                if (Event.current.type == EventType.Repaint)
                {
                    _rectButtonTag = GUILayoutUtility.GetLastRect();
                }

                elem.DrawInspector();
                GUILayout.Space(5);
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Esempio n. 4
0
 void OnEnable()
 {
     _target = (PYBundleManager)target;
 }
Esempio n. 5
0
        // 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);

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

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            // Calculate rects
            var tagButtonRect = new Rect(position.x, position.y, position.width, position.height);

            SerializedProperty unprocessedTag = property.FindPropertyRelative("UnprocessedTag");
            string             tag            = string.IsNullOrEmpty(unprocessedTag.stringValue) ?
                                                "None" : unprocessedTag.stringValue.Split(':')[0];

            if (GUI.Button(tagButtonRect, tag))
            {
                string[] tags = PYBundleManager.GetAssetsTag();

                _currentType = PYBundleManager.GetTypeByRealType(property.serializedObject.targetObject);
                if (!string.IsNullOrEmpty(_currentType))
                {
                    tags = tags.Where(FilterTag).ToArray();
                }

                // Create a description for each tag, if exist any
                string[] tagsDescriptions = new string[tags.Length];
                for (int x = 0; x < tags.Length; x++)
                {
                    string[] tagSplit = tags[x].Split(new string[] { "<||>" }, StringSplitOptions.None);

                    if (tagSplit.Length > 1)
                    {
                        tags[x]             = tagSplit[0];
                        tagsDescriptions[x] = tagSplit[1];
                    }
                    else
                    {
                        tagsDescriptions[x] = "";
                    }
                }

                PYSelectorWindow.Init(tagButtonRect, tag, tags,
                                      tagsDescriptions, (selectedItem) =>
                {
                    unprocessedTag.stringValue = selectedItem.Value;

                    property.serializedObject.ApplyModifiedProperties();
                    property.serializedObject.Update();
                });
            }

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

            EditorGUI.EndProperty();
        }