示例#1
0
 public void FinishEdit()
 {
     if (current)
     {
         parts.Remove(current);
         current = null;
     }
     ownBuilding.setNewRobotStats(robotStat);
     Manager.instance.finishRobotMaking();
 }
示例#2
0
 void newPartToMouse(int index)
 {
     if (current)
     {
         Destroy(current.gameObject);
     }
     current        = Instantiate <RoboterPart>(premade[index], (Vector2)getCurrentMouseOver(), Quaternion.identity, transform);
     current.myShop = this;
     parts.Add(current);
 }
示例#3
0
    State[] getAllPointsOfPart(RoboterPart part)
    {
        var b = new State[width * height];

        System.Array.Clear(b, 0, b.Length);
        foreach (var point in part.connectionPoints)
        {
            var pos = point.pos + part.position;
            int i   = Mathf.FloorToInt(pos.x);
            int j   = Mathf.FloorToInt(pos.y);
            if (i >= 0 && i < width && j >= 0 && j < height)
            {
                b[i + j * width] = point.state;
            }
        }
        return(b);
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        updatePlaced();

        robotStat            = culcStat();
        robotStat.nameOfPart = partName.text;

        //12 max name length
        submit.interactable = parts.Count > 2 && partName.text != "" && partName.text.Length <= 12;



        if (current)
        {
            var item     = current;
            var woultBeX = new bool[width * height];
            //System.Array.Clear(woultBeX, 0, woultBeX.Length);
            if (!item.placed)
            {
                var b = getAllPointsOfPart(item);
                item.ok    = false;
                item.wrong = false;



                for (int i = 0; i < b.Length; i++)
                {
                    if (!overLayIsOk(placed[i], b[i]))
                    {
                        item.wrong = true;
                        break;
                    }
                    else
                    if (overLayIsFine(placed[i], b[i]))
                    {
                        item.ok     = true;
                        woultBeX[i] = true;
                    }
                }

                foreach (var child in item.GetComponentsInChildren <Renderer>())
                {
                    child.material.color = item.wrong ? Color.red : (item.ok ? Color.green : Color.white);
                }
            }

            current.transform.position = (Vector2)getCurrentMouseOver();
            int old = currentIndex;
            if (Input.GetAxis("Mouse ScrollWheel") > 0)
            {
                currentIndex++;
            }
            if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                currentIndex--;
            }


            if (currentIndex > premade.Length - 1)
            {
                currentIndex = 0;
            }
            if (currentIndex < 0)
            {
                currentIndex = premade.Length - 1;
            }
            if (old != currentIndex)
            {
                newPartToMouse(currentIndex);
            }

            if (current.ok && !current.wrong)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    for (int i = 0; i < woultBeX.Length; i++)
                    {
                        if (woultBeX[i])
                        {
                            placed[i] = State.X;
                        }
                    }
                    current.transform.position = (Vector2)Vector2Int.RoundToInt(getCurrentMouseOver());

                    foreach (var child in current.GetComponentsInChildren <Renderer>())
                    {
                        child.material.color = Color.white;
                    }

                    current.placed = true;

                    current = null;
                    newPartToMouse(currentIndex);
                }
            }
        }
    }