Example #1
0
    public void Dust(bool playDust = true, bool removeObject = false)
    {
        if (tag == "enemy" || tag == "bubble")
        {
            throw new CYFException("sprite.Dust(): You can't dust a " + tag + "'s sprite!");
        }

        GameObject go = Object.Instantiate(Resources.Load <GameObject>("Prefabs/MonsterDuster"));

        go.transform.SetParent(UIController.instance.psContainer.transform);
        if (playDust)
        {
            UnitaleUtil.PlaySound("DustSound", AudioClipRegistry.GetSound("enemydust"));
        }
        img.GetComponent <ParticleDuplicator>().Activate(this);
        if (img.gameObject.name == "player")
        {
            return;
        }
        img.SetActive(false);
        if (removeObject)
        {
            Remove();
        }
    }
Example #2
0
    public void Hurt(int damage)
    {
        if (damage >= 0)
        {
            UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound("hurtsound"), 0.65f);
        }
        else
        {
            UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound("healsound"), 0.65f);
        }

        if (-damage + player.HP > player.MaxHP)
        {
            player.HP = player.MaxHP;
        }
        else if (-damage + player.HP <= 0)
        {
            player.HP = 1;
        }
        else
        {
            player.HP -= damage;
        }
        appliedScript.Call("CYFEventNextCommand");
    }
Example #3
0
    private static UnderFont getUnderFont(string fontName)
    {
        XmlDocument xml      = new XmlDocument();
        string      fontPath = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".png");
        string      xmlPath  = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".xml", false);

        if (xmlPath == null)
        {
            return(null);
        }
        xml.Load(xmlPath);
        Dictionary <char, Sprite> fontMap = loadBuiltinFont(xml["font"]["spritesheet"], fontPath);
        AudioClip defaultVoice            = null;

        if (xml["font"]["voice"] != null)
        {
            defaultVoice = AudioClipRegistry.GetVoice(xml["font"]["voice"].InnerText);
        }

        UnderFont underfont = new UnderFont(fontMap, defaultVoice);

        if (xml["font"]["linespacing"] != null)
        {
            underfont.LineSpacing = ParseUtil.getFloat(xml["font"]["linespacing"].InnerText);
        }

        if (xml["font"]["color"] != null)
        {
            underfont.DefaultColor = ParseUtil.getColor(xml["font"]["color"].InnerText);
        }

        return(underfont);
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        FindObjectOfType <Fading>().BeginFade(-1);

        tmMain       = GameObject.Find("TextManager Main").GetComponent <TextManager>();
        tmChoice     = GameObject.Find("TextManager Choice").GetComponent <TextManager>();
        tmInfo       = GameObject.Find("TextManager Info").GetComponent <TextManager>();
        tmBigTalk    = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>();
        tmGold       = GameObject.Find("TextManager Gold").GetComponent <TextManager>();
        tmItem       = GameObject.Find("TextManager Item").GetComponent <TextManager>();
        tmInfoParent = tmInfo.transform.parent.parent.gameObject;
        tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });
        utHeart = GameObject.Find("utHeart");
        EnableBigText(false);

        if (scriptName == null)
        {
            throw new CYFException("You must give a valid script name to the function General.EnterShop()");
        }

        script = new ScriptWrapper()
        {
            scriptname = scriptName
        };
        string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName);

        if (scriptText == null)
        {
            throw new CYFException("You must give a valid script name to the function General.EnterShop()");
        }

        try {
            script.DoString(scriptText);
            script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>())));
            script.script.Globals["Interrupt"]    = ((Action <DynValue, string>)Interrupt);
            script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite;
            script.script.Globals["CreateLayer"]  = (Action <string, string, bool>)SpriteUtil.CreateLayer;
            script.script.Globals["CreateText"]   = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText;
            TryCall("Start");

            tmMain.SetCaller(script);
            tmChoice.SetCaller(script);
            tmInfo.SetCaller(script);
            tmBigTalk.SetCaller(script);

            tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) });
            tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9]    Buy\n    Sell\n    Talk\n    Exit", false, true) });
            tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) });
            tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) });
            tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });

            Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String);
            Camera.main.GetComponent <AudioSource>().time = 0;
            Camera.main.GetComponent <AudioSource>().Play();

            SetPlayerOnSelection();
        }
        catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage != null ? UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message : ex.Message); }
        catch (Exception ex)            { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); }
    }
