Esempio n. 1
0
 //Plays click sound if button is enabled
 private void PlaySound(Button button, AudioKey soundKey)
 {
     if (button.interactable)
     {
         PlaySound(soundKey);
     }
 }
Esempio n. 2
0
 public void PlaySound(AudioKey soundKey)
 {
     if (SettingsManager.Instance.SoundOn)
     {
         Array.Find(audioList, d => d.key == soundKey).source.Play();
     }
 }
Esempio n. 3
0
 public void PlayAudio(AudioKey key)
 {
     if (m_audioDictionary.ContainsKey(key))
     {
         m_sfxAudioSource.PlayOneShot(m_audioDictionary[key]);
     }
 }
        public static AudioClip Load(AudioKey InAudioKey)
        {
#if UNITY_EDITOR
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (!AudioConfig.USE_ASSET_BUNDLE_IN_EDITOR_B)
            {
                if (_keyForFullname == null)
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo("Assets/Bundle/Audio");
                    FileInfo[]    files         = directoryInfo.GetFiles();
                    int           count         = files.Length;
                    _keyForFullname = new Dictionary <string, string>(count);
                    for (int i = 0; i < count; i++)
                    {
                        if (files[i].Extension == ".meta")
                        {
                            continue;
                        }

                        string fullname = files[i].Name;
                        _keyForFullname.Add(Path.GetFileNameWithoutExtension(fullname), fullname);
                    }
                }

                if (_keyForFullname.TryGetValue(InAudioKey.ToString(), out var filename))
                {
                    return(UnityEditor.AssetDatabase.LoadAssetAtPath <AudioClip>(Path.Combine("Assets/Bundle/Audio/",
                                                                                              filename)));
                }

                Debug.LogError($"Audio clip named '{InAudioKey}' not found in .");

                return(null);
            }
#endif
            string fileName   = InAudioKey.ToString();
            string bundleName = fileName.ToLower();

            string localPath =
                UnityPathTools.GetPersistentDataPath(
                    $"b22f0418e8ac915eb66f829d262d14a2/{MD5Tools.GetStringMd5(bundleName)}");

            string streamPath = UnityPathTools.GetStreamingAssetsPath($"Audio/{MD5Tools.GetStringMd5(bundleName)}");

            AssetBundle ab = AssetBundle.LoadFromFile(File.Exists(localPath) ? localPath : streamPath);

            if (ab == null)
            {
                return(null);
            }

            AudioClip ac = ab.LoadAsset <AudioClip>(fileName);

            ab.Unload(false);

            return(ac);
        }
Esempio n. 5
0
    public AudioEntry GetAudioClip(AudioKey key)
    {
        if (!this.audioByKey.TryGetValue(key, out var audioEntry))
        {
            Debug.LogError($"Couldn't find the corresponding audio entry for the key {key}");
            return(null);
        }

        return(audioEntry);
    }
Esempio n. 6
0
    public void PlayAudio(AudioSource source, AudioKey key)
    {
        switch (key)
        {
        case AudioKey.AcelerationStart:
            source.PlayOneShot(AcelerationStart);
            break;

        case AudioKey.Crash:
            source.PlayOneShot(Crash);
            break;

        case AudioKey.Door:
            source.PlayOneShot(Door);
            break;

        case AudioKey.Fire:
            source.clip = Fire;
            source.Play();
            break;

        case AudioKey.FireStopped:
            source.PlayOneShot(FireStopped);
            break;

        case AudioKey.Idle:
            source.PlayOneShot(Idle);
            break;

        case AudioKey.Repair:
            source.PlayOneShot(Repair);
            break;

        case AudioKey.Ambient:
            source.clip = Ambient;
            source.Play();
            break;

        case AudioKey.Spin:
            source.PlayOneShot(Spin);
            break;
        }
    }
