Exemple #1
0
    public override void init(ComponentOwner owner)
    {
        base.init(owner);
        // 通知子类设置自己的音效类型
        setSoundOwner();
        // 如果音效还未加载,则加载所有音效,此处只是注册
        if (mAudioTypeMap.Count == 0)
        {
            int dataCount = mDataBase.getDataCount(DATA_TYPE.DT_GAME_SOUND);
            for (int i = 0; i < dataCount; ++i)
            {
                DataGameSound soundData = mDataBase.queryData(DATA_TYPE.DT_GAME_SOUND, i) as DataGameSound;
                string        soundName = BinaryUtility.bytesToString(soundData.mSoundFileName);
                mAudioTypeMap.Add(soundName, soundData.mSoundType);
                mSoundDefineMap.Add((SOUND_DEFINE)(soundData.mSoundID), soundName);
                mAudioManager.createAudio(soundName, false);
            }
        }

        // 清空所有类型正在播放的音效
        for (int i = 0; i < mMaxChannel; ++i)
        {
            mCurPlayList.Add(i, "");
        }
    }
Exemple #2
0
    public override void execute()
    {
        if (mLoginRet.mValue == 0)
        {
            // 创建玩家
            CommandCharacterManagerCreateCharacter cmdCreate = newCmd(out cmdCreate);
            cmdCreate.mCharacterType = CHARACTER_TYPE.CT_MYSELF;
            cmdCreate.mName          = BinaryUtility.bytesToString(mName.mValue, Encoding.UTF8);
            cmdCreate.mID            = mPlayerGUID.mValue;
            pushCommand(cmdCreate, mCharacterManager);
            // 设置角色数据
            CharacterMyself myself = mCharacterManager.getMyself();
            CharacterData   data   = myself.getCharacterData();
            data.mMoney = mMoney.mValue;
            data.mHead  = mHead.mValue;

            // 进入到主场景
            CommandGameSceneManagerEnter cmdEnterMain = newCmd(out cmdEnterMain, true, true);
            cmdEnterMain.mSceneType = GAME_SCENE_TYPE.GST_MAIN;
            pushDelayCommand(cmdEnterMain, mGameSceneManager);
        }
        else if (mLoginRet.mValue == 1)
        {
            UnityUtility.logInfo("账号密码错误!");
        }
        else if (mLoginRet.mValue == 2)
        {
            UnityUtility.logInfo("已在其他地方登陆!");
        }
    }
Exemple #3
0
    public override void execute()
    {
        string name = BinaryUtility.bytesToString(mName.mValue, Encoding.UTF8);

        UnityUtility.logInfo("获得玩家数据 : " + mPlayerGUID + ", 名字 : " + name);
        // 创建该玩家的实例
        CommandCharacterManagerCreateCharacter cmdCreate = newCmd(out cmdCreate);

        cmdCreate.mName          = name;
        cmdCreate.mID            = mPlayerGUID.mValue;
        cmdCreate.mCharacterType = CHARACTER_TYPE.CT_OTHER;
        pushCommand(cmdCreate, mCharacterManager);
        CharacterOther other = mCharacterManager.getCharacter(mPlayerGUID.mValue) as CharacterOther;
        CharacterData  data  = other.getCharacterData();

        data.mMoney          = mMoney.mValue;
        data.mHead           = mHead.mValue;
        data.mServerPosition = (PLAYER_POSITION)mPosition.mValue;
        data.mBanker         = mBanker.mValue;
        data.mReady          = mReady.mValue;
        // 将该玩家加入房间
        GameScene       gameScene = mGameSceneManager.getCurScene();
        CommandRoomJoin cmd       = newCmd(out cmd);

        cmd.mCharacter = other;
        pushCommand(cmd, (gameScene as MahjongScene).getRoom());
    }
Exemple #4
0
    protected void notifyVersionDownloaded(FileWrap versionFile)
    {
        // 版本文件下载完毕后,提示是否有新版本可以更新
        string versionString = FileUtility.openTxtFile(CommonDefine.VERSION);
        bool   hasNewVersion = false;

        if (versionString == "")
        {
            hasNewVersion = true;
        }
        else
        {
            string remoteVersion = BinaryUtility.bytesToString(versionFile.getFileData());
            hasNewVersion = remoteVersion != versionString;
        }
        if (hasNewVersion)
        {
            setState(UPGRADE_STATE.US_WAIT_FOR_UPGRADE);
        }
        else
        {
            done();
        }
        mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_NEW_VERSION, StringUtility.boolToString(hasNewVersion));
    }
