Пример #1
0
        private void Start()
        {
            //Setup the configuration. You only need to set the values you want different from the defaults that you can see on the GridConfig class.
            var gridCfg = new GridConfig
            {
                cellSize                 = 2f,
                generateHeightmap        = true,
                heightLookupType         = HeightLookupType.QuadTree,
                heightLookupMaxDepth     = 5,
                lowerBoundary            = 1f,
                upperBoundary            = 10f,
                obstacleSensitivityRange = 0.5f,
                sizeX                  = 16,
                sizeZ                  = 16,
                subSectionsX           = 2,
                subSectionsZ           = 2,
                subSectionsCellOverlap = 2,
                origin                 = this.gridHost.transform.position
            };

            //Create the grid instance
            var grid = GridComponent.Create(this.gridHost, gridCfg);

            //Initialize the grid
            grid.Initialize(10, g =>
            {
                Debug.Log("Initialization Done");
            });
        }
Пример #2
0
    public override void Initialize(Transform[] objects)
    {
        // list because I don't know size here
        List <Filter> tmpFilters = new List <Filter>();
        int           index      = 0;

        for (int i = 0; i < objects.Length; i++)
        {
            // check performance
            LightComponent lc = objects[i].GetComponent <LightComponent>();
            InputComponent ic = objects[i].GetComponent <InputComponent>();

            if (lc && ic)
            {
                tmpFilters.Add(new Filter(index, objects[i].gameObject, ic, lc));
                lightyComp = lc;
            }
        }

        filters = tmpFilters.ToArray();
        player.uiComponent.torchIndicator.SetImageFillAmount(1, 0f);
        player.uiComponent.torchIndicator.SetImageFillAmount(2, 0f);
        player.uiComponent.torchIndicator.SetImageFillAmount(3, 0f);
        gridComp = GetComponentInChildren <GridComponent>();
    }
Пример #3
0
        public static Vector3 GetCellPosition(GridComponent component)
        {
            if (component.GetType() == typeof(GridComponent))
            {
                var cell = component.CellLocations.First();

                //start is (1,1) aka middle
                var xChange         = cell.X - 1;
                var yChange         = cell.Y - 1;
                var xThicknessAdded = gridLineThickness * xChange;
                var yThicknessAdded = gridLineThickness * yChange;
                //var centerDistance =  / cellWidth;

                var x = xChange * cellWidth + xThicknessAdded;
                var y = yChange * cellWidth + yThicknessAdded;

                var divX = x == 0 ? 1 : ppu;
                var divY = y == 0 ? 1 : ppu;
                return(new Vector3(x / divX, y / divY, 0));
            }
            if (component.GetType() == typeof(Chip))
            {
                return(Vector3.zero);
            }
            return(Vector3.zero);
        }
Пример #4
0
        private void BuildGrids(Bounds b)
        {
            if (gridSize % cellSize != 0 || gridSize % cellSize != 0)
            {
                Debug.LogError("Grid Width and Grid Height must be a multiple of Cell Size");
            }

            var gridColumns = Mathf.FloorToInt(b.size.x / gridSize);
            var gridRows    = Mathf.FloorToInt(b.size.z / gridSize);

            var baseOrigin = b.min + new Vector3(gridSize * .5f, b.size.y, gridSize * .5f);
            var offset     = Vector3.zero;

            var cfg = new GridConfig
            {
                cellSize             = this.cellSize,
                sizeX                = (int)(gridSize / cellSize),
                sizeZ                = (int)(gridSize / cellSize),
                automaticConnections = true
            };

            for (int x = 0; x < gridColumns; x++)
            {
                for (int z = 0; z < gridRows; z++)
                {
                    offset.x   = x * gridSize;
                    offset.z   = z * gridSize;
                    cfg.origin = baseOrigin + offset;

                    GridComponent.Create(this.gridHost, cfg);
                }
            }
        }
        private static void BakeGrid(GridComponent g)
        {
            var builder = g.GetBuilder();

            var matrix = CellMatrix.Create(builder);

            var data = g.bakedData;

            if (data == null)
            {
                data = CellMatrixData.Create(matrix);

                g.bakedData = data;
            }
            else
            {
                data.Refresh(matrix);
            }

            if (g.storeBakedDataAsAsset)
            {
                EditorUtilitiesInternal.CreateOrUpdateAsset(data, g.friendlyName.Trim());
            }
            else
            {
                EditorUtility.SetDirty(data);
            }

            g.ResetGrid();
            EditorUtility.SetDirty(g);

            Debug.Log(string.Format("The grid {0} was successfully baked.", g.friendlyName));
        }
