コード例 #1
0
        private void drawPiece(QMazePieceType pieceType, string pieceName, Texture2D pieceIcon, bool specOptions = false)
        {
            QMazePiece piece = mazePiecePack.getPiece(pieceType);

            GUILayout.Box(pieceIcon);
            GUILayout.BeginVertical();
            {
                drawPieceGeometryList(pieceName, piece);

                bool found      = false;
                bool errorFound = false;
                for (int i = 0; i < piece.geometryList.Count; i++)
                {
                    if (piece.geometryList[i] != null)
                    {
                        found = true;
                    }
                    else
                    {
                        errorFound = true;
                    }
                }

                if (piece.require && !found)
                {
                    EditorGUILayout.HelpBox("Piece geometry is required", MessageType.Warning);
                }
                else if (errorFound)
                {
                    EditorGUILayout.HelpBox("One of the elements is null", MessageType.Warning);
                }

                if (specOptions)
                {
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(20);
                        GUILayout.Label("Use");
                        piece.use = EditorGUILayout.Toggle(piece.use, GUILayout.Width(40));
                    }
                    GUILayout.EndHorizontal();

                    if (piece.use)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Space(20);
                            GUILayout.Label("Frequency", GUILayout.MinWidth(40));
                            piece.frequency = Mathf.Clamp01(EditorGUILayout.FloatField(piece.frequency, GUILayout.Width(40)));
                        }
                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUILayout.EndVertical();
        }
コード例 #2
0
        private void addPiece(QMazePieceType type, bool require, bool use, float frequency, params QMazeOutput[] mazeOutput)
        {
            List <QMazeOutput> outputs = new List <QMazeOutput>();

            for (int i = 0; i < mazeOutput.Length; i++)
            {
                outputs.Add(mazeOutput[i]);
            }
            mazePieceArray[(int)type] = new QMazePiece(type, require, use, frequency, outputs);
        }
コード例 #3
0
        private void checkGeometryList(QMazePiece piece)
        {
            List <GameObject> geometryList = piece.geometryList;

            for (int i = 0; i < geometryList.Count; i++)
            {
                if (geometryList[i] == null)
                {
                    geometryList.RemoveAt(i);
                    i--;
                }
            }
        }
コード例 #4
0
        private void drawPieceGeometryList(string pieceName, QMazePiece piece)
        {
            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button(addButton, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(20)))
                {
                    piece.geometryList.Add(null);
                }

                Rect rect = GUILayoutUtility.GetRect(50, 150, 10, 20);
                rect.x += 3;
                rect.y += 2;
                EditorGUI.LabelField(rect, pieceName);
            }
            GUILayout.EndHorizontal();
            if (piece.geometryList.Count > 0)
            {
                for (int i = 0; i < piece.geometryList.Count; i++)
                {
                    GUILayout.BeginHorizontal();
                    {
                        bool remove = GUILayout.Button(removeButton, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(20));
                        piece.geometryList[i] = (GameObject)EditorGUILayout.ObjectField(piece.geometryList[i], typeof(GameObject), true, GUILayout.MinWidth(80));
                        if (remove)
                        {
                            piece.geometryList.RemoveAt(i);
                            i--;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(20);
                    GameObject gameObject = (GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), true, GUILayout.MinWidth(80));
                    if (gameObject != null)
                    {
                        piece.geometryList.Add(gameObject);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
 private void drawPieceGeometryList(string pieceName, QMazePiece piece)
 {
     GUILayout.BeginHorizontal();
     {
         if (GUILayout.Button(addButton, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(20)))
             piece.geometryList.Add(null);
         GUILayout.Label(pieceName);
     }
     GUILayout.EndHorizontal();
     if (piece.geometryList.Count > 0)
     {
         for(int i = 0; i < piece.geometryList.Count; i++)
         {
             GUILayout.BeginHorizontal();
             {
                 bool remove = GUILayout.Button(removeButton,  GUIStyle.none, GUILayout.Width(16), GUILayout.Height(20));
                 piece.geometryList[i] = (GameObject)EditorGUILayout.ObjectField(piece.geometryList[i], typeof(GameObject), true, GUILayout.MinWidth(90));
                 if (remove)
                 {
                     piece.geometryList.RemoveAt(i);
                     i--;
                 }
             }
             GUILayout.EndHorizontal();
         }
     }
     else
     {
         GUILayout.BeginHorizontal();
         {
             GUILayout.Space(20);
             GameObject gameObject = (GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), true, GUILayout.MinWidth(90));
             if (gameObject != null)	piece.geometryList.Add(gameObject);
         }
         GUILayout.EndHorizontal();
     }
 }
コード例 #6
0
 private void addPiece(QMazePieceType type, bool require, bool use, float frequency, params QMazeOutput[] mazeOutput)
 {
     List<QMazeOutput> outputs = new List<QMazeOutput>();
     for (int i = 0; i < mazeOutput.Length; i++) outputs.Add(mazeOutput[i]);
     mazePieceArray[(int)type] = new QMazePiece(type, require, use, frequency, outputs);
 }
コード例 #7
0
 private void checkGeometryList(QMazePiece piece)
 {
     List<GameObject> geometryList = piece.geometryList;
     for (int i = 0; i < geometryList.Count; i++)
     {
         if (geometryList[i] == null)
         {
             geometryList.RemoveAt(i);
             i--;
         }
     }
 }
コード例 #8
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;
        }