Example #5
0
    public static void PlayVoice(string name, string voice, bool loop = false, float volume = 0.65f)
    {
        if (name == null)
        {
            throw new CYFException("NewAudio.PlayVoice: The first argument (the channel name) is nil.\n\nSee the documentation for proper usage.");
        }
        if (voice == null)
        {
            throw new CYFException("NewAudio.PlayVoice: The second argument (the voice name) is nil.\n\nSee the documentation for proper usage.");
        }
        if (!audiolist.ContainsKey(name))
        {
            throw new CYFException("The audio channel " + name + " doesn't exist.");
        }

        ((AudioSource)audiolist[name]).Stop();
        ((AudioSource)audiolist[name]).loop   = loop;
        ((AudioSource)audiolist[name]).volume = volume;
        ((AudioSource)audiolist[name]).clip   = AudioClipRegistry.GetVoice(voice);
        audiolist[name] = ((AudioSource)audiolist[name]);
        audioname[name] = "voice:" + voice.ToLower();
        if (name == "src")
        {
            MusicManager.filename = "voice:" + voice.ToLower();
        }
        ((AudioSource)audiolist[name]).Play();
    }
Example #6
0
 public static void Launch()
 {
     //GameObject.Find("player").GetComponent<Image>().sprite = null;
     Camera.main.GetComponent <AudioSource>().clip             = AudioClipRegistry.GetMusic("mus_gameover");
     GameObject.Find("GameOver").GetComponent <Image>().sprite = SpriteRegistry.Get("UI/spr_gameoverbg_0");
     GameObject.FindObjectOfType <GameOverBehavior>().StartDeath(null, null);
 }
Example #7
0
    void LateStart()
    {
        if (!string.IsNullOrEmpty(SpritePath))
        {
            Image img = GetComponent <Image>();
            if (img != null)
            {
                img.sprite = SpriteRegistry.Get(SpritePath);
                if (SetNativeSize)
                {
                    img.SetNativeSize();
                }
            }

            ParticleSystem psys = GetComponent <ParticleSystem>();
            if (psys != null)
            {
                ParticleSystemRenderer prender = GetComponent <ParticleSystemRenderer>();
                prender.material.mainTexture = SpriteRegistry.Get(SpritePath).texture;
            }
        }

        if (!string.IsNullOrEmpty(SoundPath))
        {
            AudioSource aSrc = GetComponent <AudioSource>();
            aSrc.clip = AudioClipRegistry.Get(SoundPath);
            aSrc.loop = Loop;
        }
    }
Example #8
0
    public void setHP(float newhp, bool forced = false)
    {
        if (newhp <= 0)
        {
            EventManager.instance.luaGeneralOw.GameOver();
            return;
        }
        float CheckedHP = PlayerCharacter.instance.HP;

        UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound(CheckedHP - newhp >= 0 ? "hurtsound" : "healsound").name);

        newhp = Mathf.Round(newhp * Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma)) / Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma);

        if (forced)
        {
            CheckedHP = newhp > PlayerCharacter.instance.MaxHP * 1.5 ? (int)(PlayerCharacter.instance.MaxHP * 1.5) : newhp;
        }
        else
        {
            CheckedHP = newhp > PlayerCharacter.instance.MaxHP       ? PlayerCharacter.instance.MaxHP              : newhp;
        }

        if (CheckedHP > ControlPanel.instance.HPLimit)
        {
            CheckedHP = ControlPanel.instance.HPLimit;
        }

        PlayerCharacter.instance.HP = CheckedHP;
    }