Пример #6
0
 public static void LoadLevel(GridComponent gridComponent, LevelData levelData)
 {
     if (levelData.Goals.Count < 1)
     {
         throw new MissingComponentException("No Goals set!");
     }
     foreach (FieldGridCoordinate goal in levelData.Goals)
     {
         gridComponent.Grid[goal.X, goal.Z].IsGoal = true;
         GameObject goalObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         goalObject.transform.position = gridComponent.Grid[goal.X, goal.Z].GetMiddlePoint();
         goalObject.GetComponent <Renderer>().material.color = Color.green;
         //goalObject.AddComponent<GoalController>();
     }
     if (levelData.Spawns.Count < 1)
     {
         throw new MissingComponentException("No spawn points set!");
     }
     foreach (FieldGridCoordinate spawn in levelData.Spawns)
     {
         gridComponent.Spawns.Add(new KeyValuePair <Field, List <FieldGridCoordinate> >(gridComponent.Grid[spawn.X, spawn.Z], null));
         GameObject spawnObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
         spawnObject.transform.position = gridComponent.Grid[spawn.X, spawn.Z].GetMiddlePoint();
         spawnObject.GetComponent <Renderer>().material.color = Color.blue;
     }
     foreach (FieldGridCoordinate environment in levelData.Environment)
     {
         gridComponent.Grid[environment.X, environment.Z].IsEnvironment = true;
         GameObject environmentObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
         environmentObject.transform.position = gridComponent.Grid[environment.X, environment.Z].GetMiddlePoint();
         environmentObject.GetComponent <Renderer>().material.color = Color.red;
     }
 }
Пример #7
0
    // Use this for initialization
    void Start()
    {
        GameObject
            bdc = GetComponent <BuildingDisposeComponent>();

        grid = GetComponent <GridComponent>();
    }
Пример #8
0
        private bool DrawGrid(GridComponent gridComp, Bounds drawArea, bool outlineOnly)
        {
            if (gridComp.sizeX == 0 || gridComp.sizeZ == 0 || gridComp.cellSize == 0f)
            {
                return(true);
            }

            Gizmos.color = this.boundsColor;
            Gizmos.DrawWireCube(gridComp.bounds.center, gridComp.bounds.size);

            IGrid grid = gridComp.grid;

            if (outlineOnly || grid == null)
            {
                return(true);
            }

            var start = grid.GetCell(drawArea.min);
            var end   = grid.GetCell(drawArea.max);

            if (start == null || end == null)
            {
                return(false);
            }

            var lineColor = this.gridLinesColor;

            if (!gridComp.automaticInitialization && !Application.isPlaying)
            {
                lineColor.a = lineColor.a * 0.5f;
            }

            if (this.drawMode == GridMode.Layout)
            {
                DrawLayout(grid, start, end, lineColor);
            }
            else if (this.drawMode == GridMode.HeightOverlay)
            {
                grid.cellMatrix.RenderHeightOverlay(this.gridLinesColor);
            }
            else
            {
                DrawAccessibility(grid, start, end, lineColor);
            }

            if (this.drawSubSections)
            {
                var y = grid.origin.y + 0.05f;

                Gizmos.color = this.subSectionsColor;
                foreach (var section in grid.gridSections)
                {
                    var subCenter = section.bounds.center;
                    subCenter.y = y;
                    Gizmos.DrawWireCube(subCenter, section.bounds.size);
                }
            }

            return(true);
        }
 public async Task InputSearchKeyup(KeyboardEventArgs e)
 {
     if (e.Key == "Enter")
     {
         await GridComponent.AddSearch(_searchValue);
     }
 }
