예제 #1
0
 void SelectMusic()
 {
     if (selMusic == -1)
     {
         // Nothing selected
         if (soundType == 0)
         {
             musicValues.ResetValues();
         }
         else
         {
             sfxValues.ResetValues();
         }
     }
     else
     {
         // Something selected
         selMusic = Mathf.Min(currentEntryList.Length - 1, selMusic);
         if (soundType == 0)
         {
             MusicEntry me = (MusicEntry)musicLibrary.GetEntryByIndex(selMusic);
             musicValues.CopyValues(me);
         }
         else
         {
             SfxEntry se = (SfxEntry)sfxLibrary.GetEntryByIndex(selMusic);
             sfxValues.CopyValues(se);
         }
     }
 }
예제 #2
0
    /// <summary>
    /// Resets the values to default.
    /// </summary>
    public override void ResetValues()
    {
        base.ResetValues();

        activations       = new List <ModuleActivation>();
        effects           = new List <ModuleEffect>();
        startCooldownTime = 0;
        maxCharges        = 10;
        delay             = 0.1f;
        cooldown          = 5f;

        moduleType = ModuleType.OTHER;
        area       = 1.0f;
        holdMin    = -1f;
        holdMax    = 0.5f;

        projectile      = null;
        projectileSpeed = Vector2.zero;
        effectSteps     = new EffectStep[0];

        damage          = 0;
        baseDamageScale = 1f;
        multihit        = true;

        activationSound = null;
        impactSound     = null;
    }
예제 #3
0
    void InstansiateSfx()
    {
        GUI.FocusControl(null);
        if (sfxLibrary.ContainsID(uuid))
        {
            Debug.Log("uuid already exists!");
            return;
        }
        SfxEntry se = Editor.CreateInstance <SfxEntry>();

        se.name      = uuid;
        se.uuid      = uuid;
        se.entryName = uuid;
        se.repColor  = repColor;
        string path = "Assets/LibraryData/Sfx/" + uuid + ".asset";

        AssetDatabase.CreateAsset(se, path);
        sfxLibrary.InsertEntry(se, 0);
        Undo.RecordObject(sfxLibrary, "Added sfxx");
        EditorUtility.SetDirty(sfxLibrary);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        currentEntryList = sfxLibrary.GetRepresentations("", filterStr);
        uuid             = "";
        selMusic         = 0;
        SelectMusic();
    }
예제 #4
0
    public override void CopyValues(ScrObjLibraryEntry other)
    {
        base.CopyValues(other);
        SfxEntry ce = (SfxEntry)other;

        clip = ce.clip;
    }
예제 #5
0
    //Add some kind of loot table


    public override void ResetValues()
    {
        base.ResetValues();

        // General
        enemyModelN = null;
        enemyModelS = null;
        maxhp       = 1;
        speed       = new Vector2(0f, 0f);

        // AI values
        waitStates     = new List <WaitStates>();
        waitTimeLimits = new RangedFloat(3f, 5f);
        chaseTimeLimit = 30f;
        fleeDistance   = 3f;
        fleeTimeLimit  = 30f;

        // Attacking
        meleeRange       = 1f;
        attackRate       = 1f;
        attacks          = 1;
        meleeTimeStartup = 0.5f;

        //Sounds
        attackChargeSfx   = null;
        attackActivateSfx = null;
        attackImpactSfx   = null;

        // Reward
        exp   = 0;
        money = 0;
        //Add some kind of loot table
    }
예제 #6
0
    protected override void DrawContentWindow()
    {
        SfxEntry sfxValues = (SfxEntry)entryValues;

        sfxValues.entryName = EditorGUILayout.TextField("Name", sfxValues.entryName);
        sfxValues.clip      = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", sfxValues.clip, typeof(AudioClip), false);
    }
예제 #7
0
 /// <summary>
 /// Constructor for the editor window.
 /// </summary>
 /// <param name="entries"></param>
 /// <param name="container"></param>
 public MusicEditorWindow(ScrObjLibraryVariable entries, MusicEntry container, ScrObjLibraryVariable entries2, SfxEntry container2)
 {
     musicLibrary = entries;
     musicValues  = container;
     sfxLibrary   = entries2;
     sfxValues    = container2;
     LoadLibrary();
 }