Example #9
0
 public void setMaxHP(int value)
 {
     if (value == PlayerCharacter.instance.MaxHP)
     {
         return;
     }
     if (value <= 0)
     {
         setHP(0);
         return;
     }
     if (value > ControlPanel.instance.HPLimit)
     {
         value = ControlPanel.instance.HPLimit;
     }
     else if (PlayerCharacter.instance.HP > value)
     {
         PlayerCharacter.instance.HP = value;
     }
     else
     {
         UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("healsound").name);
     }
     PlayerCharacter.instance.MaxHPShift = value - PlayerCharacter.instance.BasisMaxHP;
 }
Example #10
0
    public void initAll()
    {
        if (!Initialized)
        {
            Stopwatch sw = new Stopwatch(); //benchmarking terrible loading times
            sw.Start();
            ScriptRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Script registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            AudioClipRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Audio clip registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteFontRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite font registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();
        }
        LateUpdater.init(); // must be last; lateupdater's initialization is for classes that depend on the above registries
        MusicManager.src = Camera.main.GetComponent <AudioSource>();
    }
 public static bool PlaySound(string name, string sound, bool loop = false, float volume = 0.65f)
 {
     if (name == null)
     {
         throw new CYFException("NewAudio.PlaySound: The first argument (the channel name) is nil.\n\nSee the documentation for proper usage.");
     }
     else if (sound == null)
     {
         throw new CYFException("NewAudio.PlaySound: The second argument (the sound name) is nil.\n\nSee the documentation for proper usage.");
     }
     if (!audiolist.ContainsKey(name))
     {
         throw new CYFException("The audio channel " + name + " doesn't exist.");
     }
     ((AudioSource)audiolist[name]).Stop();
     ((AudioSource)audiolist[name]).loop   = loop;
     ((AudioSource)audiolist[name]).volume = volume;
     ((AudioSource)audiolist[name]).clip   = AudioClipRegistry.GetSound(sound, GlobalControls.retroMode);
     audiolist[name] = ((AudioSource)audiolist[name]);
     audioname[name] = "sound:" + sound.ToLower();
     if (name == "src")
     {
         MusicManager.filename = "sound:" + sound.ToLower();
     }
     ((AudioSource)audiolist[name]).Play();
     return(((AudioSource)audiolist[name]).clip != null);
 }
Example #12
0
    /// <summary>
    /// Get an AudioClip at the given full path. Attempts to retrieve it from the AudioClipRegistry first by using folderRoot to extract the clip's name, otherwise attempts to load from disk.
    /// </summary>
    /// <param name="musicFilePath">Full path to a file.</param>
    /// <returns>AudioClip object on successful load, otherwise null.</returns>
    public static AudioClip getAudioClip(string folderRoot, string musicFilePath)
    {
        string clipName = FileLoader.getRelativePathWithoutExtension(folderRoot, musicFilePath);
        //AudioClip music = AudioClipRegistry.Get(clipName);
        //if (music != null)
        //    return music;
        WWW www = new WWW(new Uri(musicFilePath).AbsoluteUri.Replace("+", "%2B"));

        while (!www.isDone)
        {
        }                       // hold up a bit while it's loading; delay isn't noticeable and loading will fail otherwise
        AudioType type = AudioType.UNKNOWN;

        if (musicFilePath.EndsWith(".ogg"))
        {
            type = AudioType.OGGVORBIS;
        }
        else if (musicFilePath.EndsWith(".wav"))
        {
            type = AudioType.WAV;
        }
        else
        {
            return(null);
        }

        AudioClip music;

        music      = www.GetAudioClip(false, false, type);
        music.name = "File at " + musicFilePath;
        music.LoadAudioData();

        AudioClipRegistry.Set(clipName, music);
        return(music);
    }
