void Init()
    {
        snapToGrid.m_snapY = false;
        snapToGrid.m_lockY = true;
        snapToGrid.m_snapZ = false;
        snapToGrid.m_lockZ = true;
        transform.position = Vector3.zero;
        snapToGrid.UpdatePosition();

        // delete old children
        PatternChildControll[] childControls = GetComponentsInChildren <PatternChildControll>();

        foreach (PatternChildControll child in childControls)
        {
            if (Application.isPlaying)
            {
                Destroy(child.gameObject);
            }
            else
            {
                DestroyImmediate(child.gameObject);
            }
        }

        pattern = Pattern.bottom;

        children = new PatternChildControll[Constants.NUMBER_OF_PLAYERS];

        // spawn new children
        for (int i = 0; i < children.Length; i++)
        {
            children[i] = Instantiate(childrenPrefab, transform.position, Quaternion.identity) as PatternChildControll;
            children[i].transform.parent = transform;
            children[i].SetLocalPositionInGrid(i, pattern.coords[i]);
        }

        // add line renderer
        lineRenderer = gameObject.AddComponent <LineRenderer>();
    }
Esempio n. 2
0
    public override void OnInspectorGUI()
    {
        SnapToGrid script = (SnapToGrid)target;

        GUILayout.BeginHorizontal();

        GUILayout.Label("Snap X");
        script.m_snapX = EditorGUILayout.Toggle(script.m_snapX);
        GUILayout.Label("Snap Y");
        script.m_snapY = EditorGUILayout.Toggle(script.m_snapY);
        GUILayout.Label("Snap Z");
        script.m_snapZ = EditorGUILayout.Toggle(script.m_snapZ);

        GUILayout.EndHorizontal();


        if (script.m_snapX)
        {
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

            EditorGUILayout.BeginHorizontal();

            GUILayout.Label("X (time)", EditorStyles.boldLabel);

            EditorGUILayout.BeginVertical();
            GUILayout.Label("Bar");
            script.m_bar = EditorGUILayout.IntField(script.m_bar);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            GUILayout.Label("Beat");
            script.m_beat = EditorGUILayout.IntField(script.m_beat);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            GUILayout.Label("SubBeat");
            script.m_subBeat = EditorGUILayout.IntField(script.m_subBeat);
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();
        }

        if (script.m_snapY && script.m_snapZ)
        {
            // draw table
            float cellWidth = EditorGUIUtility.currentViewWidth / ((float)grid.GetLength(0) * 3 / 2);

            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Y&Z", EditorStyles.boldLabel, GUILayout.Width(cellWidth));
            // label row
            for (int x = 0; x < grid.GetLength(0); x++)
            {
                GUILayout.Label("" + x, GUILayout.Width(cellWidth));
            }
            EditorGUILayout.EndHorizontal();

            for (int y = grid.GetLength(1) - 1; y >= 0; y--)
            {
                EditorGUILayout.BeginHorizontal();

                GUILayout.Label("" + y, GUILayout.Width(cellWidth));                 // label column

                for (int x = 0; x < grid.GetLength(0); x++)
                {
                    string buttonText = (script.m_playerLane == x && script.m_verticalPosition == y) ? "X": " ";
                    if (GUILayout.Button(buttonText, GUILayout.Width(cellWidth)))
                    {
                        Undo.RecordObject(target, "SnapToGrid SetPosition");
                        script.SetPosition(x, y);
                        EditorUtility.SetDirty(target);
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
        }
        else if (script.m_snapY)
        {
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

            EditorGUILayout.BeginHorizontal();

            GUILayout.Label("Y (vertical position)", EditorStyles.boldLabel);
            script.m_verticalPosition = EditorGUILayout.IntSlider(script.m_verticalPosition, 0, Constants.VERTICAL_POSITIONS - 1);

            EditorGUILayout.EndHorizontal();
        }
        else if (script.m_snapZ)
        {
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

            EditorGUILayout.BeginHorizontal();

            GUILayout.Label("Z (player lane)", EditorStyles.boldLabel);
            script.m_playerLane = EditorGUILayout.IntSlider(script.m_playerLane, 0, Constants.NUMBER_OF_PLAYERS - 1);

            EditorGUILayout.EndHorizontal();
        }

        if (script.m_snapX || script.m_snapY || script.m_snapZ)
        {
            Undo.RecordObject(target, "SnapToGrid");
            script.UpdatePosition();
            EditorUtility.SetDirty(target);
        }
    }
    void PrepareEnvironmentTileAtBar(int bar)
    {
        if (environmentTileObjectsInScene.ContainsKey(bar))
        {
            return;
        }

        //Debug.Log("Preparing at " + bar);

        EnvironmentSet.EnvironmentTile nextTile;
        if (environmentTilesInScene.ContainsKey(bar - barsPerTile))
        {
            int index = environmentTilesInScene[bar - barsPerTile].GetNextTileRandom();
            nextTile = environmentSet.environmentTiles[index];
        }
        else
        {
            Mathf.Clamp(startAtIndex, 0, environmentSet.environmentTiles.Length - 1);
            nextTile = environmentSet.environmentTiles[startAtIndex];
        }

        GameObject tileObject          = GetTileFromList(nextTile);
        Transform  variationsTransform = tileObject.transform.FindChild("Variations");

        SnapToGrid snapToGrid = tileObject.GetComponent <SnapToGrid>();

        snapToGrid.m_snapX = true;
        snapToGrid.m_bar   = bar;
        snapToGrid.m_snapY = false;
        snapToGrid.m_snapZ = false;
        snapToGrid.UpdatePosition();


        if (variationsTransform != null)
        {
            //Debug.Log(nextTile.name + ": Enabling child " + variationsIndexDict[nextTile]);
            // enable variation game object
            //EnableChild(variationsTransform, variationsIndexDict[nextTile]);

            // set new variations index
            if (randomVariations)
            {
                variationsIndexDict[nextTile] = Random.Range(0, variationsLengthDict[nextTile]);
                EnableChild(variationsTransform, variationsIndexDict[nextTile]);
            }
            else
            {
                EnableChild(variationsTransform, variationsIndexDict[nextTile]);
                variationsIndexDict[nextTile] = (variationsIndexDict[nextTile] + 1) % variationsLengthDict[nextTile];
            }

            //Debug.Log(nextTile.name + ": Next index is " + variationsIndexDict[nextTile]);
        }
        else
        {
            Debug.Log(nextTile.name + ": no variations transform found");
        }


        environmentTileObjectsInScene.Add(bar, tileObject);
        environmentTilesInScene.Add(bar, nextTile);
    }