public void EnableDrag(bool isEnabled)
    {
        if (isEnabled)
        {
            if (inputType == InputSystemType.NGUIAndWorldInput)
            {
                if (sourceCamera == null)
                {
                    GameLogger.LogError("## Source Camera for drag scroll view is null ##");
                    return;
                }

                if (dragController == null)
                {
                    dragController = gameObject.AddComponent <EnhanceScrollViewDragController>();
                }
                dragController.enabled = true;
                // set the camera and mask
                dragController.SetTargetCameraAndMask(sourceCamera, (1 << LayerMask.NameToLayer("UI")));
            }
        }
        else
        {
            if (dragController != null)
            {
                dragController.enabled = false;
            }
        }
    }
Esempio n. 2
0
    public void GenerateLevel(Level level)
    {
        level.width  = this.width;
        level.height = this.height;

        if (level.height < Level.MinHeight || level.width < Level.MinWidth)
        {
            GameLogger.LogError("Level is too small", "EmptyGenerator");
            level.height = Level.MinHeight;
            level.width  = Level.MinWidth;
        }

        level.width  = this.width;
        level.height = this.height;

        level.objectMap = new MapObject[height, width];
        for (int i = 0; i < level.height; i++)
        {
            for (int j = 0; j < level.width; j++)
            {
                if (i < Level.BorderSize || i >= level.height - Level.BorderSize || j < Level.BorderSize || j >= level.width - Level.BorderSize)
                {
                    level.objectMap[i, j] = MapObject.Wall;
                }
                else
                {
                    level.objectMap[i, j] = MapObject.Floor;
                }
            }
        }
    }
Esempio n. 3
0
    public void PlaceSpawners(Level level, MapObject[] spawners, int[] counts)
    {
        for (int spawner = 0; spawner < spawners.Length; spawner++)
        {
            for (int i = 0; i < counts[spawner]; i++)
            {
                int y     = Random.Range(0, level.height);
                int x     = Random.Range(0, level.width);
                int tries = 0;

                while (level.objectMap[y, x] != MapObject.Floor)
                {
                    y = Random.Range(0, level.height);
                    x = Random.Range(0, level.width);
                    tries++;
                    if (tries > 100)
                    {
                        GameLogger.LogError($"Invalid map, too many tries to emplace spawner of type {spawner}", "CaveGenerator");
                        return;
                    }
                }

                level.objectMap[y, x] = spawners[spawner];
            }
        }
    }