Example #13
0
    public void setHP(float newhp, bool forced = false)
    {
        if (newhp <= 0)
        {
            GameOverBehavior gob = GameObject.FindObjectOfType <GameOverBehavior>();
            if (!MusicManager.IsStoppedOrNull(PlayerOverworld.audioKept))
            {
                gob.musicBefore = PlayerOverworld.audioKept;
                gob.music       = gob.musicBefore.clip;
                gob.musicBefore.Stop();
            }
            else if (!MusicManager.IsStoppedOrNull(Camera.main.GetComponent <AudioSource>()))
            {
                gob.musicBefore = Camera.main.GetComponent <AudioSource>();
                gob.music       = gob.musicBefore.clip;
                gob.musicBefore.Stop();
            }
            else
            {
                gob.musicBefore = null;
                gob.music       = null;
            }
            player.HP = 0;
            gob.gameObject.transform.SetParent(null);
            GameObject.DontDestroyOnLoad(gob.gameObject);
            RectTransform rt = gob.gameObject.GetComponent <RectTransform>();
            rt.position = new Vector3(rt.position.x, rt.position.y, -1000);
            gob.gameObject.GetComponent <GameOverBehavior>().StartDeath();
            return;
        }
        float CheckedHP = player.HP;

        if (CheckedHP - newhp >= 0)
        {
            UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("hurtsound").name);
        }
        else
        {
            UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("healsound").name);
        }

        newhp = Mathf.Round(newhp * Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma)) / Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma);

        if (forced)
        {
            CheckedHP = newhp > player.MaxHP * 1.5 ? (int)(player.MaxHP * 1.5) : newhp;
        }
        else
        {
            CheckedHP = newhp > player.MaxHP       ? player.MaxHP              : newhp;
        }

        if (CheckedHP > ControlPanel.instance.HPLimit)
        {
            CheckedHP = ControlPanel.instance.HPLimit;
        }

        player.HP = CheckedHP;
    }
Example #14
0
 public static void LoadFile(string name)
 {
     src.Stop();
     src.clip = AudioClipRegistry.GetMusic(name);
     filename = "music:" + name.ToLower();
     NewMusicManager.audioname["src"] = filename;
     src.Play();
 }
Example #15
0
    private void inUpdateControlCommand(string command)
    {
        string[] cmds = command.Split(':');
        string[] args = new string[0];
        if (cmds.Length == 2)
        {
            args    = cmds[1].Split(',');
            cmds[1] = args[0];
        }
        switch (cmds[0].ToLower())
        {
        case "w":
            letterTimer = timePerLetter - (singleFrameTiming * ParseUtil.getInt(cmds[1]));
            break;

        case "waitall":
            timePerLetter = singleFrameTiming * ParseUtil.getInt(cmds[1]);
            break;

        case "voice":
            if (cmds[1].ToLower() == "default")
            {
                letterSound.clip = SpriteFontRegistry.Get(SpriteFontRegistry.UI_DEFAULT_NAME).Sound;
            }
            else
            {
                letterSound.clip = AudioClipRegistry.GetVoice(cmds[1].ToLower());
            }
            break;

        case "font":
            letterSound.clip = SpriteFontRegistry.Get(cmds[1].ToLower()).Sound;
            break;

        case "novoice":
            letterSound.clip = null;
            break;

        case "next":
            autoSkip = true;
            break;

        case "func":
            if (caller == null)
            {
                UnitaleUtil.displayLuaError("???", "Func called but no script to reference. This is the engine's fault, not yours.");
            }
            if (args.Length > 1)
            {
                caller.Call(args[0], DynValue.NewString(args[1]));
            }
            else
            {
                caller.Call(cmds[1]);
            }
            break;
        }
    }
Example #16
0
    public static void PlaySound(string name, float volume = 0.65f)
    {
        if (name == null)
        {
            throw new CYFException("Attempted to load a nil value as a sound.");
        }

        UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume);
    }