Пример #10
0
 protected void Awake()
 {
     Buildings = new Dictionary <Building, BuildingGameObject>();
     if (grid == null)
     {
         grid = this;
     }
     BG = GetComponent <Renderer>();
 }
Пример #11
0
    private void Awake()
    {
        grid = GetComponent <GridComponent>();
        GameObject finded = GameObject.Find("ResourceStorage");

        if (finded != null)
        {
            resources = finded.GetComponent <ResourceStorage>();
        }
    }
Пример #12
0
        protected async Task TitleButtonClicked()
        {
            //switch direction for link:
            GridSortDirection newDir = Column.Direction == GridSortDirection.Ascending
                                           ? GridSortDirection.Descending
                                           : GridSortDirection.Ascending;

            await GridComponent.GetSortUrl(SortingSettings.ColumnQueryParameterName, Column.Name,
                                           SortingSettings.DirectionQueryParameterName, ((int)newDir).ToString(CultureInfo.InvariantCulture));
        }
Пример #13
0
	void Start () 
	{				
		hp = STARTING_HP;
		acceptableTower = GameObject.Instantiate(acceptableTowerPrefab) as GameObject;
		unAcceptableTower = GameObject.Instantiate(unAcceptableTowerPrefab) as GameObject;
		acceptableTower.transform.position = Vector3.zero;
		unAcceptableTower.transform.position = Vector3.zero;
		gc = gameWorldGrid.GetComponent<GridComponent>();
		cellSize = gc.grid.cellSize;
		instance = this;
	}
Пример #14
0
 private void DrawGizmos(GridComponent gridComponent, Translation translation)
 {
     //if (!gridComponent.drawGizmos) return;
     //for(int x = 0; x < gridComponent.gridArray.GetLength(0); x++)
     //{
     //    for (int y = 0; y < gridComponent.gridArray.GetLength(1); y++)
     //    {
     //        GameObject.CreatePrimitive(PrimitiveType.Quad);
     //    }
     //}
 }
Пример #15
0
 private void PopulateGridArray(GridComponent gridComponent, DynamicBuffer <GridBufferElement> gridBuffer)
 {
     for (int x = 0; x < gridComponent.width; x++)
     {
         for (int y = 0; y < gridComponent.height; y++)
         {
             gridBuffer[x * gridComponent.width + y] = 0;
         }
     }
     gridComponent.isArrayPopulated = true;
 }
Пример #16
0
 protected async Task HandleDrop()
 {
     _dropClass = "";
     if (Grid.Settings.SortSettings.SortValues.Any(r => r.ColumnName == GridComponent.Payload.ColumnName))
     {
         GridComponent.Payload = ColumnOrderValue.Null;
     }
     else
     {
         await GridComponent.AddExtSorting();
     }
 }
Пример #17
0
        public static Entity CreateGrid(this EntityWorld world, Vector2 gridSize, Color color)
        {
            var entity = world.CreateEntity();
            var grid = new GridComponent
            {
                GridSize = gridSize,
                GridColor = color
            };

            entity.AddComponent(grid);
            return entity;
        }
Пример #18
0
 // Start is called before the first frame update
 void Start()
 {
     GameState          = State.Idle;
     grid               = GameObject.Find("Grid").GetComponent <GridComponent>();
     inventory          = Inventory.instance;
     OnNewObjectPlaced += grid.RecalculatePathAfterPlacement;
     OnObjectDestroyed += grid.RecalculatePathAfterDestroy;
     levelData          = LevelUtility.GetLevelData(level);
     LevelUtility.LoadLevel(grid, levelData);
     grid.CalculatePath();
     SpawnEnemy();
     CheckUniqueBuildingIds();
 }
Пример #19
0
            public int IndexOfRow(GridComponent <SuspensionExpulsion> suspensionGrid)
            {
                IList <SuspensionExpulsion> listRow = suspensionGrid.Rows;

                foreach (SuspensionExpulsion rowItem in listRow)
                {
                    if (rowItem.Type.Trim().Equals(this.Type))
                    {
                        return(listRow.IndexOf(rowItem));
                    }
                }
                return(-1);
            }