예제 #8
0
 /// <summary>
 /// Plays the next sfx clip.
 /// </summary>
 /// <param name="clip">Clip.</param>
 public void PlaySfxEntry(SfxEntry entry)
 {
     if (entry != null && entry.clip != null)
     {
         RandomizePitch();
         efxSource[currentSfxTrack].clip = entry.clip;
         efxSource[currentSfxTrack].Play();
         currentSfxTrack = (currentSfxTrack + 1) % efxSource.Length;
     }
 }
예제 #9
0
    /// <summary>
    /// Displays a spinner notification with the given information.
    /// Locks the controls for the duration if lockGame is true.
    /// </summary>
    /// <param name="duration"></param>
    /// <param name="icon"></param>
    /// <param name="text"></param>
    /// <param name="lockGame"></param>
    public IEnumerator ShowSpinner(Sprite icon, string text, SfxEntry sfx, float duration = 2f, bool lockGame = true)
    {
        spinnerIcon.sprite = icon;
        messageText.text   = text;

        if (sfx != null)
        {
            sfxQueue.Enqueue(sfx);
            playSfxEvent.Invoke();
        }

        yield return(StartCoroutine(DisplaySpinner(duration, lockGame)));
    }
예제 #10
0
    /// <summary>
    /// Shows the popup with the given text and icon.
    /// Uses the default duration and cooldown.
    /// </summary>
    /// <param name="icon"></param>
    /// <param name="text"></param>
    /// <param name="sfx"></param>
    /// <returns></returns>
    public IEnumerator ShowPopup(Sprite icon, string text, SfxEntry sfx = null)
    {
        popupIcon.sprite = icon;
        popupText.text   = text;
        popupObject.SetActive(true);
        if (sfx != null)
        {
            sfxQueue.Enqueue(sfx);
            playSfxEvent.Invoke();
        }
        yield return(new WaitForSeconds(defaultDuration));

        popupObject.SetActive(false);
        yield return(new WaitForSeconds(defaultCooldown));
    }
예제 #11
0
    public override bool Act(DialogueScene scene, DialogueActionData data)
    {
        SfxEntry sfx = (SfxEntry)data.entries[0];

        if (sfx == null)
        {
            Debug.LogWarning("Empty Sfx action!");
            return(true);
        }

        scene.sfxClip.Enqueue(sfx);
        scene.effectStartDuration.value = data.values[0] * 0.001f;
        scene.effectEndDuration.value   = 0;

        return(true);
    }
예제 #12
0
 void SaveSelectedMusic()
 {
     if (soundType == 0)
     {
         MusicEntry me = (MusicEntry)musicLibrary.GetEntryByIndex(selMusic);
         me.CopyValues(musicValues);
         Undo.RecordObject(me, "Updated music");
         EditorUtility.SetDirty(me);
     }
     else
     {
         SfxEntry se = (SfxEntry)sfxLibrary.GetEntryByIndex(selMusic);
         se.CopyValues(sfxValues);
         Undo.RecordObject(se, "Updated sfx");
         EditorUtility.SetDirty(se);
     }
 }
예제 #13
0
    /// <summary>
    /// Uses the selected item.
    /// </summary>
    private void UseItem()
    {
        selectMode = false;
        inventoryButtons.ResetButtons();
        InventoryTuple tup = selectedCharacter.value.inventory.GetTuple(inventoryIndex.value);
        SfxEntry       sfx = (tup.weaponType == WeaponType.C_HEAL) ? healItemSfx : boostItemSfx;

        sfxQueue.Enqueue(sfx);
        playSfxEvent.Invoke();

        selectedCharacter.value.inventory.UseItem(inventoryIndex.value, selectedCharacter.value);
        inventoryIndex.value = -1;
        currentMode.value    = ActionMode.NONE;
        InputDelegateController.instance.TriggerMenuChange(MenuMode.MAP);
        selectedCharacter.value.End();
        inventoryChangedEvent.Invoke();
    }
