private void Awake()
        {
            if (!inited)
            {
                inited = true;

                if (gameObject.GetComponent <QMazeGeometryGenerator>() == null)
                {
                    mazeGeometryGenerator = gameObject.AddComponent <QMazeGeometryGenerator>();
                }

                if (gameObject.GetComponent <QMazePiecePack>() == null)
                {
                    piecePack = gameObject.AddComponent <QMazePiecePack>();
                }
            }
        }
예제 #2
0
        private void OnEnable()
        {
            mazePiecePack = (QMazePiecePack)target;

            inited    = serializedObject.FindProperty("inited");
            greyLight = EditorGUIUtility.isProSkin ? new Color(0.25f, 0.25f, 0.25f) :  new Color(0.8f, 0.8f, 0.8f);

            customPieces = serializedObject.FindProperty("dragAndDropPieceGeometryArray");
            QInspectorUtils.SetIcon(mazePiecePack, QInspectorUtils.getAsset <Texture2D>("MazePiecePackIcon t:texture2D"));

            pieceIconNone = QInspectorUtils.getAsset <Texture2D>("PieceIconNone t:texture2D");
            pieceIconLine = QInspectorUtils.getAsset <Texture2D>("PieceIconLine t:texture2D");

            pieceIconDeadlock = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadLock t:texture2D");
            pieceIconTriple   = QInspectorUtils.getAsset <Texture2D>("PieceIconTriple t:texture2D");

            pieceIconCorner   = QInspectorUtils.getAsset <Texture2D>("PieceIconCorner t:texture2D");
            pieceIconCrossing = QInspectorUtils.getAsset <Texture2D>("PieceIconCrossing t:texture2D");

            pieceIconStart  = QInspectorUtils.getAsset <Texture2D>("PieceIconStart t:texture2D");
            pieceIconFinish = QInspectorUtils.getAsset <Texture2D>("PieceIconFinish t:texture2D");

            pieceIconDoubleCorner = QInspectorUtils.getAsset <Texture2D>("PieceIconDoubleCorner t:texture2D");
            pieceIconIntersection = QInspectorUtils.getAsset <Texture2D>("PieceIconIntersection t:texture2D");

            pieceIconDeadlockCorner = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockCorner t:texture2D");
            pieceIconDeadlockLine   = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockLine t:texture2D");

            pieceIconDeadlockTriple   = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockTriple t:texture2D");
            pieceIconDeadlockCrossing = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockCrossing t:texture2D");

            pieceIconTripleDeadlock = QInspectorUtils.getAsset <Texture2D>("PieceIconTripleDeadlock t:texture2D");
            pieceIconLineDeadlock   = QInspectorUtils.getAsset <Texture2D>("PieceIconLineDeadlock t:texture2D");

            pieceIconLineDeadlockLine   = QInspectorUtils.getAsset <Texture2D>("PieceIconLineDeadlockLine t:texture2D");
            pieceIconCornerDeadlockLeft = QInspectorUtils.getAsset <Texture2D>("PieceIconCornerDeadlockLeft t:texture2D");

            pieceIconCornerDeadlockRight  = QInspectorUtils.getAsset <Texture2D>("PieceIconCornerDeadlockRight t:texture2D");
            pieceIconCornerDeadlockCorner = QInspectorUtils.getAsset <Texture2D>("PieceIconCornerDeadlockCorner t:texture2D");

            addButton    = QInspectorUtils.getAsset <Texture2D>("AddButton t:texture2D");
            removeButton = QInspectorUtils.getAsset <Texture2D>("RemoveButton t:texture2D");
        }