Example #17
0
 public void SetVoice(string voiceName)
 {
     if (voiceName == null)
     {
         throw new CYFException("Text.SetVoice: The first argument (the voice name) is nil.\n\nSee the documentation for proper usage.");
     }
     CheckExists();
     default_voice = voiceName == "none" ? null : AudioClipRegistry.GetVoice(voiceName);
 }
    // Use this for initialization
    void Start()
    {
        textObjFolder = GameObject.Find("NameText");
        AddToDict();
        isNewGame = SaveLoad.savedGame == null;
        uiAudio   = GameObject.Find("TextManager Instructions").GetComponent <AudioSource>();
        try { GameObject.Find("textframe_border_outer").SetActive(false); } catch { }
        tmInstr = GameObject.Find("TextManager Instructions").GetComponent <TextManager>();
        tmInstr.SetHorizontalSpacing(2);
        if (GlobalControls.crate)
        {
            tmInstr.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]GIV HMI A NAME!!!", false, true) });
        }
        else
        {
            tmInstr.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]Name the fallen human.", false, true) });
        }
        tmName = GameObject.Find("TextManager Name").GetComponent <TextManager>();
        tmName.SetHorizontalSpacing(2);
        GameObject firstCamera = GameObject.Find("Main Camera");

        firstCamera.name = "temp";
        if (GameObject.Find("Main Camera"))
        {
            GameObject.Destroy(GameObject.Find("Main Camera"));
        }
        firstCamera.name = "Main Camera";
        if (!isNewGame)
        {
            playerName = PlayerCharacter.instance.Name;
        }
        else
        {
            Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic("mus_menu");
            Camera.main.GetComponent <AudioSource>().Play();
        }
        tmName.SetTextQueue(new TextMessage[] { new TextMessage(playerName, false, true) });
        tmLettersMaj = GameObject.Find("TextManager LettersMaj").GetComponent <TextManager>();
        tmLettersMaj.SetHorizontalSpacing(52.2f);
        tmLettersMaj.SetVerticalSpacing(-1);
        tmLettersMaj.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]ABCDEFG\nHIJKLMN\nOPQRSTU\nVWXYZ", false, true) });
        tmLettersMaj.SetEffect(new ShakeEffect(tmLettersMaj));
        tmLettersMin = GameObject.Find("TextManager LettersMin").GetComponent <TextManager>();
        tmLettersMin.SetHorizontalSpacing(52.2f);
        tmLettersMin.SetVerticalSpacing(-1);
        tmLettersMin.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]abcdefg\nhijklmn\nopqrstu\nvwxyz", false, true) });
        tmLettersMin.SetEffect(new ShakeEffect(tmLettersMin));
        for (int i = 0; i < GameObject.Find("TextManager LettersMaj").GetComponentsInChildren <Image>().Length; i++)
        {
            GameObject.Find("TextManager LettersMaj").GetComponentsInChildren <Image>()[i].name = GameObject.Find("TextManager LettersMaj").GetComponentsInChildren <Image>()[i].sprite.name;
        }
        for (int i = 0; i < GameObject.Find("TextManager LettersMin").GetComponentsInChildren <Image>().Length; i++)
        {
            GameObject.Find("TextManager LettersMin").GetComponentsInChildren <Image>()[i].name = GameObject.Find("TextManager LettersMaj").GetComponentsInChildren <Image>()[i].sprite.name.ToLower();
        }
        GameObject.Find("A").GetComponent <Image>().color = new Color(1, 1, 0, 1);
    }
Example #19
0
    // Use this for initialization
    void Start()
    {
        if (!SaveLoad.started)
        {
            StaticInits.Start();
            SaveLoad.Start();
            new ControlPanel();
            new PlayerCharacter();
            #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            if (GlobalControls.crate)
            {
                Misc.WindowName = ControlPanel.instance.WinodwBsaisNmae;
            }
            else
            {
                Misc.WindowName = ControlPanel.instance.WindowBasisName;
            }
            #endif
            SaveLoad.LoadAlMighty();
            LuaScriptBinder.Set(null, "ModFolder", MoonSharp.Interpreter.DynValue.NewString("@Title"));
            UnitaleUtil.AddKeysToMapCorrespondanceList();
        }
        Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic("mus_intro");
        Camera.main.GetComponent <AudioSource>().Play();
        if (imagePaths.Length != textsToDisplay.Length)
        {
            throw new Exception("You need to have the same number of images and lines of text.");
        }
        text = GameObject.FindObjectOfType <TextManager>();
        img  = GameObject.Find("CutsceneImages").GetComponent <Image>();
        text.SetVerticalSpacing(6);
        text.SetHorizontalSpacing(6);
        if (SpriteRegistry.Get("Intro/mask") != null)
        {
            mask = true;
            GameObject.Find("Mask").GetComponent <Image>().sprite = SpriteRegistry.Get("Intro/mask");
            GameObject.Find("Mask").GetComponent <Image>().color  = new Color(1, 1, 1, 1);
        }

        TextMessage[] mess = new TextMessage[textsToDisplay.Length];
        for (int i = 0; i < mess.Length; i++)
        {
            mess[i] = new TextMessage("[waitall:2]" + textsToDisplay[i], false, false);
        }
        text.SetTextQueue(mess);
        img.sprite = SpriteRegistry.Get("Intro/" + imagePaths[0]);
        img.SetNativeSize();
        if (specialEffects[0] != string.Empty)
        {
            try { ApplyEffect((Effect)Enum.Parse(typeof(Effect), specialEffects[currentIndex].ToUpper())); }
            catch { UnitaleUtil.DisplayLuaError("IntroManager", "The effect " + specialEffects[currentIndex] + " doesn't exist."); }
        }
        if (goToNextDirect[0] == "Y")
        {
            timer = 0.5f;
        }
    }