Esempio n. 4
0
    public void GenerateLevel(Level level)
    {
        GameLogger.LogMessage($"Processing file {this.filePath}", "ReaderGenerator");
        var levelAsset = Resources.Load(this.filePath, typeof(TextAsset)) as TextAsset;

        try {
            if (levelAsset == null)
            {
                GameLogger.LogMessage("Opening custom level", "ReaderGenerator");
                using (var file = new BinaryReader(File.Open(this.filePath, FileMode.Open))) {
                    this.ProcessFile(file, level);
                }
            }
            else
            {
                GameLogger.LogMessage("Opening standart level", "ReaderGenerator");
                using (var file = new BinaryReader(new MemoryStream(levelAsset.bytes))) {
                    this.ProcessFile(file, level);
                }
            }
        } catch {
            GameLogger.LogError($"Incorrect input file", "ReaderGenerator");
            level.width     = Level.MinWidth;
            level.height    = Level.MinHeight;
            level.objectMap = new MapObject[level.height, level.width];
            for (int i = 0; i < level.height; i++)
            {
                for (int j = 0; j < level.width; j++)
                {
                    level.objectMap[i, j] = MapObject.Floor;
                }
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Select position on <paramref name="level"/> by iterating through map from needed corner
    /// (set by <paramref name="xTransformer"/> and <paramref name="yTransformer"/>)
    /// with chance <paramref name="selectionChance"/>.
    /// </summary>
    /// <param name="selectionChance"> Selection chance. </param>
    /// <param name="xTransformer"> Function that selects side of corner by X. </param>
    /// <param name="yTransformer"> Function that selects side of corner by Y. </param>
    /// <param name="level"> Level on which position will be selected. </param>
    /// <returns> Selected position. </returns>
    private Vector2Int SelectPosition(float selectionChance, Func <int, int, int> xTransformer, Func <int, int, int> yTransformer, Level level)
    {
        for (int j = 0; j < level.width; j++)
        {
            for (int i = 0; i < level.height; i++)
            {
                int x = xTransformer(j, level.width);
                int y = yTransformer(i, level.height);
                if (level.objectMap[y, x] == MapObject.Floor && Random.value < selectionChance)
                {
                    return(new Vector2Int(x, y));
                }
            }
        }

        for (int j = 0; j < level.width; j++)
        {
            for (int i = 0; i < level.height; i++)
            {
                int x = xTransformer(j, level.width);
                int y = yTransformer(i, level.height);
                if (level.objectMap[y, x] == MapObject.Floor)
                {
                    return(new Vector2Int(x, y));
                }
            }
        }

        GameLogger.LogError("Can't select position", "CaveGenerator");
        return(Vector2Int.one);
    }
    void Start()
    {
        canChangeItem = true;
        int count = listEnhanceItems.Count;

        dFactor      = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f;
        mCenterIndex = count / 2;
        if (count % 2 == 0)
        {
            mCenterIndex = count / 2 - 1;
        }
        int index = 0;

        for (int i = count - 1; i >= 0; i--)
        {
            listEnhanceItems[i].CurveOffSetIndex = i;
            listEnhanceItems[i].CenterOffSet     = dFactor * (mCenterIndex - index);
            listEnhanceItems[i].SetSelectState(false);
            GameObject obj = listEnhanceItems[i].gameObject;

            if (inputType == InputSystemType.NGUIAndWorldInput)
            {
                DragEnhanceView script = obj.GetComponent <DragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
            }
            else
            {
                UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
            }
            index++;
        }

        // set the center item with startCenterIndex
        if (startCenterIndex < 0 || startCenterIndex >= count)
        {
            GameLogger.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count  out of index ##");
            startCenterIndex = mCenterIndex;
        }

        // sorted items
        listSortedItems      = new List <EnhanceItem>(listEnhanceItems.ToArray());
        totalHorizontalWidth = cellWidth * count;
        curCenterItem        = listEnhanceItems[startCenterIndex];
        curHorizontalValue   = 0.5f - curCenterItem.CenterOffSet;
        LerpTweenToTarget(0f, curHorizontalValue, false);

        //
        // enable the drag actions
        //
        EnableDrag(true);
    }
Esempio n. 7
0
    /// <summary>
    /// Check loading for TL.
    /// </summary>
    private IEnumerator CheckLoading()
    {
        yield return(new WaitForSeconds(60));

        if (this.gameState == GameState.NOT_LOADED)
        {
            GameLogger.LogError("Loading took too much time", "GameManager");
            Application.Quit();
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Add assets from <paramref name="arr"/> to wallAssets Dictionary.
    /// </summary>
    /// <param name="arr"> An array of assets. </param>
    /// <param name="alias"> Key in wallAssets dictionary. </param>
    public void AddWallAsset(GameObject arr, MapObject alias)
    {
        if (arr == null)
        {
            GameLogger.LogError($"LevelManager: Asset: {alias} is not set yet", "Level");
            return;
        }

        this.wallAssets[alias] = arr;
    }
    /// <summary>
    /// 异步加载资源
    /// </summary>
    /// <param name="assetName">需要加载的资源路径</param>
    /// <param name="onLoadAsset">加载成功之后的回调</param>
    /// <returns>请求Id</returns>
    public static int LoadAssetAsync(string assetName, OnLoadAsset onLoadAsset)
    {
        // 回调不存在不允加载
        if (onLoadAsset == null)
        {
            GameLogger.LogError("[资源加载错误] 加载函数回调不能为空,加载后也没有引用");
            return(0);
        }

        // 资源对应bundle名
        string abName = BundleAsset.GetBundleName(assetName);

        if (abName == null)
        {
            GameLogger.LogError("[资源加载错误] 找不到资源 ", assetName);
            return(0);
        }

        // 获取请求ID
        int requestId = ResourceManager.GetRequestId();

        LoadAssetInfo loadAssetInfo = GetTempLoadAssetInfo();

        loadAssetInfo.requestId   = requestId;
        loadAssetInfo.assetName   = assetName;
        loadAssetInfo.onLoadAsset = onLoadAsset;
        loadAssetInfo.bundleName  = abName;
        EnterLoadWait(loadAssetInfo);

        // 1 asset是否已加载
        if (ReferenceObject.IsObjectCreate(loadAssetInfo.assetName))
        {
            EnterWaitCall(loadAssetInfo);
        }

        // 2 bundle是否已加载
        else if (!ReferenceBundle.IsAssetBundleCraete(abName))
        {
            PushPending(loadAssetInfo);
        }

        // 3 从bundle加载资源
        else
        {
            List <LoadAssetInfo> loadingAssetList = GetLoadAssetStateList(LoadAssetStep.Loading);
            if (loadingAssetList.Count < _frameLoadMaxCount)
            {
                LoadAssetAsync(loadAssetInfo);
            }
        }

        _loadAssetInfoList.Add(loadAssetInfo);

        return(requestId);
    }
Esempio n. 10
0
    /// <summary>
    /// Procedural generation of map via Cellular automaton.
    /// </summary>
    private void CellularAutomatonGeneration(Level level)
    {
        if (level.height < Level.MinHeight || level.width < Level.MinWidth)
        {
            GameLogger.LogError("Level is too small", "CaveGenerator");
            level.height = Level.MinHeight;
            level.width  = Level.MinWidth;
        }

        // Rate for random cellar placement
        const float initRate = 0.5f;

        // Initialization
        level.objectMap = new MapObject[level.height, level.width];
        for (int i = 0; i < level.height; i++)
        {
            for (int j = 0; j < level.width; j++)
            {
                if (i < Level.BorderSize || i >= level.height - Level.BorderSize || j < Level.BorderSize || j >= level.width - Level.BorderSize)
                {
                    level.objectMap[i, j] = MapObject.Wall;
                    continue;
                }

                if (Random.value < initRate)
                {
                    level.objectMap[i, j] = MapObject.Wall;
                }
                else
                {
                    level.objectMap[i, j] = MapObject.Floor;
                }
            }
        }

        this.MakeAutomatonSteps(level.objectMap, 4, 4, 10);

        for (int i = 0; i < level.height; i++)
        {
            level.objectMap[i, 0] = MapObject.Wall;
            level.objectMap[i, level.width - 1] = MapObject.Wall;
        }

        for (int i = 0; i < level.width; i++)
        {
            level.objectMap[0, i] = MapObject.Wall;
            level.objectMap[level.height - 1, i] = MapObject.Wall;
        }

        this.MakeConnectedCave(level);
    }
Esempio n. 11
0
    public void PlaceOre(Level level, MapObject[] ores, int[] oreCounts, float[] chunkChances)
    {
        const int maxPerVein = 6;

        List <Vector2Int> deadends = this.FindDeadEnds(level);
        int deadendsIndx           = 0;

        for (int ore = 0; ore < ores.Length; ore++)
        {
            float chance = (float)oreCounts[ore] / (level.width * level.height);
            while (oreCounts[ore] > 0)
            {
                int x, y;

                if (deadendsIndx < deadends.Count)
                {
                    x = deadends[deadendsIndx].x;
                    y = deadends[deadendsIndx].y;
                    deadendsIndx++;
                }
                else
                {
                    int attempts = 0;
                    int neighbours;
                    do
                    {
                        if (attempts > 500)
                        {
                            GameLogger.LogError($"Too many attempts to spawn ore {ore}", "CaveGenerator");
                            return;
                        }

                        neighbours = 0;
                        x          = (int)(Random.value * (level.width - 2)) + 1;
                        y          = (int)(Random.value * (level.height - 2)) + 1;
                        attempts++;
                        for (int k = 0; k < 8; k++)
                        {
                            if (level.objectMap[y + Utility.Dy[k], x + Utility.Dx[k]] == MapObject.Wall)
                            {
                                neighbours++;
                            }
                        }
                    } while (level.objectMap[y, x] != MapObject.Floor || neighbours < 3);
                }

                oreCounts[ore] -= this.VeinPlacement(level, x, y, ores[ore], Mathf.Min(oreCounts[ore], maxPerVein), chunkChances[ore]);
            }
        }
    }
Esempio n. 12
0
    /// <summary>
    /// Add assets from <paramref name="arr"/> to floorAsset Dictionary.
    /// </summary>
    /// <param name="arr"> An array of assets. </param>
    /// <param name="alias"> Key in floorAssets dictionary. </param>
    public void AddFloorAsset(GameObject[] arr, MapObject alias)
    {
        if (arr == null || arr.Length == 0)
        {
            GameLogger.LogError($"LevelManager: Asset: {alias} is not set yet", "Level");
            return;
        }

        this.floorAssets.Add(alias, new List <GameObject>());

        for (int i = 0; i < arr.Length; i++)
        {
            this.floorAssets[alias].Add(arr[i]);
        }
    }
 static int LogError(IntPtr L)
 {
     try
     {
         int      count = LuaDLL.lua_gettop(L);
         string   arg0  = ToLua.CheckString(L, 1);
         string[] arg1  = ToLua.CheckParamsString(L, 2, count - 1);
         GameLogger.LogError(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
    {
        if (!enabled)
        {
            return(true);
        }

        Sprite sprite = image.overrideSprite;

        if (sprite == null)
        {
            return(true);
        }

        Vector2 local;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(image.rectTransform, screenPoint, eventCamera, out local);

        Rect rect = image.rectTransform.rect;

        // Convert to have lower left corner as reference point.
        local.x += image.rectTransform.pivot.x * rect.width;
        local.y += image.rectTransform.pivot.y * rect.height;

        float u = local.x / rect.width;
        float v = local.y / rect.height;

        try
        {
            if (!reversed)
            {
                return(sprite.texture.GetPixelBilinear(u, v).a != 0);
            }
            else
            {
                return(sprite.texture.GetPixelBilinear(u, v).a == 0);
            }
        }
        catch (UnityException e)
        {
            GameLogger.LogError(e);
        }

        return(true);
    }
Esempio n. 15
0
    /// <summary>
    /// Instantiates object of type <paramref name="alias"/> on level and returns it.
    /// </summary>
    /// <param name="alias"> Internal object type. </param>
    /// <param name="pos"> Position of instantiating. </param>
    /// <param name="isInit"> Is it initialization of map. </param>
    /// <returns> Instantiated object. </returns>
    private GameObject InstantiateOnMap(MapObject alias, Vector2 pos, bool isInit = false)
    {
        if (!isInit)
        {
            MonoBehaviour.Destroy(this.map[(int)pos.y][(int)pos.x].obj);
        }

        GameObject obj = Instantiate(this.dummy, pos, Quaternion.identity);

        obj.transform.SetParent(this.grid.transform);

        obj.GetComponent <EditorDummy>().attachedObject = this.brushes[alias];

        if (alias >= MapObject.PortalRed && alias <= MapObject.PortalYellow)
        {
            obj.GetComponent <EditorDummy>().attachedObject.GetComponent <Portal>().SetupPortal(null, alias);
            if (this.portalMap[alias].Item1 == null && this.portalMap[alias].Item2 == null)
            {
                this.portalMap[alias].Item1 = obj;
            }
            else if (this.portalMap[alias].Item1 != null && this.portalMap[alias].Item2 == null)
            {
                this.portalMap[alias].Item2 = obj;
            }
            else
            {
                GameLogger.LogError($"Too many portals of color {alias}", "EditorManager");
                return(null);
            }
        }

        obj.GetComponent <EditorDummy>().UpdateSprite();
        if (isInit)
        {
            this.map[(int)pos.y].Add(new GridObject(alias, obj));
        }
        else
        {
            this.map[(int)pos.y][(int)pos.x].obj   = obj;
            this.map[(int)pos.y][(int)pos.x].alias = alias;
        }

        return(obj);
    }
Esempio n. 16
0
    //C#传递lua表到Lua脚本
    void TestTableToLua()
    {
        m_luastate.LuaCreateTable(0, 0);
        LuaTable tab = m_luastate.CheckLuaTable(-1);

        tab["name"] = "zzf";
        tab["id"]   = 10001;

        m_luastate.LuaCreateTable();
        LuaTable tab1 = m_luastate.CheckLuaTable(-1);

        for (int i = 0; i < 10; ++i)
        {
            m_luastate.LuaCreateTable(0, 0);
            LuaTable tempTab = m_luastate.CheckLuaTable(-1);
            for (int j = 0; j < 10; ++j)
            {
                tempTab[j + 1] = 100 + j;
            }
            tab1[i + 1] = tempTab;
        }
        tab["data"] = tab1;
        LuaFunction luaFunc = m_luastate.GetFunction("TestTableToLua");

        luaFunc.Call(tab);

        System.Action <object[]> func1 = delegate(object[] objs)
        {
            if (objs.Length == 2)
            {
                GameLogger.LogGreen("data  1 = " + System.Convert.ToInt32(objs[0]));
                GameLogger.LogGreen("data  2 = " + System.Convert.ToString(objs[1]));
            }
        };

        System.Action func2 = delegate()
        {
            GameLogger.LogError("--------------");
        };
        LuaFunction luaFunc2 = m_luastate.GetFunction("TestCSharpDelegate");

        luaFunc2.Call(func2);
    }
Esempio n. 17
0
    private void Start()
    {
        if (this.hordeEntities.Length != this.entitiesCounts.Length || this.entitiesCounts.Length != this.dCounts.Length)
        {
            GameLogger.LogError("Arrays have different lengths", "HordeManager");
            return;
        }

        if (GameManager.instance.currentLevelNumber == 5)
        {
            return;
        }

        for (int i = 0; i < this.dCounts.Length; i++)
        {
            this.dCounts[i] += this.dCounts[i] * GameManager.instance.currentLevelNumber / 5;
        }

        this.StartCoroutine(this.Setup(GameManager.instance.levelManager.currentLevel));
    }
        /// <summary>
        /// 获取 content的SizeDalta
        /// </summary>
        private void SetContentSizeDelta()
        {
            var sizeDelta = mContent.sizeDelta;

            if (mScroll.horizontal)
            {
                sizeDelta.x = mContentCellSize;
                sizeDelta.y = mLayoutGroup.cellSize.y;
            }
            else if (mScroll.vertical)
            {
                sizeDelta.y = mContentCellSize;
                sizeDelta.x = mLayoutGroup.cellSize.x;
            }
            else
            {
                GameLogger.LogError("InfiniteList ScrollView only accept horizontal or vertical");
            }
            mContent.sizeDelta = sizeDelta;
        }
        private void InitOriginData()
        {
            GetCurrentType();
            if (mScroll.horizontal)
            {
                mContentValue = mContent.anchoredPosition3D.x;
                mSpaceing     = mLayoutGroup.spacing.x;
                mCellSize     = mLayoutGroup.cellSize.x;
                mViewPortRect = mViewPort.rect.width;
            }
            else if (mScroll.vertical)
            {
                mContentValue = mContent.anchoredPosition3D.y;
                mSpaceing     = mLayoutGroup.spacing.y;
                mCellSize     = mLayoutGroup.cellSize.y;
                mViewPortRect = mViewPort.rect.height;
            }
            else
            {
                GameLogger.LogError("InfiniteList ScrollView only accept horizontal or vertical");
            }
            var space = mSpaceing + mCellSize;

            mContentCellSize = mTotalDataCount * space - mSpaceing;

            var Delta = mContentCellSize - mViewPortRect;

            mBaseoffsetValue = (mSpaceing + mCellSize) / (Delta);
            if (mBaseoffsetValue < 0)
            {
                mBaseoffsetValue = 1;
            }
            var LayoutSpacing = mSpaceing + mCellSize;

            mMaxNum = (int)(mViewPortRect / LayoutSpacing) + 2;
            if (mMaxNum >= mTotalDataCount)
            {
                mMaxNum = mTotalDataCount;
            }
        }
Esempio n. 20
0
        // Use this for initialization
        void Start()
        {
            float base_number = 0;

            base_number = 16777200f;
            base_number = 16777200.22f;
            base_number = 16777216f;
            base_number = 16777216.6666f;
            base_number = 99999992f;
            base_number = 99999993f;
            base_number = 99999994f;
            base_number = 99999995f;
            base_number = 99999996f;
            base_number = 99999997f;
            base_number = 99999998f;
            base_number = 99999999f;

            decimal dec_number = 9999999999;

            dec_number = dec_number * 10;


            float proccess = Mathf.Lerp(0f, base_number, 1f);

            GameLogger.LogError("process = " + proccess.ToString());
            long long_process = (long)proccess;

            GameLogger.LogError("long_process = " + long_process.ToString());

            float long_process_ex = base_number * 1f;

            GameLogger.LogError("long_process_ex = " + long_process_ex.ToString());
            long long_process_exx = (long)long_process_ex;

            GameLogger.LogError("long_process_exx = " + long_process_exx.ToString());
        }
Esempio n. 21
0
 public static void LogError(object obj)
 {
     GameLogger.LogError(obj);
 }
Esempio n. 22
0
 public static void LogError(string str)
 {
     GameLogger.LogError(str);
 }