Esempio n. 1
0
 public Round(
     RythmInfo _Rythm,
     AudioClip _Background,
     AudioClip _Sample,
     AudioController _AudioController
     )
 {
     m_Rythm           = _Rythm;
     m_Background      = _Background;
     m_Sample          = _Sample;
     m_AudioController = _AudioController;
 }
    public static void AddToRythmStore(RythmInfo _Rythm, int _Level, bool _ReplaceSameName = true)
    {
        AssetDatabase.AddObjectToAsset(_Rythm, GameAudioSettings.Instance);
        AssetDatabase.SaveAssets();

        SerializedObject   rythmStoreObj = new SerializedObject(GameAudioSettings.Instance);
        SerializedProperty levels        = rythmStoreObj.FindProperty("m_Levels");
        SerializedProperty prop;

        if (_Level < levels.arraySize)
        {
            prop = levels.GetArrayElementAtIndex(_Level).FindPropertyRelative("Rhythms");
        }
        else
        {
            levels.arraySize = _Level + 1;
            prop             = levels.GetArrayElementAtIndex(_Level).FindPropertyRelative("Rhythms");
        }

        bool replaced = false;

        if (_ReplaceSameName)
        {
            for (int i = 0; i < prop.arraySize; i++)
            {
                SerializedProperty element = prop.GetArrayElementAtIndex(i);
                if (element.objectReferenceValue != null && element.objectReferenceValue.name == _Rythm.name)
                {
                    Object.DestroyImmediate(element.objectReferenceValue, true);
                    element.objectReferenceValue = _Rythm;
                    replaced = true;
                    break;
                }
            }
        }

        if (!replaced)
        {
            prop.arraySize++;
            prop.GetArrayElementAtIndex(prop.arraySize - 1).objectReferenceValue = _Rythm;
        }


        rythmStoreObj.ApplyModifiedProperties();
    }
Esempio n. 3
0
    public static void ConvertToRythm(int _Level)
    {
        var selectedObjects = Selection.objects;

        if (selectedObjects == null || selectedObjects.Length == 0)
        {
            Debug.Log("No animation clips selected");
            return;
        }

        int clipsNum = selectedObjects.Length;

        for (int c = 0; c < clipsNum; c++)
        {
            string assetPath = AssetDatabase.GetAssetPath(selectedObjects[c]);
            var    bundle    = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
            if (bundle != null)
            {
                foreach (var obj in bundle)
                {
                    if (obj is AnimationClip)
                    {
                        AnimationClip clip = obj as AnimationClip;

                        RythmInfo rythm = ScriptableObject.CreateInstance <RythmInfo>();
                        rythm.name = selectedObjects[c].name;
                        SerializedObject     rythmObject   = new SerializedObject(rythm);
                        EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(clip);
                        foreach (var binding in curveBindings)
                        {
                            if (binding.propertyName == "m_LocalPosition.y")
                            {
                                AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, binding);
                                foreach (var key in curve.keys)
                                {
                                    if (!Mathf.Approximately(key.value, 0f))
                                    {
                                        SerializedProperty prop = rythmObject.FindProperty("m_Ticks");
                                        prop.arraySize++;
                                        prop.GetArrayElementAtIndex(prop.arraySize - 1).floatValue = key.time;
                                    }
                                }
                            }
                        }

                        rythmObject.FindProperty("m_Length").floatValue = clip.length;
                        rythmObject.ApplyModifiedProperties();
                        //string ap = AssetDatabase.GetAssetPath(clip);
                        //int slash = ap.LastIndexOf("/");
                        //string newPath = ap.Remove(slash + 1, ap.Length - slash - 1) + selectedObjects[c].name + ".asset";
                        //AssetDatabase.CreateAsset(rythm, newPath);

                        EditorUtility.AddToRythmStore(rythm, _Level);
                    }
                }
            }
        }

        Selection.activeInstanceID = GameAudioSettings.Instance.GetInstanceID();

        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();
    }