Example #20
0
    // Use this for initialization
    void Start()
    {
        FindObjectOfType <Fading>().BeginFade(-1);

        tmMain       = GameObject.Find("TextManager Main").GetComponent <TextManager>();
        tmChoice     = GameObject.Find("TextManager Choice").GetComponent <TextManager>();
        tmInfo       = GameObject.Find("TextManager Info").GetComponent <TextManager>();
        tmBigTalk    = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>();
        tmGold       = GameObject.Find("TextManager Gold").GetComponent <TextManager>();
        tmItem       = GameObject.Find("TextManager Item").GetComponent <TextManager>();
        tmInfoParent = tmInfo.transform.parent.parent.gameObject;
        tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });
        utHeart = GameObject.Find("utHeart");
        EnableBigText(false);

        if (scriptName == null)
        {
            UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()");
            return;
        }

        script = new ScriptWrapper()
        {
            scriptname = scriptName
        };
        string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName);

        if (scriptText == null)
        {
            UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()");
            return;
        }


        script.DoString(scriptText);
        script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>())));
        script.script.Globals["Interrupt"]    = ((Action <DynValue, string>)Interrupt);
        script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite;
        script.script.Globals["CreateLayer"]  = (Action <string, string, bool>)SpriteUtil.CreateLayer;
        script.script.Globals["CreateText"]   = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText;
        script.Call("Start");

        tmMain.SetCaller(script);
        tmChoice.SetCaller(script);
        tmInfo.SetCaller(script);
        tmBigTalk.SetCaller(script);

        tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) });
        tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9]    Buy\n    Sell\n    Talk\n    Exit", false, true) });
        tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) });
        tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) });
        tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });

        Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String);
        Camera.main.GetComponent <AudioSource>().Play();
    }
Example #21
0
 /// <summary>
 /// Plays a selected sound at a given volume.
 /// </summary>
 /// <param name="sound"></param>
 /// <param name="volume"></param>
 [CYFEventFunction] public void PlaySound(string sound, float volume = 0.65f)
 {
     volume = Mathf.Clamp01(volume);
     if (AudioClipRegistry.GetSound(sound) == null)
     {
         throw new CYFException("General.PlaySound: The given BGM doesn't exist. Please check if you've spelled it correctly.");
     }
     UnitaleUtil.PlaySound("PlaySound", AudioClipRegistry.GetSound(sound), volume);
     //GameObject.Find("Player").GetComponent<AudioSource>().PlayOneShot(AudioClipRegistry.GetSound(sound), volume);
     appliedScript.Call("CYFEventNextCommand");
 }
Example #22
0
    public static void PlaySound(string name, float volume = 0.65f)
    {
        if (name == null)
        {
            UnitaleUtil.WriteInLogAndDebugger("[WARN]Attempted to load a nil value as a sound.");
            return;
        }

        try { UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume); }
        catch {  }
    }
Example #23
0
 public void SetVoice(string voiceName)
 {
     if (voiceName == "none")
     {
         default_voice = null;
     }
     else
     {
         default_voice = AudioClipRegistry.GetVoice(voiceName);
     }
 }
