Exemplo n.º 1
0
    private void PlaceHeadNear(Vector2 pos)
    {
        Vector2 newHeadPos = Vector2.zero;

        List <Vector2> emptySlots = _chipPanel.GetEmptySlots();

        if (emptySlots.Count > 0)
        {
            newHeadPos = emptySlots.OrderBy(s => Vector2.Distance(s, pos)).First();
        }
        else
        {
            List <Vector2> avaliablePositions = new List <Vector2>();
            for (int i = 0; i < EditingModule.Size; i++)
            {
                for (int j = 0; j < EditingModule.Size; j++)
                {
                    if (i != pos.x && j != pos.y)
                    {
                        avaliablePositions.Add(new Vector2(i, j));
                    }
                }
            }
            newHeadPos = avaliablePositions.OrderBy(s => Vector2.Distance(s, pos)).First();
            Player.Instance.AddElements(DefaultResources.GetElementByEnum((LogicElement.LogicElementType)((SimpleModule)EditingModule).Elements[(int)newHeadPos.x, (int)newHeadPos.y]), 1);
        }
        ((SimpleModule)EditingModule).SetElement(newHeadPos, LogicElement.LogicElementType.MyHead);
    }
Exemplo n.º 2
0
    public void ElementClicked(LogicModules editingModule, Vector2 position, LogicElement currentElement)
    {
        if (!_elementCounter.SelectedElement || Player.Instance.GetElementCount(_elementCounter.SelectedElement) == 0)
        {
            return;
        }

        if (currentElement.ElementType != LogicElement.LogicElementType.MyHead)
        {
            if (_elementCounter.SelectedElement.ElementType == LogicElement.LogicElementType.MyHead)
            {
                //click on any with head
                RemovePreviousHead();
            }
        }
        else
        {
            if (_elementCounter.SelectedElement.ElementType == LogicElement.LogicElementType.MyHead)
            {
                //click with head on head
                return;
            }
        }

        LogicElement newElement;

        if (_elementCounter.SelectedElement.ElementType == currentElement.ElementType)
        {
            newElement = DefaultResources.GetElementByEnum(LogicElement.LogicElementType.Any);
            Player.Instance.AddElements(currentElement, 1);
        }
        else
        {
            if (Player.Instance.GetElementCount(_elementCounter.SelectedElement) > 0)
            {
                Player.Instance.AddElements(_elementCounter.SelectedElement, -1);
                Player.Instance.AddElements(currentElement, 1);
                newElement = _elementCounter.SelectedElement;
            }
            else
            {
                newElement = currentElement;
                Debug.LogWarning("Not enough elements!");
            }
        }


        ((SimpleModule)editingModule).SetElement(position, newElement.ElementType);

        if (currentElement.ElementType == LogicElement.LogicElementType.MyHead)
        {
            PlaceHeadNear(position);
        }
    }
Exemplo n.º 3
0
    public void Init(SimpleModule chip)
    {
        foreach (Transform t in transform)
        {
            t.GetComponent <ModuleSlot>().enabled = false;
            Destroy(t.gameObject);
        }

        _grid.constraintCount = chip.Size;
        _grid.cellSize        = Mathf.RoundToInt(_size / chip.Size) * Vector2.one;
        for (int i = 0; i < chip.Size; i++)
        {
            for (int j = 0; j < chip.Size; j++)
            {
                GameObject slotGo = Instantiate(ElementSlot, Vector3.zero, Quaternion.identity, transform);
                slotGo.transform.localScale    = Vector3.one;
                slotGo.transform.localPosition = Vector3.zero;
                slotGo.GetComponent <ModuleSlot>().Init(DefaultResources.GetElementByEnum((LogicElement.LogicElementType)chip.Elements[i, j]), new Vector2(i, j));
            }
        }
    }
Exemplo n.º 4
0
 public void UpdateElement(LogicElement.LogicElementType elType)
 {
     _currentElement = DefaultResources.GetElementByEnum(elType);
 }
    public override void OnInspectorGUI()
    {
        int w = 0;
        int h = 0;

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Size: ", GUILayout.Width(45));
        w = Mathf.Clamp(EditorGUILayout.IntField(_template.Cells.Count, GUILayout.Width(45)), 1, 25);
        EditorGUILayout.LabelField("X", GUILayout.Width(15));
        h = Mathf.Clamp(EditorGUILayout.IntField(_template.Cells[0].raw.Count, GUILayout.Width(45)), 1, 25);
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (w != _template.Cells.Count || h != _template.Cells[0].raw.Count)
        {
            _template.Setize(w, h);
            EditorUtility.SetDirty(_template);
        }

        EditorGUILayout.LabelField(_template.SnakesCount + " players");

        for (int i = 0; i < _template.Cells.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            for (int j = 0; j < _template.Cells[0].raw.Count; j++)
            {
                Texture2D texture = _template.Cells[i].raw[j].image.texture;
                if (!topLayer || _template.Cells[i].raw[j].element == LogicElement.LogicElementType.None)
                {
                    texture = _template.CellsBack[i].raw[j].image.texture;
                }

                if (GUILayout.Button(texture, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(16)))
                {
                    _template.SetCell(_brush, i, j, topLayer);
                    EditorUtility.SetDirty(_template);
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUI.skin.horizontalScrollbar, GUIStyle.none, GUILayout.Height(45));
        EditorGUILayout.BeginHorizontal();

        foreach (ElementPair ep in _template.Tiles)
        {
            if (DefaultResources.GetElementByEnum(ep.element) != null)
            {
                if (!topLayer)
                {
                    if (ep.element == LogicElement.LogicElementType.None)
                    {
                        if (GUILayout.Button(ep.image.texture, GUILayout.Width(30), GUILayout.Height(30)))
                        {
                            _brush = ep;
                        }
                    }
                }
                else
                {
                    if (ep.element != LogicElement.LogicElementType.None || ep == _template.Tiles.FirstOrDefault(e => e.element == LogicElement.LogicElementType.None))
                    {
                        if (GUILayout.Button(ep.image.texture, GUILayout.Width(30), GUILayout.Height(30)))
                        {
                            _brush = ep;
                        }
                    }
                }
            }
        }



        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndScrollView();

        if (_brush != null)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(_brush.image.texture, GUILayout.Width(50), GUILayout.Height(50));
            string s = "top";
            if (!topLayer)
            {
                s = "bottom";
            }

            if (GUILayout.Button(s, GUILayout.Width(100), GUILayout.Height(50)))
            {
                topLayer = !topLayer;

                if (_brush != null && _brush.element != LogicElement.LogicElementType.None && !topLayer)
                {
                    _brush = null;
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        showTiles = EditorGUILayout.Foldout(showTiles, "Tiles");
        if (showTiles)
        {
            tilesList.DoLayoutList();
        }
    }