Пример #20
0
    void instantiateGrid()
    {
        mainGridComponent = GridManager.instance.GetGridComponent(center);



        if (mainGridComponent != null)
        {
            mainGridComponent.Initialize(1000, (Result) =>
            {
                afterInitialization();
            });
        }
    }
Пример #21
0
    //private int Get2DArrayValue(GridComponent grid, int x, int y)
    //{
    //}

    public float3 GetNearestPointOnGrid(Translation gridTranslation, GridComponent gridComponent, float3 position)
    {
        position -= gridTranslation.Value;

        int xCount = Mathf.RoundToInt(position.x / gridComponent.cellSize);
        int yCount = Mathf.RoundToInt(position.y / gridComponent.cellSize);
        int zCount = Mathf.RoundToInt(position.z / gridComponent.cellSize);

        float3 result = new float3(
            (float)xCount * gridComponent.cellSize,
            (float)yCount * gridComponent.cellSize,
            (float)zCount * gridComponent.cellSize);

        result += gridTranslation.Value;

        return(result);
    }
Пример #22
0
        internal static Bounds SnapToGrid(GridComponent grid, Bounds targetBounds, bool expandAlongPerimeter)
        {
            var cellSize = grid.cellSize;
            var startX   = grid.origin.x - (grid.sizeX * cellSize * 0.5f);
            var startZ   = grid.origin.z - (grid.sizeZ * cellSize * 0.5f);
            var endX     = startX + (grid.sizeX * cellSize);
            var endZ     = startZ + (grid.sizeZ * cellSize);

            targetBounds = targetBounds.Intersection(grid.bounds);

            var boundsMinX = targetBounds.min.x;
            var boundsMinZ = targetBounds.min.z;
            var boundsMaxX = targetBounds.max.x;
            var boundsMaxZ = targetBounds.max.z;

            if (expandAlongPerimeter)
            {
                var dxMin = targetBounds.min.x - startX;
                var dzMin = targetBounds.min.z - startZ;
                var dxMax = endX - targetBounds.max.x;
                var dzMax = endZ - targetBounds.max.z;

                var dMin = Mathf.Min(dxMin, dzMin, dxMax, dzMax);
                if (dMin == dxMin || dMin == dxMax)
                {
                    boundsMinZ = startZ;
                    boundsMaxZ = endZ;
                }
                else if (dMin == dzMin || dMin == dzMax)
                {
                    boundsMinX = startX;
                    boundsMaxX = endX;
                }
            }

            var minX = AdjustMin(startX, boundsMinX, cellSize) + 0.05f;
            var minZ = AdjustMin(startZ, boundsMinZ, cellSize) + 0.05f;
            var maxX = AdjustMax(endX, boundsMaxX, cellSize) - 0.05f;
            var maxZ = AdjustMax(endZ, boundsMaxZ, cellSize) - 0.05f;

            targetBounds.SetMinMax(new Vector3(minX, targetBounds.min.y, minZ), new Vector3(maxX, targetBounds.max.y, maxZ));
            return(targetBounds);
        }
Пример #23
0
        protected override void LoadContent()
        {
            _grid       = new GridComponent(GraphicsDevice, 10);
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            _icon = Content.Load <Texture2D>("icon");
            // First, load the texture as a Texture2D (can also be done using the XNA/FNA content pipeline)
            _xnaTexture = Texture2D.FromStream(GraphicsDevice, GenerateImage(300, 150));

            // Then, bind it to an ImGui-friendly pointer, that we can use during regular ImGui.** calls (see below)
            _imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);

            _cube = Content.Load <Model>("models/Cube_obj");
            //_cube = Content.Load<Model>("models/xbot");
            _cubeDiffuse    = Content.Load <Texture2D>("textures/Cube_diffuse");
            _specularEffect = Content.Load <Effect>("effects/Specular");

            //SetupAmbientEffect();
        }
