Ejemplo n.º 1
0
    private void InitializeMap() {
        if (_constructions == null) {
            Debug.Log("Null Map");
            _constructions = new Dictionary<Vector3, BaseConstructionData>();
            _layers = new List<GameObject>();
        }
        else {
            Debug.Log("Clear Map");
            _constructions.Clear();
            foreach (GameObject go in _layers) {
                Destroy(go);
            }
            _layers.Clear();
        }
        _gridReference = MainCamera.GetComponent<GridOverlay>();
        _gridReference.gridSizeX = gridSizeX;
        _gridReference.largeStep = gridStepY;
        _levelCount = gridSizeY / gridStepY;
        _gridReference.gridSizeZ = gridSizeZ;
        gridSizeZ = _gridReference.gridSizeZ;
        for (int i = 0; i < _levelCount; i++) {
            GameObject layer = Instantiate(LayerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
            layer.GetComponent<TileMapMouse>().selectionCube = CubeHighlight.transform;
            layer.transform.parent = transform;
            layer.transform.position = new Vector3(transform.position.x, transform.position.y + (i * gridStepY + gridStepY), transform.position.z + gridSizeZ);

            _layers.Add(layer);
            if (i != currentLayer) {
                layer.SetActive(false);
            }
            MainCamera.GetComponent<GridOverlay>().offsetY = gridStepY * currentLayer + transform.position.y;
        }
    }
Ejemplo n.º 2
0
    public GridOverlay PresentGridOverlay(string category, int id, Color color, Color selectedColor, PathNode[] destinations)
    {
        if (overlays == null)
        {
            overlays = new Dictionary <string, Dictionary <int, Overlay> >();
        }
        if (!overlays.ContainsKey(category))
        {
            overlays[category] = new Dictionary <int, Overlay>();
        }
        else if (overlays[category].ContainsKey(id))
        {
            Overlay existing = overlays[category][id];
            if (existing is GridOverlay)
            {
                return(existing as GridOverlay);
            }
            Debug.LogError("Expected grid overlay, but got " + existing + " for cat " + category + " and id " + id);
            return(null);
        }
        GameObject go = new GameObject();

        go.transform.parent = this.transform;
        GridOverlay ov = go.AddComponent <GridOverlay>();

        ov.destinations        = destinations;
        ov.color               = color;
        ov.selectedColor       = selectedColor;
        ov.category            = category;
        ov.identifier          = id;
        overlays[category][id] = ov;
        return(ov);
    }
Ejemplo n.º 3
0
        public void DrawTree(GridOverlay gridOverlay)
        {
            if (TotalChildren > 0)
            {
                //Debug.Log(" Center : " + Center + " HalfWidth :" + HalfWidth);
                ///Debug.Log(" _CurrentDepth : " + _CurrentDepth + " HalfWidth :" + HalfWidth);
                //Debug.Log(" _TotalChildren : " + _TotalChildren + "_CurrentDepth" + _CurrentDepth);
                //Debug.Log(" sQuarterDiagonal : " + sQuarterDiagonal);
                for (int i = 0; i < 8; ++i)
                {
                    if (_Nodes.ContainsKey(i))
                    {
                        _Nodes[i].DrawTree(gridOverlay);
                        gridOverlay.DrawLinePQ(Center, _Nodes[i].Center);
                    }
                }

                //Debug.Log(" _Children : " + _Children.Count + " Depth : " + _CurrentDepth);
                foreach (GameObject child in _Children)
                {
                    //Debug.Log("center : " + Center + "child.transform.position : " + child.transform.position);

                    gridOverlay.DrawLinePQ(Center, child.transform.position);
                }
            }
        }
 private void Awake()
 {
     if (instanse == null)
     {
         instanse = this;
     }
 }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        transform.position = new Vector3(0, 0, -10f);
        overlay            = GetComponent <GridOverlay>();

        distance = new Vector3(0, 0, -8f);
        //distance = transform.localPosition.z;
    }
