// Update is called once per frame
 void FixedUpdate()
 {
     modFrame %= 2;
     if (items[0] != null)
     {
         if (
             (
                 ((modFrame == 0 || rightOutput == null) && filterSide == -1) ||
                 ((filterSide == 0 && filter == items[0].item.id) || (filterSide == 1 && filter != items[0].item.id))
             ) &&
             leftOutput != null)
         {
             if (outputOrientation == ConveyorBelt.OutputOrientation.East)
             {
                 if (leftOutput.TryInsertHorizontal(items[0], this.transform.position.x + 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.x += 0.51f;
                     temp.y += 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             else if (outputOrientation == ConveyorBelt.OutputOrientation.West)
             {
                 if (leftOutput.TryInsertHorizontal(items[0], this.transform.position.x - 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.x -= 0.51f;
                     temp.y += 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             else if (outputOrientation == ConveyorBelt.OutputOrientation.North)
             {
                 if (leftOutput.TryInsertVertical(items[0], this.transform.position.y + 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.y += 0.51f;
                     temp.x -= 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             else
             {
                 if (leftOutput.TryInsertVertical(items[0], this.transform.position.y - 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.y -= 0.51f;
                     temp.x -= 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             modFrame++;
         }
         else if (
             (
                 ((modFrame == 1 || leftOutput == null) && filterSide == -1) ||
                 ((filterSide == 1 && filter == items[0].item.id) || (filterSide == 0 && filter != items[0].item.id))
             ) &&
             rightOutput != null)
         {
             if (outputOrientation == ConveyorBelt.OutputOrientation.East)
             {
                 if (rightOutput.TryInsertHorizontal(items[0], this.transform.position.x + 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.x += 0.51f;
                     temp.y -= 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             else if (outputOrientation == ConveyorBelt.OutputOrientation.West)
             {
                 if (rightOutput.TryInsertHorizontal(items[0], this.transform.position.x - 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.x -= 0.51f;
                     temp.y -= 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             else if (outputOrientation == ConveyorBelt.OutputOrientation.North)
             {
                 if (rightOutput.TryInsertVertical(items[0], this.transform.position.y + 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.y += 0.51f;
                     temp.x += 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             else
             {
                 if (rightOutput.TryInsertVertical(items[0], this.transform.position.y - 0.51f))
                 {
                     Vector3 temp = this.transform.position;
                     temp.y -= 0.51f;
                     temp.x += 0.5f;
                     items[0].transform.position = temp;
                     for (int j = 0; j < items.Length - 1; j++)
                     {
                         items[j] = items[j + 1];
                     }
                     items[items.Length - 1] = null;
                     heldItems--;
                 }
             }
             modFrame++;
         }
     }
 }
示例#2
0
 void FixedUpdate()
 {
     if (output != null && items[0] != null) //push into output belt
     {
         //push input output belt
         if (outputOrientation == ConveyorBelt.OutputOrientation.East)
         {
             if (output.TryInsertHorizontal(items[0], this.transform.position.x + 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.x += 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
         else if (outputOrientation == ConveyorBelt.OutputOrientation.West)
         {
             if (output.TryInsertHorizontal(items[0], this.transform.position.x - 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.x -= 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
         else if (outputOrientation == ConveyorBelt.OutputOrientation.North)
         {
             if (output.TryInsertVertical(items[0], this.transform.position.y + 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.y += 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
         else
         {
             if (output.TryInsertVertical(items[0], this.transform.position.y - 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.y -= 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
     }
 }
示例#3
0
    /// <summary>
    /// I'm sure someone's done it better.  Don't think about it too hard.
    /// </summary>
    public void FixedUpdate()
    {
        if (rotationState == Rotation.Vertical)
        {
            for (int i = 0; i < items.Length; i++)
            {
                if (items[i] == null)
                {
                    break;
                }
                Vector3 temp   = items[i].transform.position;
                float   deltaX = temp.x - this.transform.position.x;
                if (deltaX > 2 * conveyorBeltSpeed)
                {
                    temp.x -= 2 * conveyorBeltSpeed;
                }
                else if (deltaX < -2 * conveyorBeltSpeed)
                {
                    temp.x += 2 * conveyorBeltSpeed;
                }
                else
                {
                    temp.x = this.transform.position.x;
                }
                temp.y += conveyorBeltSpeed * velocityMultiplier;

                if (nextBelt == null && velocityMultiplier * (temp.y - this.transform.position.y) >= beltSpacing)
                {
                    temp.y = this.transform.position.y + velocityMultiplier * beltSpacing;
                }
                else if (Mathf.Abs(temp.y - this.transform.position.y) > 0.5f) //will do nothing if item can't be inserted to next belt
                {
                    if (nextBelt.GetOutputOrientation() != this.outputOrientation && nextBelt.TryInsertHorizontal(items[i], temp.x))
                    {
                        items[i].transform.position = temp;
                        for (int j = i; j < items.Length - 1; j++)
                        {
                            items[j] = items[j + 1];
                        }
                        items[items.Length - 1] = null;
                        heldItems--;
                    }
                    if (nextBelt.TryInsertVertical(items[i], temp.y))
                    {
                        items[i].transform.position = temp;
                        for (int j = i; j < items.Length - 1; j++)
                        {
                            items[j] = items[j + 1];
                        }
                        items[items.Length - 1] = null;
                        heldItems--;
                    }
                }
                else if ((i == 0 && (nextBelt == null || !nextBelt.CheckCollisionVertical(temp.y))) ||
                         (i - 1 >= 0 && Mathf.Abs(temp.y - items[i - 1].transform.position.y) >= beltSpacing)) //moves item forward if it isn't outside the belt (need to check against items in front)
                {
                    items[i].transform.position = temp;
                }
            }
        }
        else
        {
            for (int i = 0; i < items.Length; i++)
            {
                if (items[i] == null)
                {
                    break;
                }
                Vector3 temp   = items[i].transform.position;
                float   deltaY = temp.y - this.transform.position.y;
                if (deltaY > 2 * conveyorBeltSpeed)
                {
                    temp.y -= 2 * conveyorBeltSpeed;
                }
                else if (deltaY < -2 * conveyorBeltSpeed)
                {
                    temp.y += 2 * conveyorBeltSpeed;
                }
                else
                {
                    temp.y = this.transform.position.y;
                }
                temp.x += conveyorBeltSpeed * velocityMultiplier;

                if (nextBelt == null && velocityMultiplier * (temp.x - this.transform.position.x) >= beltSpacing)
                {
                    temp.x = this.transform.position.x + velocityMultiplier * beltSpacing;
                }
                else if (Mathf.Abs(temp.x - this.transform.position.x) > 0.5f) //will do nothing if item can't be inserted to next belt
                {
                    if (nextBelt.GetOutputOrientation() != this.outputOrientation && nextBelt.TryInsertVertical(items[i], temp.y))
                    {
                        items[i].transform.position = temp;
                        for (int j = i; j < items.Length - 1; j++)
                        {
                            items[j] = items[j + 1];
                        }
                        items[items.Length - 1] = null;
                        heldItems--;
                    }
                    if (nextBelt.TryInsertHorizontal(items[i], temp.x))
                    {
                        items[i].transform.position = temp;
                        for (int j = i; j < items.Length - 1; j++)
                        {
                            items[j] = items[j + 1];
                        }
                        items[items.Length - 1] = null;
                        heldItems--;
                    }
                }
                else if ((i == 0 && (nextBelt == null || !nextBelt.CheckCollisionHorizontal(temp.x))) ||
                         (i - 1 >= 0 && Mathf.Abs(temp.x - items[i - 1].transform.position.x) >= beltSpacing)) //moves item forward if it isn't outside the belt (need to check against items in front)
                {
                    items[i].transform.position = temp;
                }
            }
        }
        if (bufferedInput != null)
        {
            items[heldItems] = bufferedInput;
            heldItems++;
            bufferedInput = null;
        }
    }
示例#4
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (inputInventory != null && heldItems < items.Length) //pull from input inventory
     {
         ItemEntity item = inputInventory.GetOutputItemEntity(this.transform.position, filter);
         if (item != null)
         {
             items[heldItems] = item;
             heldItems++;
         }
     }
     //try to pull from input belt (actually this is handled by prev belts) but this does give me the idea to fix belt wiggle maybe
     if (outputInventory != null && heldItems > 0) //push into output inventory
     {
         if (outputInventory.TryInsertItem(items[0].item))
         {
             items[0].ConsumeItem();
             for (int j = 0; j < items.Length - 1; j++)
             {
                 items[j] = items[j + 1];
             }
             items[items.Length - 1] = null;
             heldItems--;
         }
     }
     if (outputBelt != null && items[0] != null) //push into output belt
     {
         //push input output belt
         if (outputOrientation == ConveyorBelt.OutputOrientation.East)
         {
             if (outputBelt.TryInsertHorizontal(items[0], this.transform.position.x + 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.x += 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
         else if (outputOrientation == ConveyorBelt.OutputOrientation.West)
         {
             if (outputBelt.TryInsertHorizontal(items[0], this.transform.position.x - 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.x -= 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
         else if (outputOrientation == ConveyorBelt.OutputOrientation.North)
         {
             if (outputBelt.TryInsertVertical(items[0], this.transform.position.y + 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.y += 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
         else
         {
             if (outputBelt.TryInsertVertical(items[0], this.transform.position.y - 0.51f))
             {
                 Vector3 temp = this.transform.position;
                 temp.y -= 0.51f;
                 items[0].transform.position = temp;
                 for (int j = 0; j < items.Length - 1; j++)
                 {
                     items[j] = items[j + 1];
                 }
                 items[items.Length - 1] = null;
                 heldItems--;
             }
         }
     }
 }