Beispiel #1
0
    public void PlaceExistedPart() //需要加上对in和out的修改
    {
        curLineList.Remove(new Vector2(originX, originZ));
        curLineList.Add(new Vector2(curX, curZ));
        ProdLinePart changing = curLinePartList.Find(item => item.itemPos == new Vector2(originX, originZ));

        changing.itemPos = new Vector2(curX, curZ);
        chosenPart       = null;
    }
Beispiel #2
0
    int GetOutItemId(int id, int type, Vector2 curPos)
    {
        List <Vector2> dir = new List <Vector2> {
            new Vector2(1, 0), new Vector2(-1, 0), new Vector2(0, 1), new Vector2(0, -1)
        };
        List <int> connectedObj  = new List <int>();
        int        hasConnection = 0;

        foreach (Vector2 d in dir) //对相邻的四个方向找一遍,每有一个相邻的且outId没有的,就将type加到obj列表里,并且用hasConnection计数有几个连接
        {
            //print("looking for obj on direction : " + d);
            if (curLineList.Contains(curPos + d))
            {
                //print("is looking of position " + curPos + "+" + d);
                ProdLinePart thisItem = curLinePartList.Find(item => item.itemPos == curPos + d);
                print("find item here. the item is " + thisItem.itemId + ", and it's in id is " + thisItem.inId + ", and this item's out id is " + thisItem.outId);
                if (thisItem.inId == -1 && thisItem.outId != id)
                {
                    //print("find this is a not connected item");
                    if (type == 0) //如果是trans,则所有的物体都可能是in
                    {
                        connectedObj.Add(thisItem.itemId);
                        hasConnection++;
                        //print("current part is a trans, and find a connectable item is " + thisItem.itemId);
                    }
                    else //如果是机器部件,则必须trans才可以in
                    {
                        if (thisItem.type == 0)
                        {
                            connectedObj.Add(thisItem.itemId);
                            hasConnection++;
                            //print("current part is not a trans, and find a connectable item is " + thisItem.itemId);
                        }
                    }
                }
            }
            //print("there are " + hasConnection + " objects around,");
        }
        if (hasConnection == 0) //没有连接时候,返回-1
        {
            return(-1);
        }
        else if (hasConnection == 1) //有唯一连接时,返回id
        {
            ProdLinePart thisItem = curLinePartList.Find(item => item.itemId == connectedObj[0]);
            thisItem.inId = id;
            //print(thisItem.itemId + "'s in id is" + id);
            return(connectedObj[0]);
        }
        else if (hasConnection > 1) //有大于一个连接物时,取id最小(最早放置的)
        {
            int min = connectedObj[0];
            for (int i = 0; i < connectedObj.Count; i++)
            {
                if (min > connectedObj[i])
                {
                    min = connectedObj[i];
                }
            }
            ProdLinePart thisItem = curLinePartList.Find(item => item.itemId == min);
            thisItem.inId = id;
            //print(thisItem.itemId + "'s in id is" + id);
            return(min);
        }
        return(-1);
    }
Beispiel #3
0
    void PlaceNewPart(GameObject chosenObj)
    {
        GameObject newPart = Instantiate(chosenObj, new Vector3(curX, 0, curZ), chosenObj.transform.rotation) as GameObject;

        newPart.name = chosenPart.name + curId.ToString();
        ProdLinePart curPart = new ProdLinePart();

        curPart.itemId  = curId;
        curPart.itemObj = newPart;
        curPart.itemPos = new Vector2(curX, curZ);
        switch (chosenPart.name)
        {
        case "pt_transfer":
            curPart.type = 0;
            break;

        case "pt_coremaker":
            curPart.type = 1;
            break;

        case "pt_skeletonmaker":
            curPart.type = 2;
            break;

        case "pt_musclemaker":
            curPart.type = 3;
            break;

        case "pt_painter":
            curPart.type = 4;
            break;

        case "pt_combiner":
            curPart.type = 5;
            break;
        }
        print("--------start to find in and out for item " + curPart.itemId + "--------------");
        if (curPart.type != 1) //不是core的部分,寻找是否有input
        {
            curPart.inId = GetInItemId(curPart.itemId, curPart.type, curPart.itemPos);
            print(curPart.itemId + "'s in id is ----------------- " + curPart.inId);
        }
        else
        {
            curPart.inId = -1;
        }
        if (curPart.type != 5) //不是combine的部分,寻找是否有output
        {
            curPart.outId = GetOutItemId(curPart.itemId, curPart.type, curPart.itemPos);
            print(curPart.itemId + "'s out id is ----------------- " + curPart.outId);
        }
        else
        {
            curPart.outId = -1;
        }
        curLinePartList.Add(curPart);
        curLineList.Add(new Vector2(curX, curZ));
        curId++;
        if (chosenPart.name != "pt_transfer")
        {
            Destroy(chosenPart);
            curState = 0;
        }
        if (curPart.type == 1)
        {
            startId = curPart.itemId;
            print("the start item's id is " + startId);
        }
    }