예제 #14
0
    /// <summary>
    /// Copies the values from another entry.
    /// </summary>
    /// <param name="other"></param>
    public override void CopyValues(ScrObjLibraryEntry other)
    {
        base.CopyValues(other);
        Module module = (Module)other;

        chargingIcon = module.chargingIcon;

        activations = new List <ModuleActivation>();
        for (int i = 0; i < module.activations.Count; i++)
        {
            activations.Add(module.activations[i]);
        }
        effects = new List <ModuleEffect>();
        for (int i = 0; i < module.effects.Count; i++)
        {
            effects.Add(module.effects[i]);
        }

        startCooldownTime = module.startCooldownTime;
        maxCharges        = module.maxCharges;
        delay             = module.delay;
        cooldown          = module.cooldown;

        moduleType = module.moduleType;
        area       = module.area;
        holdMin    = module.holdMin;
        holdMax    = module.holdMax;

        projectile      = module.projectile;
        projectileSpeed = module.projectileSpeed;
        effectSteps     = module.effectSteps;

        damage          = module.damage;
        baseDamageScale = module.baseDamageScale;
        multihit        = module.multihit;

        activationSound = module.activationSound;
        impactSound     = module.impactSound;
    }
예제 #15
0
    void DeleteSfx()
    {
        GUI.FocusControl(null);
        SfxEntry se   = (SfxEntry)sfxLibrary.GetEntryByIndex(selMusic);
        string   path = "Assets/LibraryData/Sfx/" + se.uuid + ".asset";

        sfxLibrary.RemoveEntryByIndex(selMusic);
        Undo.RecordObject(sfxLibrary, "Deleted sfx");
        EditorUtility.SetDirty(sfxLibrary);
        bool res = AssetDatabase.MoveAssetToTrash(path);

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

        currentEntryList = sfxLibrary.GetRepresentations("", filterStr);

        if (res)
        {
            Debug.Log("Removed sfx: " + se.uuid);
            selMusic = -1;
        }
    }
예제 #16
0
    public override void CopyValues(ScrObjLibraryEntry other)
    {
        base.CopyValues(other);
        EnemyEntry ee = (EnemyEntry)other;

        // General
        enemyModelN = ee.enemyModelN;
        enemyModelS = ee.enemyModelS;
        maxhp       = ee.maxhp;
        speed       = ee.speed;

        // AI values
        waitStates = new List <WaitStates>();
        for (int i = 0; i < ee.waitStates.Count; i++)
        {
            waitStates.Add(ee.waitStates[i]);
        }
        waitTimeLimits = new RangedFloat(ee.waitTimeLimits.minValue, ee.waitTimeLimits.maxValue);
        chaseTimeLimit = ee.chaseTimeLimit;
        fleeDistance   = ee.fleeDistance;
        fleeTimeLimit  = ee.fleeTimeLimit;

        // Attacking
        meleeRange       = ee.meleeRange;
        attackRate       = ee.attackRate;
        attacks          = ee.attacks;
        meleeTimeStartup = ee.meleeTimeStartup;

        //Sounds
        attackChargeSfx   = ee.attackChargeSfx;
        attackActivateSfx = ee.attackActivateSfx;
        attackImpactSfx   = ee.attackImpactSfx;

        // Reward
        exp   = ee.exp;
        money = ee.money;
        //Add some kind of loot table
    }
예제 #17
0
        public static SoundEffectInstance Play(SfxEntry entry, Vector2 position, int variant, float volMod = Single.NaN, float pitch = Single.NaN, float panMod = Single.NaN)
        {
            return Play(entry, position, variant, (SfxEntry e, Vector2 p, ref int v, ref float vol, ref float pi, ref float pan) =>
            {
                if (!Single.IsNaN(volMod))
                    vol *= volMod;
                if (!Single.IsNaN(pitch ))
                    pi = pitch;
                if (!Single.IsNaN(panMod))
                    pan *= panMod;

                return true;
            });
        }