Example #24
0
 /// <summary>
 /// Built-in Unity function for initialization.
 /// </summary>
 private void Awake()
 {
     self        = GetComponent <RectTransform>();
     selfImg     = GetComponent <Image>();
     playerAbs   = new Rect(0, 0, selfImg.sprite.texture.width - hitboxInset * 2, selfImg.sprite.texture.height - hitboxInset * 2);
     instance    = this;
     playerAudio = GetComponent <AudioSource>();
     hurtSound   = AudioClipRegistry.GetSound("hurtsound");
     healSound   = AudioClipRegistry.GetSound("healsound");
     SetSoul(new RedSoul(this));
     luaStatus = new LuaPlayerStatus(this);
 }
Example #25
0
 private IEnumerator TitlePhase1()
 {
     Camera.main.GetComponent <AudioSource>().PlayOneShot(AudioClipRegistry.GetSound("intro_noise"));
     while (Camera.main.GetComponent <AudioSource>().isPlaying)
     {
         yield return(0);
     }
     while (phase == 0)
     {
         PressEnterOrZ.color = new Color(255, 255, 255, PressEnterOrZ.color.a == 1 ? 0 : 1);
         yield return(new WaitForSeconds(1));
     }
 }
 public void StopAction()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     Damage  = getDamage();
     line.SetAnimation(lineAnim, 1 / 12f);
     slice.SetAnimation(sliceAnim, 1 / 6f);
     slice.loop = KeyframeCollection.LoopMode.ONESHOT;
     UIController.playSoundSeparate(AudioClipRegistry.GetSound("slice"));
 }
Example #27
0
    public static void LoadFile(string name)
    {
        if (name == null)
        {
            throw new CYFException("Attempted to load a nil value as an Audio file.");
        }

        src.Stop();
        src.clip = AudioClipRegistry.GetMusic(name);
        filename = "music:" + name.ToLower();
        NewMusicManager.audioname["src"] = filename;
        src.loop = true;
        src.Play();
    }
Example #28
0
    /// <summary>
    /// Plays and adjust the volume of a chosen bgm.
    /// </summary>
    /// <param name="bgm">The name of the chosen BGM to play.</param>
    /// <param name="volume">The volume of the BGM. Clamped from 0 to 1.</param>
    [CYFEventFunction] public void PlayBGM(string bgm, float volume)
    {
        volume = Mathf.Clamp01(volume);
        if (AudioClipRegistry.GetMusic(bgm) == null)
        {
            throw new CYFException("General.PlayBGM: The given BGM doesn't exist. Please check if you've spelled it correctly.");
        }
        AudioSource audio = UnitaleUtil.GetCurrentOverworldAudio();

        audio.clip   = AudioClipRegistry.GetMusic(bgm);
        audio.volume = volume;
        audio.Play();
        appliedScript.Call("CYFEventNextCommand");
    }
Example #29
0
    public static void LoadFile(string name)
    {
        if (name == null)
        {
            UnitaleUtil.WriteInLogAndDebugger("[WARN]Attempted to load a nil value as an Audio file.");
            return;
        }

        src.Stop();
        src.clip = AudioClipRegistry.GetMusic(name);
        filename = "music:" + name.ToLower();
        NewMusicManager.audioname["src"] = filename;
        src.Play();
    }
Example #30
0
 public void StartDeath()
 {
     brokenHeartPrefab = Resources.Load <GameObject>("Prefabs/heart_broken");
     heartShardPrefab  = SpriteRegistry.GENERIC_SPRITE_PREFAB.gameObject;
     gameOverTxt       = GameObject.Find("TextParent").GetComponent <TextManager>();
     heartbreak        = AudioClipRegistry.GetSound("heartbeatbreaker");
     heartsplode       = AudioClipRegistry.GetSound("heartsplosion");
     gameOverImage     = GameObject.Find("GameOver").GetComponent <Image>();
     heartPos          = gameObject.GetComponent <RectTransform>().position;
     heartColor        = gameObject.GetComponent <Image>().color;
     gameObject.transform.SetParent(GameObject.Find("Canvas").transform);
     gameOverMusic = Camera.main.GetComponent <AudioSource>();
     started       = true;
 }