Exemple #5
0
    protected void notifyFileListDownloaded(FileWrap listFile)
    {
        // 列表文件下载完毕,解析列表
        setState(UPGRADE_STATE.US_PARSING_REMOTE_FILE_LIST);
        string listContent = BinaryUtility.bytesToString(listFile.getFileData());

        parseRemoteFileList(listContent);
        setState(UPGRADE_STATE.US_GENERATE_LOCAL_FILE);
        // 检查本地文件
        getLocalFileList();
        // 如果在检查本地文件过程中取消了,则直接返回
        if (mCancel)
        {
            setState(UPGRADE_STATE.US_NONE);
            return;
        }

        // 判断出需要更新的文件
        setState(UPGRADE_STATE.US_GENERATE_MODIFIED_FILE);
        // 然后下载修改过和新增的文件
        mModifiedList = generateModifiedFile(mRemoteFileList, mLocalFileList, mIgnorePathList);
        setState(UPGRADE_STATE.US_DOWNLOADING_REMOTE_FILE);
        if (mModifiedList.Count() == 0)
        {
            // 如果有临时目录,则将临时目录中的所有文件替换到游戏目录
            notifyAllDownloaded();
            mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_NOTHING_UPDATE);
            done();
        }
        else
        {
            // 计算所有需要下载的文件的大小
            mTotalSize = 0.0f;
            foreach (var item in mModifiedList)
            {
                mTotalSize = mTotalSize + item.Value.mFileSize;
            }
            // 开始下载所有文件,并且开始计时
            mCurTimeCount = 0.0f;
            foreach (var item in mModifiedList)
            {
                // 如果临时文件存在,表示之前没下载成功,暂时删除临时文件
                // 如果实现断点续传时需要获取临时文件的大小
                long offset = 0;
                if (FileUtility.isFileExist(CommonDefine.TEMP_PATH + item.Key + CommonDefine.TEMP_FILE_EXTENSION))
                {
                    offset = FileUtility.getFileSize(CommonDefine.TEMP_PATH + item.Key + CommonDefine.TEMP_FILE_EXTENSION);
                }
                repuestDownload(item.Key, offset);
            }
        }
    }
Exemple #6
0
    protected string encode(string str, byte[] encodeKeyBytes)
    {
        byte[] strBytes     = BinaryUtility.stringToBytes(str);
        int    byteLen      = strBytes.Length;
        int    encodeKeyLen = encodeKeyBytes.Length;

        for (int i = 0; i < byteLen; ++i)
        {
            sbyte oriByte    = (sbyte)strBytes[i];
            sbyte encodeByte = (sbyte)encodeKeyBytes[i % encodeKeyLen];
            oriByte    ^= encodeByte;
            strBytes[i] = REGISTER_CODE[Mathf.Abs((oriByte + encodeByte) + 0xff) % CODE_LEN];
        }
        str = BinaryUtility.bytesToString(strBytes);
        return(str);
    }
Exemple #7
0
    public override void init()
    {
        int dataCount = mDataBase.getDataCount(DATA_TYPE.DT_GAME_SOUND);

        for (int i = 0; i < dataCount; ++i)
        {
            DataGameSound soundData = mDataBase.queryData(DATA_TYPE.DT_GAME_SOUND, i) as DataGameSound;
            string        soundName = BinaryUtility.bytesToString(soundData.mSoundFileName);
            string        audioName = StringUtility.getFileNameNoSuffix(soundName, true);
            SOUND_DEFINE  soundID   = (SOUND_DEFINE)(soundData.mSoundID);
            mSoundDefineMap.Add(soundID, audioName);
            if (!mVolumeScale.ContainsKey(soundID))
            {
                mVolumeScale.Add(soundID, soundData.mVolumeScale);
            }
            registeAudio(soundName);
        }
    }
Exemple #8
0
 public override void init(ComponentOwner owner)
 {
     base.init(owner);
     // 通知子类设置自己的音效类型
     setSoundOwner();
     // 如果音效还未加载,则加载所有音效,此处只是注册
     if (mSoundDefineMap.Count == 0)
     {
         int dataCount = mDataBase.getDataCount(DATA_TYPE.DT_GAME_SOUND);
         for (int i = 0; i < dataCount; ++i)
         {
             DataGameSound soundData = mDataBase.queryData(DATA_TYPE.DT_GAME_SOUND, i) as DataGameSound;
             string        soundName = BinaryUtility.bytesToString(soundData.mSoundFileName);
             string        audioName = StringUtility.getFileNameNoSuffix(soundName, true);
             mSoundDefineMap.Add((SOUND_DEFINE)(soundData.mSoundID), audioName);
             mAudioManager.createAudio(soundName, false);
         }
     }
 }