예제 #18
0
        static Tuple<int, float, float, float> CalcParams(SfxEntry e, Vector2 pos, int v, PlaySoundEvent onPlay)
        {
            var volSetting = e.IsAmbient ? (Main.gameInactive ? 0f : Main.ambientVolume) : Main.soundVolume;

            if (volSetting <= 0f)
                return null;

            bool shouldPlay = true;
            float
                vol = 1f, pitch = 0f, pan = 0f;

            if (pos.X <= 0f || pos.Y <= 0f || Single.IsNaN(pos.X) || Single.IsNaN(pos.Y))
                shouldPlay = true;
            else
            {
            #pragma warning disable RECS0091 // Use 'var' keyword when possible
                                 // to the code analyser: learn to C#
                Rectangle
            #pragma warning restore RECS0091
                    screen = new Rectangle((int)(Main.screenPosition.X - Main.screenWidth * 2), (int)(Main.screenPosition.Y - Main.screenHeight * 2), Main.screenWidth * 5, Main.screenHeight * 5),
                    sound  = new Rectangle((int)pos.X, (int)pos.Y, 1, 1);

                shouldPlay |= sound.Intersects(screen);

                if (shouldPlay)
                {
                    var screenCentre = new Vector2(Main.screenPosition.X + Main.screenWidth * 0.5f, Main.screenPosition.Y + Main.screenHeight * 0.5f);

                    pan = (pos.X - screenCentre.X) / (Main.screenWidth * 0.5f);
                    vol = 1f - Vector2.Distance(pos, screenCentre) / (Main.screenWidth * 1.5f);
                }
            }
            pan = MathHelper.Clamp(pan, -1f, 1f);
            vol = Math.Min(vol * volSetting, 1f);

            if (vol <= 0f)
                return null;

            if (onPlay != null && !onPlay(e, pos, ref v, ref vol, ref pitch, ref pan))
                return null;

            vol   = MathHelper.Clamp(vol  ,  0f, 1f);
            pitch = MathHelper.Clamp(pitch, -1f, 1f);
            pan   = MathHelper.Clamp(pan  , -1f, 1f);

            return Tuple.Create(v, vol, pitch, pan);
        }
 /// <summary>
 /// Plays the buy item sfx when triggered.
 /// </summary>
 public void PlaySingleSfx(SfxEntry entry)
 {
     currentSfx.value.Enqueue(entry.clip);
     playSfx.Invoke();
 }
예제 #20
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos)
 {
     return Play(entry, tilePos.ToVector2() * 16f, -1, null);
 }
예제 #21
0
        public static SoundEffectInstance Play(SfxEntry entry, Vector2 position, int variant, PlaySoundEvent onPlay)
        {
            if (Main.dedServ || WorldGen.gen || Main.netMode == 2)
                return null;

            var kvp = new KeyValuePair<SfxEntry, int>(entry, entry.Variants == 1 ? 0 : variant);

            var t = CalcParams(entry, position, variant, onPlay);

            if (t == null || t.Item2 <= 0f)
                return null;

            SoundEffectInstance inst;
            var b = entry.PlayBehaviour(variant);
            switch (b)
            {
                case SfxPlayBehaviour.MultipleInstances:
                    inst = entry.GetInstance(variant);

                    if (inst == null)
                        return null;

                    instancePool.Add(inst); // don't GC
                    break;
                case SfxPlayBehaviour.PlayIfStopped:
                case SfxPlayBehaviour.PlayIfStoppedUpdateParams:
                    if (instanceMap.ContainsKey(kvp))
                    {
                        var inst_ = instanceMap[kvp];

                        if (inst_.State == SoundState.Stopped)
                            inst = inst_;
                        else
                        {
                            if (b == SfxPlayBehaviour.PlayIfStoppedUpdateParams)
                                ApplyParams(inst_, t);

                            return null;
                        }
                    }
                    else
                    {
                        inst = entry.GetInstance(variant);

                        if (inst == null)
                            return null;

                        instanceMap.Add(kvp, inst);
                    }
                    break;
                case SfxPlayBehaviour.Singleton:
                    if (instanceMap.ContainsKey(kvp))
                    {
                        var inst_ = instanceMap[kvp];

                        inst_.Stop();

                        instanceMap.Remove(kvp);
                    }

                    inst = entry.GetInstance(variant);

                    if (inst == null)
                        return null;

                    instanceMap.Add(kvp, inst);
                    break;
                // required, compiler will complain about 'inst' not being assigned to otherwise
                // and this is more foolproof than setting 'inst' to null.
                default:
                    return null;
            }

            ApplyParams(inst, t);

            inst.Play(); // !

            CleanupLingeringInstances();

            return inst;
        }
