Exemplo n.º 1
0
 public void ResetVoxelGridToBackgroundColor()
 {
     for (int x = 0; x < worldSizeX; x++)
     {
         for (int y = 0; y < worldSizeY; y++)
         {
             for (int z = 0; z < worldSizeZ; z++)
             {
                 mImageSetter.SetPixelColor(x + z * worldSizeX, y, backgroundColor, false);
             }
         }
     }
 }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        ImageSetter editorObj = target as ImageSetter;

        if (editorObj == null)
        {
            return;
        }

        if (GUILayout.Button("UpdateInternalTexture"))
        {
            editorObj.UpdateInternalTexture();
        }

        editorObj.pixelPosX = EditorGUILayout.IntField("Pixel Position X:", editorObj.pixelPosX);
        editorObj.pixelPosY = EditorGUILayout.IntField("Pixel Position Y:", editorObj.pixelPosY);
        editorObj.newColor  = EditorGUILayout.ColorField("New Color", editorObj.newColor);

        if (GUILayout.Button("Set Pixel"))
        {
            editorObj.SetPixelColor(editorObj.pixelPosX,
                                    editorObj.pixelPosY,
                                    editorObj.newColor);
        }

        OnDebugGrid(editorObj, editorObj.imageSizeX, editorObj.imageSizeY);
    }
Exemplo n.º 3
0
    void Start()
    {
        mImageSetter = GetComponent <ImageSetter>();

        mCurrent.x = initialPlayerPositionX;
        mCurrent.y = initialPlayerPositionY;
        mCurrent.z = initialPlayerPositionZ;

        if (shouldResetGridAtStart)
        {
            ResetVoxelGridToBackgroundColor();
        }

        // Set initial player position
        mImageSetter.SetPixelColor(mCurrent.x + mCurrent.z * worldSizeX, mCurrent.y, playerColor);

        mLastDirection = new Int3(0, 0, 1);

        mCurrent = Int3.random(Int3.zero(), mWorldSize);
        // mCurrent = new Int3(mCurrentX, mCurrentY, mCurrentZ);
        mWorldSize = new Int3(worldSizeX, worldSizeY, worldSizeZ);

        snakeBody = new List <Int3>();
        snakeBody.Add(mCurrent);

        PlaceFoodAtRandom();
    }
Exemplo n.º 4
0
    void Start()
    {
        mImageSetter = GetComponent <ImageSetter>();

        mCurrentX = initialPlayerPositionX;
        mCurrentY = initialPlayerPositionY;
        mCurrentZ = initialPlayerPositionZ;

        for (int x = 0; x < worldSizeX; x++)
        {
            for (int y = 0; y < worldSizeY; y++)
            {
                for (int z = 0; z < worldSizeZ; z++)
                {
                    mImageSetter.SetPixelColor(x + z * worldSizeX, y, backgroundColor, false);
                }
            }
        }

        mImageSetter.SetPixelColor(mCurrentX + mCurrentZ * worldSizeX, mCurrentY, playerColor);
    }
Exemplo n.º 5
0
    // Use this for initialization

    // Update is called once per frame
    void Update()
    {
        mLastX = mCurrentX;
        mLastY = mCurrentY;
        mLastZ = mCurrentZ;

        if (Input.GetKeyUp(KeyCode.W))
        {
            mCurrentZ = (mCurrentZ + 1) % worldSizeZ;
        }
        if (Input.GetKeyUp(KeyCode.S))
        {
            mCurrentZ = (worldSizeZ + mCurrentZ - 1) % worldSizeZ;
        }
        if (Input.GetKeyUp(KeyCode.A))
        {
            mCurrentX = (worldSizeX + mCurrentX - 1) % worldSizeX;
        }
        if (Input.GetKeyUp(KeyCode.D))
        {
            mCurrentX = (mCurrentX + 1) % worldSizeX;
        }
        if (Input.GetKeyUp(KeyCode.Q))
        {
            mCurrentY = (worldSizeY + mCurrentY - 1) % worldSizeY;
        }
        if (Input.GetKeyUp(KeyCode.E))
        {
            mCurrentY = (mCurrentY + 1) % worldSizeY;
        }

        if (mLastX != mCurrentX ||
            mLastY != mCurrentY ||
            mLastZ != mCurrentZ)
        {
            mImageSetter.SetPixelColor(mLastX + mLastZ * worldSizeX, mLastY, backgroundColor);
            mImageSetter.SetPixelColor(mCurrentX + mCurrentZ * worldSizeX, mCurrentY, playerColor);
        }
    }
Exemplo n.º 6
0
    public void OnDebugGrid(ImageSetter editorObj, int sizeX, int sizeY)
    {
        editorObj.currentGridPosX = EditorGUILayout.IntField("Grid Start Position X:", editorObj.currentGridPosX);
        editorObj.currentGridPosY = EditorGUILayout.IntField("Grid Start Position Y:", editorObj.currentGridPosY);

        // Number of Cells
        int cols = 25, rows = 15;

        float gridItemWidth = maxInnerWidth / (1.0f * cols);

        // GUI.Box(new Rect(5,5, 800, 800), "Colors");
        // GUILayout.BeginArea(new Rect(10, 10, 700, 700));
        GUILayout.BeginVertical();
        for (int y = 0; y < rows && y < sizeY - editorObj.currentGridPosY; y++)
        {
            GUILayout.BeginHorizontal();
            for (int x = 0; x < cols && x < sizeX - editorObj.currentGridPosX; x++)
            {
                Color lastColor = editorObj.GetPixelColor(x + editorObj.currentGridPosX,
                                                          y + editorObj.currentGridPosY);

                Color newColor = EditorGUILayout.ColorField(GUIContent.none,
                                                            // colorGrid.GetColor(x, y),
                                                            lastColor,
                                                            false, true, false, null, GUILayout.Width(gridItemWidth));

                if (lastColor != newColor)
                {
                    editorObj.SetPixelColor(x + editorObj.currentGridPosX,
                                            y + editorObj.currentGridPosY,
                                            newColor);
                }
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();
        // GUILayout.EndArea();
    }