Пример #24
0
        //*************************************************************************************
        //
        // Initializer
        //
        //*************************************************************************************

        public static void initialize()
        {
            // set the initial dimensions
            _dimensions.x = 100;
            _dimensions.y = 100;
            _dimensions.z = 100;

            // initialize the grid space
            _gridSpace = new List <GridComponent>();

            // resize the grid space
            int size = _dimensions.x * _dimensions.y * _dimensions.z;

            // add the default <empty> component to the grid space
            for (int i = 0; i < size; ++i)
            {
                GridComponent empty = new GridComponent();
                _gridSpace.Add(empty);
            }
        }
Пример #25
0
    public override void Initialize(Transform[] objects)
    {
        // list because I don't know size here////
        List <Filter> tmpFilters = new List <Filter>();
        int           index      = 0;

        for (int i = 0; i < objects.Length; i++)
        {
            // check performance
            MovementComponent mc = objects[i].GetComponent <MovementComponent>();
            InputComponent    ic = objects[i].GetComponent <InputComponent>();

            if (mc && ic)
            {
                tmpFilters.Add(new Filter(index, objects[i].gameObject, mc, ic));
            }
        }

        filters = tmpFilters.ToArray();

        gridComp = GetComponentInChildren <GridComponent>();
    }
Пример #26
0
        public LoliriftGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            this.IsMouseVisible = true;
            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;

            data = new DataStore();

            network = new NetworkComponent(this, data);
            Components.Add(network);

            input = new InputComponent(this);
            Components.Add(input);

            camera = new CameraComponent(this, input);
            Components.Add(camera);

            grid = new GridComponent(this, data, camera);
            Components.Add(grid);
        }
Пример #27
0
        private void Start()
        {
            var go = this.gameObject;

            //Setup the configuration. You only need to set the values you want different from the defaults that you can see on the GridConfig class.
            var gridCfg = new GridConfig
            {
                cellSize = 1f,
                sizeX    = 32,
                sizeZ    = 32,
                origin   = go.transform.position,
                obstacleAndGroundDetection = ColliderDetectionMode.Custom,
                obstacleAndGroundDetector  = OddBlockDetector.instance
            };

            //Create the grid instance
            var grid = GridComponent.Create(go, gridCfg);

            //Initialize the grid
            grid.Initialize(10, g =>
            {
                Debug.Log("Initialization Done");
            });
        }
Пример #28
0
    public void CreateComponent(GridComponent gridComponent)
    {
        _sprites = new List <Sprite>(Sprites);
        var    child          = new GameObject();
        var    spriteRenderer = child.AddComponent <SpriteRenderer> ();
        Sprite sprite         = null;

        if (gridComponent.GetType() == typeof(GridComponent))
        {
            sprite = _sprites.FirstOrDefault(x => x.name == "basicComponent");
        }
        else if (gridComponent.GetType() == typeof(Chip))
        {
            sprite = _sprites.FirstOrDefault(x => x.name == "chipSmall");
        }

        spriteRenderer.sprite = sprite;
        var location = GridUtility.GetCellPosition(gridComponent);

        spriteRenderer.color          = gridComponent.Color;
        spriteRenderer.sortingOrder   = 15;
        child.transform.parent        = gameObject.transform;
        child.transform.localPosition = location;
    }
Пример #29
0
 // Calculating world position from grid indexes. Because we're in 3D, the array's Y (or GridComponent.gridArray's second dimension) corresponds to the World's Z axis.
 private float3 GetWorldPosition(GridComponent grid, int arrayX, int arrayY)
 {
     return(new float3(arrayX, 0f, arrayY) * grid.cellSize);
 }