예제 #22
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, PlaySoundEvent onPlay)
 {
     return Play(entry, tilePos.ToVector2() * 16f, variant, onPlay);
 }
예제 #23
0
        public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, float volMod = Single.NaN, float pitch = Single.NaN, float panMod = Single.NaN)
        {
            return Play(entry, tilePos.ToVector2() * 16f, variant, (SfxEntry e, Vector2 p, ref int v, ref float vol, ref float pi, ref float pan) =>
            {
                if (!Single.IsNaN(vol))
                    vol *= volMod;
                if (!Single.IsNaN(pi))
                    pi = pitch;
                if (!Single.IsNaN(pan))
                    pan *= panMod;

                return true;
            });
        }
예제 #24
0
 public static SoundEffectInstance Play(SfxEntry entry, Vector2 position)
 {
     return Play(entry, position, -1, null);
 }
예제 #25
0
 /// <summary>
 /// Constructor for the editor window.
 /// </summary>
 /// <param name="entries"></param>
 /// <param name="container"></param>
 public SfxEditorWindow(ScrObjLibraryVariable entries, SfxEntry container)
 {
     entryLibrary = entries;
     entryValues  = container;
     LoadLibrary();
 }
예제 #26
0
 public void Enqueue(SfxEntry sfx)
 {
     value.Enqueue(sfx.clip);
 }