Esempio n. 7
0
        IEnumerator DoConvertTake(AMTakeData oldTake, Take newTake, bool isMeta, string assetPath)
        {
            newTake.name            = oldTake.name;
            newTake.frameRate       = oldTake.frameRate;
            newTake.endFramePadding = oldTake.endFramePadding;
            newTake.numLoop         = oldTake.numLoop;
            newTake.loopMode        = oldTake.loopMode;
            newTake.loopBackToFrame = oldTake.loopBackToFrame;
            newTake.trackCounter    = oldTake.track_count;
            newTake.groupCounter    = oldTake.group_count;

            //go through groups
            newTake.rootGroup            = new Group();
            newTake.rootGroup.group_name = oldTake.rootGroup.group_name;
            newTake.rootGroup.group_id   = oldTake.rootGroup.group_id;
            newTake.rootGroup.elements   = new List <int>(oldTake.rootGroup.elements);
            newTake.rootGroup.foldout    = oldTake.rootGroup.foldout;

            newTake.groupValues = new List <Group>();
            foreach (var oldGroup in oldTake.groupValues)
            {
                var newGroup = new Group();
                newGroup.group_name = oldGroup.group_name;
                newGroup.group_id   = oldGroup.group_id;
                newGroup.elements   = new List <int>(oldGroup.elements);
                newGroup.foldout    = oldGroup.foldout;

                newTake.groupValues.Add(newGroup);
            }

            //go through tracks
            newTake.trackValues = new List <Track>();
            foreach (var oldTrack in oldTake.trackValues)
            {
                AddMessage("  - convert track: " + oldTrack.name);

                Track newTrack = null;

                if (oldTrack is AMAnimationTrack)
                {
                    newTrack = new UnityAnimationTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMAnimationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new UnityAnimationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.wrapMode      = oldKey.wrapMode;
                        newKey.amClip        = oldKey.amClip;
                        newKey.crossfade     = oldKey.crossfade;
                        newKey.crossfadeTime = oldKey.crossfadeTime;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMAudioTrack)
                {
                    newTrack = new AudioTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMAudioKey oldKey in oldTrack.keys)
                    {
                        var newKey = new AudioKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.audioClip = oldKey.audioClip;
                        newKey.loop      = oldKey.loop;
                        newKey.oneShot   = oldKey.oneShot;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMCameraSwitcherTrack)
                {
                    newTrack = new CameraSwitcherTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    for (int i = 0; i < oldTrack.keys.Count; i++)
                    {
                        var oldKey = (AMCameraSwitcherKey)oldTrack.keys[i];
                        var newKey = new CameraSwitcherKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.type                 = oldKey.type;
                        newKey.typeEnd              = oldKey.typeEnd;
                        newKey.color                = oldKey.color;
                        newKey.colorEnd             = oldKey.colorEnd;
                        newKey.cameraFadeType       = oldKey.cameraFadeType;
                        newKey.cameraFadeParameters = new List <float>(oldKey.cameraFadeParameters);
                        newKey.irisShape            = oldKey.irisShape;
                        newKey.still                = oldKey.still;
                        newKey.endFrame             = oldKey.endFrame;

                        if (isMeta)
                        {
                            newKey.SetCameraDirect(null, oldKey.cameraTargetPath);
                            newKey.SetCameraEndDirect(null, oldKey.cameraEndTargetPath);
                        }
                        else
                        {
                            newKey.SetCameraDirect(oldKey.getCamera(null), "");
                            newKey.SetCameraDirect(oldKey.getCameraEnd(null), "");
                        }

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMEventTrack)
                {
                    var newEventTrack = new EventTrack();
                    newTrack = newEventTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, false, isMeta);

                    newTrack.keys = new List <Key>();

                    string eventCompName = null;

                    //TODO: create new tracks per different components from keys
                    //for now we only allow conversion of one component, so the first key will be used.
                    foreach (AMEventKey oldKey in oldTrack.keys)
                    {
                        string keyCompName = oldKey.getComponentName();

                        if (string.IsNullOrEmpty(eventCompName))
                        {
                            if (!string.IsNullOrEmpty(keyCompName))
                            {
                                eventCompName = keyCompName;

                                AddMessage("   - EventTrack using component: " + eventCompName);

                                if (isMeta)
                                {
                                    newEventTrack.SetTargetAsComponentDirect(oldTrack.targetPath, null, eventCompName);
                                }
                                else
                                {
                                    newEventTrack.SetTargetAsComponentDirect("", oldKey.getComponentRef(), eventCompName);
                                }
                            }
                        }

                        //only add if component matched
                        if (string.IsNullOrEmpty(eventCompName) || keyCompName != eventCompName)
                        {
                            AddMessage("   - Cannot add EventKey with Component: " + eventCompName, Color.yellow);
                            continue;
                        }

                        var newKey = new EventKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.useSendMessage = oldKey.useSendMessage;
                        newKey.methodName     = oldKey.methodName;

                        newKey.parameters = new List <EventParameter>(oldKey.parameters.Count);
                        for (int i = 0; i < oldKey.parameters.Count; i++)
                        {
                            var oldParm = oldKey.parameters[i];
                            var newParm = new EventParameter();

                            ConvertEventParameter(oldParm, newParm);

                            newKey.parameters.Add(newParm);
                        }

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMGOSetActiveTrack)
                {
                    var oldGOTrack = (AMGOSetActiveTrack)oldTrack;
                    var newGOTrack = new GOSetActiveTrack();

                    newTrack = newGOTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newGOTrack.startActive = oldGOTrack.startActive;

                    newTrack.keys = new List <Key>();
                    foreach (AMGOSetActiveKey oldKey in oldTrack.keys)
                    {
                        var newKey = new GOSetActiveKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.setActive = oldKey.setActive;
                        newKey.endFrame  = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMMaterialTrack)
                {
                    var oldMatTrack = (AMMaterialTrack)oldTrack;
                    var newMatTrack = new MaterialTrack();

                    newTrack = newMatTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newMatTrack.materialIndex = oldMatTrack.materialIndex;
                    newMatTrack.property      = oldMatTrack.property;
                    newMatTrack.propertyType  = (MaterialTrack.ValueType)oldMatTrack.propertyType;

                    newTrack.keys = new List <Key>();
                    foreach (AMMaterialKey oldKey in oldTrack.keys)
                    {
                        var newKey = new MaterialKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.endFrame = oldKey.endFrame;
                        newKey.texture  = oldKey.texture;
                        newKey.vector   = oldKey.vector;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMOrientationTrack)
                {
                    newTrack = new OrientationTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMOrientationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new OrientationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        if (isMeta)
                        {
                            newKey.SetTargetDirect(null, oldKey.GetTargetPath());
                        }
                        else
                        {
                            newKey.SetTargetDirect(oldKey.GetTarget(null), "");
                        }

                        newKey.endFrame = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMPropertyTrack)
                {
                    var oldPropTrack = (AMPropertyTrack)oldTrack;
                    var newPropTrack = new PropertyTrack();

                    newTrack = newPropTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newPropTrack.valueType = (PropertyTrack.ValueType)oldPropTrack.valueType;

                    if (oldPropTrack.isPropertySet())
                    {
                        Component comp      = oldPropTrack.GetTargetComp(null);
                        string    compName  = oldPropTrack.getComponentName();
                        bool      isField   = oldPropTrack.isField;
                        string    fieldName = oldPropTrack.getMemberName();

                        if (isMeta)
                        {
                            newPropTrack.SetTargetCompDirect(null, compName, isField, fieldName);
                        }
                        else
                        {
                            newPropTrack.SetTargetCompDirect(comp, compName, isField, fieldName);
                        }
                    }

                    newTrack.keys = new List <Key>();
                    foreach (AMPropertyKey oldKey in oldTrack.keys)
                    {
                        var newKey = new PropertyKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.endFrame  = oldKey.endFrame;
                        newKey.val       = oldKey.val;
                        newKey.valString = oldKey.valString;
                        newKey.valObj    = oldKey.valObj;
                        newKey.vect4     = oldKey.vect4;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMRotationEulerTrack)
                {
                    var oldRotEulerTrack = (AMRotationEulerTrack)oldTrack;
                    var newRotEulerTrack = new RotationEulerTrack();

                    newTrack = newRotEulerTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newRotEulerTrack.axis = (AxisFlags)oldRotEulerTrack.axis;

                    newTrack.keys = new List <Key>();
                    foreach (AMRotationEulerKey oldKey in oldTrack.keys)
                    {
                        var newKey = new RotationEulerKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.rotation = oldKey.rotation;
                        newKey.endFrame = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMRotationTrack)
                {
                    newTrack = new RotationTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMRotationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new RotationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.rotation = oldKey.rotation;
                        newKey.endFrame = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMTranslationTrack)
                {
                    var oldTransTrack = (AMTranslationTrack)oldTrack;
                    var newTransTrack = new TranslationTrack();

                    newTrack = newTransTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTransTrack.pixelPerUnit = oldTransTrack.pixelPerUnit;
                    newTransTrack.pixelSnap    = oldTransTrack.pixelSnap;

                    newTrack.keys = new List <Key>();
                    foreach (AMTranslationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new TranslationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.position     = oldKey.position;
                        newKey.endFrame     = oldKey.endFrame;
                        newKey.isConstSpeed = oldKey.isConstSpeed;

                        newKey.path = new Vector3[oldKey.path.Length];
                        System.Array.Copy(oldKey.path, newKey.path, newKey.path.Length);

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMTriggerTrack)  //convert TriggerTrack to EventTrack with TriggerSignal
                {
                    var newTriggerTrack = new EventTrack();

                    newTrack = newTriggerTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, false, isMeta);

                    //grab/create signal for this trigger
                    string signalPath = GetTriggerSignalPath(assetPath);

                    TriggerSignal triggerSignal;
                    if (!mTriggerSignalLookup.TryGetValue(signalPath, out triggerSignal))
                    {
                        //try to load it if it exists
                        triggerSignal = AssetDatabase.LoadAssetAtPath <TriggerSignal>(signalPath);
                        if (!triggerSignal)
                        {
                            AddMessage("  - Creating Trigger Signal: " + signalPath);

                            triggerSignal = ScriptableObject.CreateInstance <TriggerSignal>();
                            AssetDatabase.CreateAsset(triggerSignal, signalPath);
                            AssetDatabase.SaveAssets();

                            yield return(new WaitForFixedUpdate());
                        }

                        mTriggerSignalLookup.Add(signalPath, triggerSignal);
                    }

                    newTriggerTrack.SetTargetAsObject(triggerSignal);

                    newTrack.keys = new List <Key>();
                    foreach (AMTriggerKey oldKey in oldTrack.keys)
                    {
                        var newKey = new EventKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.useSendMessage = false;
                        newKey.methodName     = "Invoke";

                        newKey.parameters = new List <EventParameter>(3);
                        newKey.parameters.Add(new EventParameter()
                        {
                            valueType = EventData.ValueType.String, val_string = oldKey.valueString
                        });
                        newKey.parameters.Add(new EventParameter()
                        {
                            valueType = EventData.ValueType.Integer, val_int = oldKey.valueInt
                        });
                        newKey.parameters.Add(new EventParameter()
                        {
                            valueType = EventData.ValueType.Float, val_float = oldKey.valueFloat
                        });

                        newTrack.keys.Add(newKey);
                    }
                }

                newTake.trackValues.Add(newTrack);

                yield return(new WaitForFixedUpdate());
            }
        }
Esempio n. 8
0
    /// <summary>
    /// Plays the audio clip with the given name
    /// </summary>
    /// <param name="name">name of the audio clip to play</param>
    public void PlaySoundEffect(AudioKey key)
    {
        var clipEntry = this.audioLibrary.GetAudioClip(key);

        this.audioSource.PlayOneShot(clipEntry.AudioClip);
    }
Esempio n. 9
0
 /// <summary>
 /// サウンドを再生する
 /// </summary>
 /// <param name="key">サウンドのキー</param>
 public void Play(AudioKey key)
 {
     _audioDatas[(int)key].Play();
 }
Esempio n. 10
0
 /// <summary>
 /// 再生中か?
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool IsPlaying(AudioKey key)
 {
     return(_audioDatas[(int)key].isPlaying);
 }
Esempio n. 11
0
 /// <summary>
 /// 再生を停止する
 /// </summary>
 /// <param name="key">サウンドのキー</param>
 public void Stop(AudioKey key)
 {
     _audioDatas[(int)key].Stop();
 }
Esempio n. 12
0
 /// <summary>
 /// サウンドを再生する
 /// 同一キーのサウンドを同時に複数鳴らすことが可能
 /// </summary>x
 /// <param name="key">サウンドのキー</param>
 public void PlayOneShot(AudioKey key)
 {
     _audioDatas[(int)key].PlayOneShot(_audioDatas[(int)key].clip);
 }
Esempio n. 13
0
 /// サウンドのボリュームを直値で変更
 public void ChangeVol(AudioKey key, float vol)
 {
     audioDatas[(int)key].volume = vol;
 }
Esempio n. 14
0
 /// サウンドをミュート解除する
 public void UnMute(AudioKey key)
 {
     audioDatas[(int)key].mute = false;
 }
Esempio n. 15
0
 /// サウンドをミュートする
 /// <param name="key">サウンドのキー</param>
 public void Mute(AudioKey key)
 {
     audioDatas[(int)key].mute = true;
 }