Ejemplo n.º 6
0
    private void SetOverlayTransform(Vector3 Size, Vector3 Center, float ForcedY, GridOverlay gridOverlay)
    {
        gridOverlay.gridSizeX = Size.x;
        gridOverlay.gridSizeY = 0f;
        gridOverlay.gridSizeZ = Size.z;

        gridOverlay.startX = Center.x;
        gridOverlay.startY = ForcedY;
        gridOverlay.startZ = Center.z;
    }
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 8
0
    public void ShowSelectedNodesInGrid(NodeGridPosition GridPos, GridOverlay gridOverlay)
    {
        if (Grid.Instance.CheckIfOutOfBounds(GridPos) || !BuildMode)
        {
            return;
        }

        SelectedOverlay.showMain = true;
        float radius = Grid.Instance.nodeRadius;


        Vector3 center = Grid.GetWorldPointFromNodeGridPosition(GridPos) - Vector3.one * radius;

        SetOverlayTransform(Vector3.one * radius * 2, center, 0f, gridOverlay);
    }
Ejemplo n.º 9
0
 // toggles the grid on and of, doesn't effect the snapping
 public void GridToggle(Toggle t)
 {
     SoundManager.ButtonClicked();
     if (!UIObjectPreferences.menuOpen)
     {
         if (t.isOn)
         {
             GridOverlay.Active(true);
         }
         else
         {
             GridOverlay.Active(false);
         }
     }
 }
Ejemplo n.º 10
0
    void Start()
    {
        DontDestroyOnLoad(this);
        grid               = FindObjectOfType <Grid> ();
        gridOverlay        = FindObjectOfType <GridOverlay> ();
        chatText           = FindObjectsOfType <ChatText> ().First(x => x.name == "ChatText");
        verticalConstraint = FindObjectOfType <VerticalConstraint> ();

        Client = FindObjectOfType <Client> ();

        Client.ThrowGameplayEvent += ReceiveFromClient;

        //temporary, eventually hotbar slots will be defined dynamically
        hotbar[0] = "Sculpture";
    }
Ejemplo n.º 11
0
    // Update is called once per frame
    void Start()
    {
        _overlay   = Hierarchy.GetComponentWithTag <GridOverlay>("MainCamera");
        gridWidth  = _overlay.gridSizeX;
        gridHeight = _overlay.gridSizeZ;
        tileWidth  = webcamWidth / gridWidth;
        tileHeight = webcamHeight / gridHeight;

        for (int i = 0; i < gridWidth; i++)
        {
            for (int j = 0; j < gridHeight; j++)
            {
                tiles.Add(new Vector2(i, j), new GridTile(i, j));
            }
        }
    }
Ejemplo n.º 12
0
        protected override void LoadContent()
        {
            RenderHelper.Init(GraphicsDevice);
            _camera    = new Camera();
            _grid      = new GridOverlay();
            _spotMap   = new SpatialMap <WireSpot>(80);
            _grid.Size = new Vector2(_spotMap.CellSize);

            _wireRenderer = new WireRenderer();
            WireGenerator.DefaultSpotDensity = 10;
            //_wire = WireGenerator.MakeCircle(new Vector2(350, 250), 200);
            _wire = WireGenerator.MakeRandomPath(new Vector2(50, 200), 0, 500, 50, 0, .5f);

            _player = new Player(_wire);

            base.LoadContent();
        }
Ejemplo n.º 13
0
 // Use this for initialization
 void Start()
 {
     //Initialize all the variables
     if (!(world == null || menu == null || userui == null || grid == null))
     {
         return;
     }
     if (GetComponent <MenuScript>() == null)
     {
         menu = gameObject.AddComponent <MenuScript>();
     }
     if (GetComponent <UserUI>() == null)
     {
         userui = gameObject.AddComponent <UserUI>();
     }
     if (GetComponent <ResourceUI>() == null)
     {
         resourceui = gameObject.AddComponent <ResourceUI>();
     }
     if (GetComponent <Builder>() == null)
     {
         builder = gameObject.AddComponent <Builder>();
     }
     if (GetComponent <ClickScript>() == null)
     {
         click = gameObject.AddComponent <ClickScript>();
     }
     if (grid == null)
     {
         grid = FindObjectOfType <CameraScript>() != null?FindObjectOfType <CameraScript>().overlay : null;
     }
     if (world == null)
     {
         world = FindObjectOfType <World>();
     }
     if (camera == null)
     {
         camera = Camera.main;
     }
             #if UNITY_ANDROID
     if (camerascript == null)
     {
         camerascript = FindObjectOfType <CameraScript>();
     }
             #endif
 }
