Exemple #1
0
    public void SendAudioPlayMsg(GameObject owner, string audioName, int index, GameObject Player)
    {
        AudioMsg msg = new AudioMsg();

        msg.owner     = owner;
        msg.audioName = audioName;
        msg.index     = index;

        if (m_client.isConnected)
        {
            if (isServer)
            {
                if (Player.GetComponent <SurvivorStatus>().isLocalPlayer)
                {
                    msg.owner.GetComponent <ObjectAudio>().StartAudioSource(msg.audioName, msg.index);
                }
                else
                {
                    NetworkServer.SendToClient(Player.GetComponent <NetworkIdentity>().connectionToClient.connectionId, AudioPlayMsg, msg);
                }
            }
            else
            {
                Debug.Log("isClient");
            }
        }
    }
Exemple #2
0
    // Start is called before the first frame update
    protected virtual void Start()
    {
        readyTxt    = transform.Find("readyTxt").GetComponent <Text>();
        clockTxt    = transform.Find("clockTxt").GetComponent <Text>();
        operateTxt  = transform.Find("operateTxt").GetComponent <Text>();
        identityImg = transform.Find("identityImg").GetComponent <Image>();
        dialogTxt   = transform.Find("dialogTxt").GetComponent <Text>();
        idTxt       = transform.Find("idTxt").GetComponent <Text>();
        //chupaiResTxt = transform.Find("chupaiResTxt").GetComponent<Text>();
        chupaiParent = transform.Find("chupaiParent");

        //创建20张牌
        for (int i = 0; i < 20; i++)
        {
            var cardPrefab = Resources.Load(GlobalData.MyCardPath);
            var cardGO     = Instantiate(cardPrefab, chupaiParent) as GameObject;
            chupaiResultList.Add(cardGO.GetComponent <CardItem>());
            Destroy(cardGO.GetComponent <BoxCollider2D>());
            cardGO.SetActive(false);
        }


        serverMsg = new MessageData();
        audioMsg  = new AudioMsg();
        //默认状态
        if (readyTxt != null)
        {
            readyTxt.gameObject.SetActive(false);
        }
        dialogTxt.gameObject.SetActive(false);
        clockTxt.gameObject.SetActive(false);
        operateTxt.gameObject.SetActive(false);
        //chupaiResTxt.gameObject.SetActive(false);
    }
Exemple #3
0
    public void SendAudioStopMsg(GameObject owner, string audioName, int index)
    {
        AudioMsg msg = new AudioMsg();

        msg.owner     = owner;
        msg.audioName = audioName;
        msg.index     = index;
        if (m_client.isConnected)
        {
            NetworkServer.SendToAll(AudioStopMsg, msg);
        }
        msg.owner.GetComponent <ObjectAudio>().EndAudioSource(msg.audioName, msg.index);
    }
    /// <summary>
    /// 获取音效
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public AudioClip GetAudioClip(string path)
    {
        if (mDicPool.ContainsKey(path))//已经在缓存中存在了
        {
            return(mDicPool[path] as AudioClip);
        }
        if (IResManager.ResDebug)
        {//调试模式下直接下载
            AudioClip audio = Resources.Load(path, typeof(AudioClip)) as AudioClip;
            mDicPool.Add(path, audio);
            return(audio);
        }

        //缓存不存在 那么看看是否在加载队列中
        if (mListLoading.Contains(path))
        {
            return(null);
        }
        //加载

        DBVersionEnum versionEnum = DBVersionManager.CompareVersion(path);

        int    index = path.LastIndexOf("/") + 1;
        string name  = path.Substring(index, path.Length - index);


        if (versionEnum == DBVersionEnum.None)
        { //本地已经是最新的,那么从本地加载
            AysnLoadTask task = new AysnLoadTask();
            task.name         = name;
            task.path         = path;
            task.absolutePath = LocalUrl + "/" + path;
            mListLoading.Add(path);
            mLoadingTask.Add(task);
        }
        else
        { //从服务器加载
            AudioMsg audioMsg = new AudioMsg();
            audioMsg.name         = path.Substring(index, path.Length - index);
            audioMsg.versionEnum  = versionEnum;
            audioMsg.path         = path;
            audioMsg.absolutePath = ResUrl + "/" + path;
            audioMsg.localPath    = LocalUrl + "/" + path;
            audioMsg.SetUrl(audioMsg.absolutePath);
            CThreadManager.GetInstance().PushMsg(enumThreadID.enumThread_Web, audioMsg);
            mListLoading.Add(path);
        }
        return(null);
    }
Exemple #5
0
    void StopAudio(NetworkMessage recvmsg)
    {
        AudioMsg msg = recvmsg.ReadMessage <AudioMsg>();

        msg.owner.GetComponent <ObjectAudio>().EndAudioSource(msg.audioName, msg.index);
    }
Exemple #6
0
    private void PlayAudio(AudioMsg msg)
    {
        AudioClip audio = Resources.Load <AudioClip>(msg.path + msg.audioName);

        audioSource.PlayOneShot(audio);
    }