Exemple #9
0
    public bool readFile(string file)
    {
        int fileSize = 0;

        byte[] fileData = null;
        FileUtility.openFile(file, ref fileData, ref fileSize);
        mFileName = file;
        Serializer serializer = new Serializer(fileData, fileSize);

        serializer.read(ref mRiffMark);
        serializer.read(ref mFileSize);
        serializer.read(ref mWaveMark);
        serializer.read(ref mFmtMark);
        serializer.read(ref mFmtChunkSize);
        serializer.read(ref mFormatType);
        serializer.read(ref mSoundChannels);
        serializer.read(ref mSamplesPerSec);
        serializer.read(ref mAvgBytesPerSec);
        serializer.read(ref mBlockAlign);
        serializer.read(ref mBitsPerSample);
        if (mFmtChunkSize == 18)
        {
            serializer.read(ref mOtherSize);
        }
        // 如果不是data块,则跳过,重新读取
        do
        {
            mDataBuffer = null;
            serializer.readBuffer(mDataMark, 4, 4);
            serializer.read(ref mDataSize);
            mDataBuffer = new byte[mDataSize];
            serializer.readBuffer(mDataBuffer, mDataSize, mDataSize);
        } while (BinaryUtility.bytesToString(mDataMark) != "data");
        refreshFileSize();

        int mixDataCount = getMixPCMDataCount();

        mMixPCMData = new short[mixDataCount];
        generateMixPCMData(mMixPCMData, mixDataCount, mSoundChannels, mDataBuffer, mDataSize);
        return(true);
    }
Exemple #10
0
    protected void notifyVersionDownloaded(FileWrap versionFile)
    {
        // 版本文件下载完毕后,提示是否有新版本可以更新
        string localUpdateInfo  = "";
        string localVersion     = getVersionFromFile(FileUtility.openTxtFile(CommonDefine.VERSION), ref localUpdateInfo);
        string remoteUpdateInfo = "";
        string remoteVersion    = getVersionFromFile(BinaryUtility.bytesToString(versionFile.getFileData()), ref remoteUpdateInfo);
        bool   hasNewVersion    = remoteVersion != localVersion;

        if (hasNewVersion)
        {
            setState(UPGRADE_STATE.US_WAIT_FOR_UPGRADE);
        }
        else
        {
            done();
        }
        List <string> paramList = new List <string>();

        paramList.Add(StringUtility.boolToString(hasNewVersion));
        paramList.Add(remoteUpdateInfo);
        mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_NEW_VERSION, paramList);
    }