예제 #3
0
        private void OnEnable()
        {
            mazePiecePack = (QMazePiecePack)target;

            pieceIconEmpty = QInspectorUtils.getAsset <Texture2D>("PieceIconEmpty t:texture2D");
            pieceIconLine  = QInspectorUtils.getAsset <Texture2D>("PieceIconLine t:texture2D");

            pieceIconDeadlock = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadLock t:texture2D");
            pieceIconTriple   = QInspectorUtils.getAsset <Texture2D>("PieceIconTripple t:texture2D");

            pieceIconCorner   = QInspectorUtils.getAsset <Texture2D>("PieceIconCorner t:texture2D");
            pieceIconCrossing = QInspectorUtils.getAsset <Texture2D>("PieceIconCrossing t:texture2D");

            pieceIconStart  = QInspectorUtils.getAsset <Texture2D>("PieceIconStart t:texture2D");
            pieceIconFinish = QInspectorUtils.getAsset <Texture2D>("PieceIconFinish t:texture2D");

            pieceIconDoubleCorner = QInspectorUtils.getAsset <Texture2D>("PieceIconDoubleCorner t:texture2D");
            pieceIconIntersection = QInspectorUtils.getAsset <Texture2D>("PieceIconIntersection t:texture2D");

            pieceIconDeadlockCorner = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockCorner t:texture2D");
            pieceIconDeadlockLine   = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockLine t:texture2D");

            pieceIconDeadlockTriple   = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockTripple t:texture2D");
            pieceIconDeadlockCrossing = QInspectorUtils.getAsset <Texture2D>("PieceIconDeadlockCrossing t:texture2D");

            pieceIconTripleDeadlock = QInspectorUtils.getAsset <Texture2D>("PieceIconTrippleDeadlock t:texture2D");
            pieceIconLineDeadlock   = QInspectorUtils.getAsset <Texture2D>("PieceIconLineDeadlock t:texture2D");

            pieceIconLineDeadlockLine = QInspectorUtils.getAsset <Texture2D>("PieceIconLineDeadlockLine t:texture2D");
            pieceIconCornerDeadlock1  = QInspectorUtils.getAsset <Texture2D>("PieceIconCornerDeadlock t:texture2D");

            pieceIconCornerDeadlock2      = QInspectorUtils.getAsset <Texture2D>("PieceIconCornerDeadlock2 t:texture2D");
            pieceIconCornerDeadlockCorner = QInspectorUtils.getAsset <Texture2D>("PieceIconCornerDeadlockCorner t:texture2D");

            addButton    = QInspectorUtils.getAsset <Texture2D>("AddButton t:texture2D");
            removeButton = QInspectorUtils.getAsset <Texture2D>("RemoveButton t:texture2D");
        }
        private void Awake()
        {
            if (!inited)
            {
                inited = true;

                if (gameObject.GetComponent<QMazeGeometryGenerator>() == null)
                    mazeGeometryGenerator = gameObject.AddComponent<QMazeGeometryGenerator>();

                if (gameObject.GetComponent<QMazePiecePack>() == null)
                    piecePack = gameObject.AddComponent<QMazePiecePack>();
            }
        }
        private void OnEnable()
        {
            mazePiecePack = (QMazePiecePack)target;

            pieceIconEmpty = QInspectorUtils.getAsset<Texture2D>("PieceIconEmpty t:texture2D");
            pieceIconLine = QInspectorUtils.getAsset<Texture2D>("PieceIconLine t:texture2D");

            pieceIconDeadlock = QInspectorUtils.getAsset<Texture2D>("PieceIconDeadLock t:texture2D");
            pieceIconTriple = QInspectorUtils.getAsset<Texture2D>("PieceIconTripple t:texture2D");

            pieceIconCorner = QInspectorUtils.getAsset<Texture2D>("PieceIconCorner t:texture2D");
            pieceIconCrossing = QInspectorUtils.getAsset<Texture2D>("PieceIconCrossing t:texture2D");

            pieceIconStart = QInspectorUtils.getAsset<Texture2D>("PieceIconStart t:texture2D");
            pieceIconFinish = QInspectorUtils.getAsset<Texture2D>("PieceIconFinish t:texture2D");

            pieceIconDoubleCorner = QInspectorUtils.getAsset<Texture2D>("PieceIconDoubleCorner t:texture2D");
            pieceIconIntersection = QInspectorUtils.getAsset<Texture2D>("PieceIconIntersection t:texture2D");

            pieceIconDeadlockCorner = QInspectorUtils.getAsset<Texture2D>("PieceIconDeadlockCorner t:texture2D");
            pieceIconDeadlockLine = QInspectorUtils.getAsset<Texture2D>("PieceIconDeadlockLine t:texture2D");

            pieceIconDeadlockTriple = QInspectorUtils.getAsset<Texture2D>("PieceIconDeadlockTripple t:texture2D");
            pieceIconDeadlockCrossing = QInspectorUtils.getAsset<Texture2D>("PieceIconDeadlockCrossing t:texture2D");

            pieceIconTripleDeadlock = QInspectorUtils.getAsset<Texture2D>("PieceIconTrippleDeadlock t:texture2D");
            pieceIconLineDeadlock = QInspectorUtils.getAsset<Texture2D>("PieceIconLineDeadlock t:texture2D");

            pieceIconLineDeadlockLine = QInspectorUtils.getAsset<Texture2D>("PieceIconLineDeadlockLine t:texture2D");
            pieceIconCornerDeadlock1 = QInspectorUtils.getAsset<Texture2D>("PieceIconCornerDeadlock t:texture2D");

            pieceIconCornerDeadlock2 = QInspectorUtils.getAsset<Texture2D>("PieceIconCornerDeadlock2 t:texture2D");
            pieceIconCornerDeadlockCorner = QInspectorUtils.getAsset<Texture2D>("PieceIconCornerDeadlockCorner t:texture2D");

            addButton = QInspectorUtils.getAsset<Texture2D>("AddButton t:texture2D");
            removeButton = QInspectorUtils.getAsset<Texture2D>("RemoveButton t:texture2D");
        }