Пример #30
0
    List <GridComponent> ParseComponents(List <string> inputComponentStringList)
    {
        /*
         * 1001	thread	5	3	S	L	{"color":1,"initial_direction":"East","capacity":1,"delay":0,"picked":0,"delivered":0,"missed":0}
         * 1002	thread	13	3	S	L	{"color":3,"initial_direction":"West","capacity":1,"delay":0,"picked":0,"delivered":0,"missed":0}
         * 2001	pickup	9	9	S	L	{"type":"Conditional","color":0,"picked":0,"passed":0}
         * 3001	delivery	9	12	S	L	{"color":0,"consumer":-1,"strict":0,"passed":0,"delivered":0,"missed":0}
         * 4001	intersection	9	14	S	L	{"directions":["North","West","North","East","North","North"],"passed":0}
         */
        List <GridComponent> returnComponents = new List <GridComponent>();

        foreach (string row in inputComponentStringList)
        {
            GridComponent gc = new GridComponent();
            string[]      s  = row.Split('\t');
            gc.id       = int.Parse(s[0]);
            gc.type     = s[1];
            gc.posX     = int.Parse(s[2]);
            gc.posY     = int.Parse(s[3]);
            gc.placedBy = s[4];
            gc.editable = s[5];

            /*CONFIGURATION DECODING NOT WORKING*/
            /*TODO: TRANSLATE TO JSONObject*/
            try
            {
                gc.configuration = JsonUtility.FromJson <Configuration>(s[6]);
                JSONObject ob = new JSONObject(s[6]);
                if (ob.GetField("directions_types") != null)
                {
                    List <string> directions_types_west  = ob.GetField("directions_types").list[0].list.ConvertAll(x => x.str);
                    List <string> directions_types_north = ob.GetField("directions_types").list[3].list.ConvertAll(x => x.str);
                    List <string> directions_types_east  = ob.GetField("directions_types").list[2].list.ConvertAll(x => x.str);
                    List <string> directions_types_south = ob.GetField("directions_types").list[1].list.ConvertAll(x => x.str);

                    gc.configuration.directions_types.Add(directions_types_west);
                    gc.configuration.directions_types.Add(directions_types_south);
                    gc.configuration.directions_types.Add(directions_types_east);
                    gc.configuration.directions_types.Add(directions_types_north);

                    /*
                     *                  Debug.Log( directions_types_west.Count + " IS WEST COUNT " );
                     *                  Debug.Log( directions_types_south.Count + " IS SOUTH COUNT " );
                     *                  Debug.Log( directions_types_east.Count + " IS EAST COUNT " );
                     *                  Debug.Log( directions_types_north.Count + " IS NORTH COUNT " );
                     */
                }

                if (ob.GetField("directions_colors") != null)
                {
                    if (ob.GetField("directions_colors").list.Count > 0)
                    {
                        List <int> directions_colors_west  = ob.GetField("directions_colors").list[0].list.ConvertAll(x => (int)x.i);
                        List <int> directions_colors_north = ob.GetField("directions_colors").list[3].list.ConvertAll(x => (int)x.i);
                        List <int> directions_colors_east  = ob.GetField("directions_colors").list[2].list.ConvertAll(x => (int)x.i);
                        List <int> directions_colors_south = ob.GetField("directions_colors").list[1].list.ConvertAll(x => (int)x.i);
                        gc.configuration.directions_colors.Add(directions_colors_west);
                        gc.configuration.directions_colors.Add(directions_colors_south);
                        gc.configuration.directions_colors.Add(directions_colors_east);
                        gc.configuration.directions_colors.Add(directions_colors_north);
                    }
                }
                if (ob.GetField("accepted_colors") != null)
                {
                    if (ob.GetField("accepted_colors").list.Count > 0)
                    {
                        List <int> accepted_colors = ob.GetField("accepted_colors").list.ConvertAll(x => (int)x.i);
                        gc.configuration.accepted_colors = accepted_colors.ToArray();
                    }
                }
            }
            catch
            {
                Debug.LogError("Error with json utility: " + s[6]);
                JSONObject j = new JSONObject(s[6]);
                gc.configuration = new Configuration();
            }

            returnComponents.Add(gc);
        }
        return(returnComponents);
    }
Пример #31
0
 public async Task RemoveFilter()
 {
     _isVisible = !_isVisible;
     await GridComponent.RemoveFilter(Column);
 }
Пример #32
0
 public async Task AddFilter(FilterCollection filters)
 {
     _isVisible = !_isVisible;
     await GridComponent.AddFilter(Column, filters);
 }