예제 #27
0
        internal static void FillVanilla()
        {
            DigBlock  = GetVanilla(Main.soundDig      );
            PlayerHit = GetVanilla(Main.soundPlayerHit);

            UseItem   = GetVanilla(Main.soundItem     , v =>
            {
                switch (v)
                {
                    case 55:
                    case 57:
                        return SfxPlayBehaviour.PlayIfStopped;
                    case 9:
                    case 10:
                    case 24:
                    case 26:
                    case 34:
                    case 43:
                    case 103:
                        return SfxPlayBehaviour.MultipleInstances;
                    default:
                        return SfxPlayBehaviour.Singleton;
                }
            });
            NpcHit    = GetVanilla(Main.soundNPCHit   , v => v == 57 /* moon lord roar */ ? SfxPlayBehaviour.PlayIfStopped : SfxPlayBehaviour.Singleton        );
            NpcKilled = GetVanilla(Main.soundNPCKilled, v => v == 10 /* wall of flesh  */ ? SfxPlayBehaviour.PlayIfStopped : SfxPlayBehaviour.MultipleInstances);

            PlayerKilled = GetVanilla(Main.soundPlayerKilled);
            CutGrass     = GetVanilla(Main.soundGrass       );
            GrabItem     = GetVanilla(Main.soundGrab        );
            DoorOpen     = GetVanilla(Main.soundDoorOpen    );
            DoorClose    = GetVanilla(Main.soundDoorClosed  );
            MenuClose    = GetVanilla(Main.soundMenuClose   );
            MenuOpen     = GetVanilla(Main.soundMenuOpen    );
            MenuTick     = GetVanilla(Main.soundMenuTick    );
            Shatter      = GetVanilla(Main.soundShatter     );

            ZombieIdle = new SfxEntry(v =>
            {
                v = v == NPCID.BloodZombie ? Main.rand.Next(21, 24) : Main.rand.Next(3);

                return Main.soundZombie[v].CreateInstance();
            }, NPCID.BloodZombie + 1, _ => SfxPlayBehaviour.MultipleInstances);

            NpcAttackSound = new SfxEntry(v => Main.soundRoar[v == -1 ? 0 : v].CreateInstance(), Main.soundRoar.Length, _ => SfxPlayBehaviour.PlayIfStopped);

            DoubleJump = GetVanilla(Main.soundDoubleJump);
            Run        = GetVanilla(Main.soundRun       );

            Buy        = GetVanilla(Main.soundCoins     , SfxPlayBehaviour.MultipleInstances);

            Splash = GetVanilla(Main.soundSplash, SfxPlayBehaviour.PlayIfStopped);

            FemaleHit = GetVanilla(Main.soundFemaleHit);
            DigOre    = GetVanilla(Main.soundTink     );
            Unlock    = GetVanilla(Main.soundUnlock   );
            Drown     = GetVanilla(Main.soundDrown    );

            Chat      = GetVanilla(Main.soundChat     , SfxPlayBehaviour.MultipleInstances);
            MaxMana   = GetVanilla(Main.soundMaxMana  , SfxPlayBehaviour.MultipleInstances);

            MummyIdle    = GetVanilla(Main.soundZombie.Subarray(3, 3), SfxPlayBehaviour.MultipleInstances);
            PixieIdle    = GetVanilla(Main.soundPixie , SfxPlayBehaviour.PlayIfStoppedUpdateParams       );
            MechBuzz     = GetVanilla(Main.soundMech  , SfxPlayBehaviour.PlayIfStopped                   );
            NpcIdleSound = GetVanilla(Main.soundZombie, SfxPlayBehaviour.PlayIfStopped                   );

            DuckIdle = new SfxEntry(v =>
            {
                v = Main.rand.Next(300) == 0 ? 12 : (v == -1 ? Main.rand.Next(10, 12) : v + 10);

                return Main.soundZombie[v].CreateInstance();
            }, 2, _ => SfxPlayBehaviour.PlayIfStopped, true);

            FrogIdle          = GetVanilla(Main.soundZombie[13], SfxPlayBehaviour.MultipleInstances, true);
            NpcIdleSoundQuiet = GetVanilla(Main.soundZombie, SfxPlayBehaviour.PlayIfStopped        , true);
            BeetleIdle        = GetVanilla(Main.soundZombie[15], SfxPlayBehaviour.PlayIfStopped    , true);

            AmbientWater = GetVanilla(Main.soundLiquid[0], SfxPlayBehaviour.PlayIfStoppedUpdateParams, true);
            AmbientLava  = GetVanilla(Main.soundLiquid[1], SfxPlayBehaviour.PlayIfStoppedUpdateParams, true);

            NpcAttackSoundExpert = new SfxEntry(v => Main.soundRoar[v == -1 ? 0 : v].CreateInstance(), Main.soundRoar.Length, _ => SfxPlayBehaviour.MultipleInstances);

            Meowmere   = GetVanilla(Main.soundItem.Subarray(57, 2), SfxPlayBehaviour.MultipleInstances);
            CoinPickup = GetVanilla(Main.soundCoin, SfxPlayBehaviour.MultipleInstances                );

            AmbientDrip = GetVanilla(Main.soundDrip, SfxPlayBehaviour.MultipleInstances, true);

            Camera = GetVanilla(Main.soundCamera);

            MoonLordCry = GetVanilla(Main.soundNPCKilled[10], SfxPlayBehaviour.MultipleInstances);

            PopulateDict();
        }
예제 #28
0
 internal static void Reset()
 {
     DigBlock = PlayerHit = UseItem = NpcHit = NpcKilled = PlayerKilled = CutGrass
         = GrabItem = DoorOpen = MenuOpen = MenuClose = MenuTick = Shatter
         = ZombieIdle = NpcAttackSound = DoubleJump = Run = Buy = Splash = FemaleHit
         = DigOre = Unlock = Drown = Chat = MaxMana = MummyIdle = PixieIdle
         = MechBuzz = NpcIdleSound = DuckIdle = FrogIdle = NpcIdleSoundQuiet = BeetleIdle = AmbientWater
         = AmbientLava = NpcAttackSoundExpert = Meowmere = CoinPickup = AmbientDrip = Camera = MoonLordCry
         = null;
 }