Ejemplo n.º 14
0
 public void DrawPartitions(GridOverlay gridOverlay)
 {
     if (TotalChildren >= SMaxChildren)
     {
         //Debug.Log(" Center : " + Center + " HalfWidth :" + HalfWidth);
         ///Debug.Log(" _CurrentDepth : " + _CurrentDepth + " HalfWidth :" + HalfWidth);
         //Debug.Log(" _TotalChildren : " + _TotalChildren + "_CurrentDepth" + _CurrentDepth);
         //Debug.Log(" sQuarterDiagonal : " + sQuarterDiagonal);
         gridOverlay.DrawPartitioners(Center, HalfWidth);
         for (int i = 0; i < 8; ++i)
         {
             if (_Nodes.ContainsKey(i))
             {
                 _Nodes[i].DrawPartitions(gridOverlay);
             }
         }
     }
 }
Ejemplo n.º 15
0
    /*public void ShowSelectedNodesInGrid(List<NodeGridPosition> nodes, GridOverlay gridOverlay)
     * {
     *  if (nodes == null || nodes.Count <= 0 || !BuildMode)
     *      return;
     *  else if (nodes.Count == 1)
     *      ShowSelectedNodesInGrid(nodes[0], gridOverlay);
     *
     *
     *  gridOverlay.showMain = true;
     *
     *  float Lenght = nodes.Count * grid.nodeRadius * 2f;
     *  float width = grid.nodeRadius * 2f;
     *
     *  Vector3 size;
     *  Vector3 center;
     *
     *  Node n1 = nodes[0];
     *  Node n2 = nodes[nodes.Count - 1];
     *
     *  float differenceX = Mathf.Abs(n2.GridPos.x - n1.GridPos.x);
     *  float differenceY = Mathf.Abs(n2.GridPos.y - n1.GridPos.y);
     *
     *  if (differenceX > differenceY)
     *  {
     *      size = new Vector3(Lenght, 0f, width);
     *  }
     *  else
     *  {
     *      size = new Vector3(width, 0f, Lenght);
     *  }
     *
     *  center = new Vector3((n1.WorldPosition.x + n2.WorldPosition.x - size.x) / 2f, 0f, (n1.WorldPosition.z + n2.WorldPosition.z - size.z) / 2f);
     *
     *
     *
     *  gridOverlay.gridSizeX = size.x;
     *  gridOverlay.gridSizeY = 0;
     *  gridOverlay.gridSizeZ = size.z;
     *
     *  gridOverlay.startX = center.x;
     *  gridOverlay.startY = 0f;
     *  gridOverlay.startZ = center.z;
     * }
     *
     * public void ShowSelectedNodesInGrid(List<NodeGridPosition> nodes)
     * {
     *  if (nodes == null || nodes.Count <= 0 || !BuildMode)
     *      return;
     *
     *  else if (nodes.Count == 1)
     *  {
     *      ShowSelectedNodesInGrid(nodes[0]);
     *      return;
     *  }
     *
     *
     *  SelectedOverlay.showMain = true;
     *
     *  float Lenght = nodes.Count * grid.nodeRadius * 2f;
     *  float width = grid.nodeRadius * 2f;
     *
     *  Vector3 size;
     *  Vector3 center;
     *
     *  Node n1 = nodes[0];
     *  Node n2 = nodes[nodes.Count - 1];
     *
     *  float differenceX = Mathf.Abs(n2.GridPos.x - n1.GridPos.x);
     *  float differenceY = Mathf.Abs(n2.GridPos.y - n1.GridPos.y);
     *
     *  if (differenceX > differenceY)
     *  {
     *      size = new Vector3(Lenght, 0f, width);
     *  }
     *  else
     *  {
     *      size = new Vector3(width, 0f, Lenght);
     *  }
     *
     *  center = new Vector3((n1.WorldPosition.x + n2.WorldPosition.x - size.x) / 2f, 0f, (n1.WorldPosition.z + n2.WorldPosition.z - size.z) / 2f);
     *
     *  SetSelectedOverlayTransform(size, center, 0f);
     * }
     */

    public void ShowSelectedNodesInGrid(List <NodeGridPosition> GridPos, GridOverlay gridOverlay)
    {
        if (GridPos == null || GridPos.Count <= 0 || !BuildMode)
        {
            return;
        }

        else if (GridPos.Count == 1)
        {
            ShowSelectedNodesInGrid(GridPos[0]);
            return;
        }


        gridOverlay.showMain = true;

        float Lenght = GridPos.Count * Grid.Instance.nodeRadius * 2f;
        float width  = Grid.Instance.nodeRadius * 2f;

        Vector3 size;
        Vector3 center;

        NodeGridPosition n1GridPos = GridPos[0];
        NodeGridPosition n2GridPos = GridPos[GridPos.Count - 1];

        float differenceX = Mathf.Abs(n2GridPos.x - n1GridPos.x);
        float differenceY = Mathf.Abs(n2GridPos.y - n1GridPos.y);

        if (differenceX > differenceY)
        {
            size = new Vector3(Lenght, 0f, width);
        }
        else
        {
            size = new Vector3(width, 0f, Lenght);
        }

        Vector3 n1WorldPos = Grid.GetWorldPointFromNodeGridPosition(n1GridPos);
        Vector3 n2WorldPos = Grid.GetWorldPointFromNodeGridPosition(n2GridPos);

        center = new Vector3((n1WorldPos.x + n2WorldPos.x - size.x) / 2f, 0f, (n1WorldPos.z + n2WorldPos.z - size.z) / 2f);

        SetOverlayTransform(size, center, 0f, gridOverlay);
    }