예제 #6
0
        public IEnumerator generateGeometry(QMazeEngine mazeEngine, List <QMazeOutput>[][] mazeArray, float maxTime = 0.1f)
        {
            Vector3    transformPosition = transform.position;
            Quaternion transformRotation = transform.rotation;

            transform.rotation = Quaternion.identity;

            float time       = Time.realtimeSinceStartup;
            int   mazeWidth  = mazeEngine.mazeWidth;
            int   mazeHeight = mazeEngine.mazeHeight;
            float mazeSize   = mazeWidth * mazeHeight;
            float count      = 0;

            instantiatingProgress = 0;
            bool wasError = false;

            QMazePiecePack    piecePack = mazeEngine.piecePack;
            List <QMazePiece> pieces    = piecePack.toMazePieceList();

            for (int i = 0; i < pieces.Count; i++)
            {
                if ((!pieces[i].use && !pieces[i].require) ||
                    pieces[i].type == QMazePieceType.Start ||
                    pieces[i].type == QMazePieceType.Finish)
                {
                    pieces.RemoveAt(i);
                    i--;
                }
            }

            for (int ix = 0; ix < mazeWidth; ix++)
            {
                for (int iy = 0; iy < mazeHeight; iy++)
                {
                    List <QMazeOutput> mazeOutputData = mazeArray[ix][iy];

                    QMazePiece targetPiece = null;

                    if (QListUtil.has(mazeEngine.startPointList, ix, iy) && mazeOutputData != null && piecePack.getPiece(QMazePieceType.Start).checkFit(mazeOutputData))
                    {
                        targetPiece = piecePack.getPiece(QMazePieceType.Start);
                    }
                    else if (QListUtil.has(mazeEngine.finishPointList, ix, iy) && mazeOutputData != null && piecePack.getPiece(QMazePieceType.Finish).checkFit(mazeOutputData))
                    {
                        targetPiece = piecePack.getPiece(QMazePieceType.Finish);
                    }
                    else
                    {
                        QListUtil.Shuffle <QMazePiece>(pieces);
                        for (int i = 0; i < pieces.Count; i++)
                        {
                            if (pieces[i].checkFit(mazeOutputData))
                            {
                                targetPiece = pieces[i];
                                break;
                            }
                        }
                    }

                    if (targetPiece == null)
                    {
                        if (mazeEngine.pointInMaze(new QVector2Int(ix, iy)) || mazeEngine.obstacleIsEmpty)
                        {
                            targetPiece = piecePack.getPiece(QMazePieceType.Empty);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (targetPiece.geometryList.Count == 0)
                    {
                        if (mazeEngine.pointInMaze(new QVector2Int(ix, iy)))
                        {
                            if (!wasError)
                            {
                                wasError = true;
                                Debug.LogWarning("QMaze: Geometry for " + targetPiece.type + " piece is not found. Please check that geometry is specified for it in the piece pack.");
                            }
                        }
                        continue;
                    }

                    GameObject prefab = targetPiece.geometryList[QMath.getRandom(0, targetPiece.geometryList.Count)];
                    GameObject go;
                                        #if UNITY_EDITOR
                    if (Application.isPlaying)
                    {
                        go = (GameObject)GameObject.Instantiate(prefab, new Vector3(), Quaternion.AngleAxis(randomPiecesRotation ? ((int)(UnityEngine.Random.value * 360 / 90)) * 90 : -targetPiece.getRotation(), Vector3.up));
                    }
                    else
                    {
                        go = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
                        go.transform.rotation = Quaternion.AngleAxis(randomPiecesRotation ? ((int)(UnityEngine.Random.value * 360 / 90)) * 90 : -targetPiece.getRotation(), Vector3.up);
                    }
                                        #else
                    go = (GameObject)GameObject.Instantiate(prefab, new Vector3(), Quaternion.AngleAxis(randomPiecesRotation ? ((int)(UnityEngine.Random.value * 360 / 90)) * 90 : -targetPiece.getRotation(), Vector3.up));
                                        #endif
                    go.transform.position = transformPosition + new Vector3(ix * mazeEngine.mazePieceWidth, 0, -iy * mazeEngine.mazePieceHeight);
                    Vector3 scale = go.transform.localScale;
                    go.transform.parent     = transform;
                    go.transform.localScale = scale;

                    count++;
                    instantiatingProgress = count / mazeSize;

                    if (Time.realtimeSinceStartup - time > maxTime)
                    {
                        time = Time.realtimeSinceStartup;
                        yield return(null);
                    }
                }
            }

            transform.rotation = transformRotation;
        }