Exemple #11
0
    public static float calculateFloat(string str)
    {
        // 判断字符串是否含有非法字符,也就是除数字,小数点,运算符以外的字符
        string newString = "";
        int    oldStrLen = str.Length;

        for (int i = 0; i < oldStrLen; ++i)
        {
            if ((str[i] < '0' || str[i] > '9') && str[i] != '.' && str[i] != '+' &&
                str[i] != '-' && str[i] != '*' && str[i] != '/' && str[i] != '(' && str[i] != ')')
            {
                continue;
            }
            else
            {
                newString += str[i];
            }
        }
        str = newString;
        // 判断左右括号数量是否相等
        int leftBracketCount  = 0;
        int rightBracketCount = 0;
        int newStrLen         = str.Length;

        for (int i = 0; i < newStrLen; ++i)
        {
            if (str[i] == '(')
            {
                ++leftBracketCount;
            }
            else if (str[i] == ')')
            {
                ++rightBracketCount;
            }
        }
        if (leftBracketCount != rightBracketCount)
        {
            // 计算错误,左右括号数量不对应
            return(0);
        }

        // 循环判断传入的字符串有没有括号
        while (true)
        {
            // 先判断有没有括号,如果有括号就先算括号里的,如果没有就退出while循环
            if (str.IndexOf("(") != -1 || str.IndexOf(")") != -1)
            {
                int    curpos       = str.LastIndexOf("(");
                string strInBracket = str.Substring(curpos + 1, str.Length - curpos - 1);
                strInBracket = strInBracket.Substring(0, strInBracket.IndexOf(")"));
                float ret = calculateFloat(strInBracket);
                // 如果括号中的计算结果是负数,则标记为负数
                bool isMinus = false;
                if (ret < 0)
                {
                    ret     = -ret;
                    isMinus = true;
                }
                // 将括号中的计算结果替换原来的表达式,包括括号也一起替换
                string floatStr = (Math.Round(ret, 4)).ToString();
                str = StringUtility.strReplace(str, curpos, curpos + strInBracket.Length + 2, floatStr);
                byte[] strchar = BinaryUtility.stringToBytes(str, Encoding.ASCII);
                if (isMinus)
                {
                    // 如果括号中计算出来是负数,则将负号提取出来,将左边的第一个加减号改为相反的符号
                    bool changeMark = false;
                    for (int i = curpos - 1; i >= 0; --i)
                    {
                        // 找到第一个+号,则直接改为减号,然后退出遍历
                        if (strchar[i] == '+')
                        {
                            strchar[i] = (byte)'-';
                            str        = BinaryUtility.bytesToString(strchar, Encoding.ASCII);
                            changeMark = true;
                            break;
                        }
                        // 找到第一个减号,如果减号的左边有数字,则直接改为+号
                        // 如果减号的左边不是数字,则该减号是负号,将减号去掉,
                        else if (strchar[i] == '-')
                        {
                            if (strchar[i - 1] >= '0' && strchar[i - 1] <= '9')
                            {
                                strchar[i] = (byte)'+';
                                str        = BinaryUtility.bytesToString(strchar, Encoding.ASCII);
                            }
                            else
                            {
                                str = StringUtility.strReplace(str, i, i + 1, "");
                            }
                            changeMark = true;
                            break;
                        }
                    }
                    // 如果遍历完了还没有找到可以替换的符号,则在表达式最前面加一个负号
                    if (!changeMark)
                    {
                        str = "-" + str;
                    }
                }
            }
            else
            {
                break;
            }
        }
        List <float> numbers = new List <float>();
        List <char>  factors = new List <char>();
        // 表示上一个运算符的下标+1
        int beginpos = 0;

        for (int i = 0; i < str.Length; ++i)
        {
            // 遍历到了最后一个字符,则直接把最后一个数字放入列表,然后退出循环
            if (i == str.Length - 1)
            {
                string num  = str.Substring(beginpos, str.Length - beginpos);
                float  fNum = float.Parse(num);
                numbers.Add(fNum);
                break;
            }
            // 找到第一个运算符
            if ((str[i] < '0' || str[i] > '9') && str[i] != '.')
            {
                if (i != 0)
                {
                    string num  = str.Substring(beginpos, i - beginpos);
                    float  fNum = float.Parse(num);
                    numbers.Add(fNum);
                }
                // 如果在表达式的开始就发现了运算符,则表示第一个数是负数,那就处理为0减去这个数的绝对值
                else
                {
                    numbers.Add(0);
                }
                factors.Add(str[i]);
                beginpos = i + 1;
            }
        }
        if (factors.Count + 1 != numbers.Count)
        {
            // 计算错误,运算符与数字数量不符
            return(0);
        }
        // 现在开始计算表达式,按照运算优先级,先计算乘除和取余
        while (true)
        {
            // 表示是否还有乘除表达式
            bool hasMS = false;
            for (int i = 0; i < (int)factors.Count; ++i)
            {
                // 先遍历到哪个就先计算哪个
                if (factors[i] == '*' || factors[i] == '/')
                {
                    // 第一个运算数的下标与运算符的下标是相同的
                    float num1 = numbers[i];
                    float num2 = numbers[i + 1];
                    float num3 = 0.0f;
                    if (factors[i] == '*')
                    {
                        num3 = num1 * num2;
                    }
                    else if (factors[i] == '/')
                    {
                        num3 = num1 / num2;
                    }
                    // 删除第i + 1个数,然后将第i个数替换为计算结果
                    numbers.RemoveAt(i + 1);
                    if (numbers.Count == 0)
                    {
                        // 计算错误
                        return(0);
                    }
                    numbers[i] = num3;
                    // 删除第i个运算符
                    factors.RemoveAt(i);
                    hasMS = true;
                    break;
                }
            }
            if (!hasMS)
            {
                break;
            }
        }
        // 再计算加减法
        while (true)
        {
            if (factors.Count == 0)
            {
                break;
            }
            if (factors[0] == '+' || factors[0] == '-')
            {
                // 第一个运算数的下标与运算符的下标是相同的
                float num1 = numbers[0];
                float num2 = numbers[1];
                float num3 = 0.0f;
                if (factors[0] == '+')
                {
                    num3 = num1 + num2;
                }
                else if (factors[0] == '-')
                {
                    num3 = num1 - num2;
                }
                // 删除第1个数,然后将第0个数替换为计算结果
                numbers.RemoveAt(1);
                if (numbers.Count == 0)
                {
                    // 计算错误
                    return(0);
                }
                numbers[0] = num3;
                // 删除第0个运算符
                factors.RemoveAt(0);
            }
        }
        if (numbers.Count != 1)
        {
            // 计算错误
            return(0);
        }
        else
        {
            return(numbers[0]);
        }
    }