Ejemplo n.º 16
0
    // Use this for initialization
    void Start()
    {
        ParticleMove.mainInst = this;
        SetStart();
        _Particles                 = new List <GameObject>();
        _Vertices                  = new List <GameObject>();
        _GridOverlay               = GLCamera.GetComponent <GridOverlay>();
        _KeyboardCameraControl     = GLCamera.GetComponent <KeyboardCameraControl>();
        _GridOverlay._MainInstance = this;
        CubeCenter                 = _GridOverlay.CubeCenter;
        CubeWidth                  = _GridOverlay.CubeDimension;
        //RootOcTree = new Octree(CubeCenter, CubeWidth, _FParticleRadius);
        RootOcTree = null;
        float _FParticleRadius = ParticlePrefab.gameObject.transform.GetChild(0).GetComponent <SpriteRenderer>().bounds.size.x / 2;

        _VParticleRadius            = new Vector3(_FParticleRadius, _FParticleRadius, _FParticleRadius);
        TextBoxCurrentMaxDepth.text = "Depth : " + Octree.SMaxDepthToStopAt;
        TextBoxCurrentSplitAt.text  = "Split after : " + Octree.SMaxChildren;
        InputMaxDepth.text          = Octree.SMaxDepthToStopAt.ToString();
        InputMaxSplitAt.text        = Octree.SMaxChildren.ToString();

        ParticlePrefab.transform.GetChild(2).gameObject.SetActive(_ShowTextMesh);
        ParticlePrefab.transform.GetChild(3).gameObject.SetActive(_ShowTextMesh);
    }
Ejemplo n.º 17
0
 private void showOverlay(GridOverlay toShow)
 {
     menuGridOverlay.Visibility     = toShow == GridOverlay.menu ? Visibility.Visible : Visibility.Hidden;
     settingsGridOverlay.Visibility = toShow == GridOverlay.settings ? Visibility.Visible : Visibility.Hidden;
 }
Ejemplo n.º 18
0
	// Use this for initialization
	void Start () {
		overlay = this.GetComponent<GridOverlay>();
		REF = this;
	}
Ejemplo n.º 19
0
	// Use this for initialization
	void Start () {
		overlay = this.GetComponent<GridOverlay>();
		REF = this;
		terrain = GameObject.FindGameObjectWithTag("Terrain").GetComponent<Terrain>();
	}
Ejemplo n.º 20
0
    public void toggleState()
    {
        GridOverlay gridOverlay = gameObject.GetComponent <GridOverlay>();

        gridOverlay.enabled = !gridOverlay.enabled; //this changes the state from on to off and vice-versa
    }