Example #1
0
    public void InteractWithPosition(ConnectionPoint f)
    {
        switch (carriageCargoState)
        {
        case CarriageCargoState.CarriageFull:        //Try to Empty the Carriage (Lay Down the Resource)
            if (f.resourceInput && !f.resourceOnField)
            {
                if (f.PushResource(cargo))
                {
                    ChangeMesh(basicMesh);
                    ChangeCarriageCargoStateTO(CarriageCargoState.CarriageEmpty);
                    ChangeCarriageStateTO(CarriageState.CarriageIdle);
                }
            }

            break;

        case CarriageCargoState.CarriageEmpty:
            //Is there a Resource on this Field
            if (f.ResourceWaitingForPickup() && f.resourceOutput)
            {
                cargo = f.PullResource();
                ChangeCarriageCargoStateTO(CarriageCargoState.CarriageFull);

                var t = cargo.GetComponent <Resource>().type;
                if (t == Resource.ResourceType.Wood)
                {
                    ChangeMesh(woodMesh);
                }
                else if (t == Resource.ResourceType.Planks)
                {
                    ChangeMesh(plankMesh);
                }
                else if (t == Resource.ResourceType.Grain || t == Resource.ResourceType.Flour || t == Resource.ResourceType.Bread)
                {
                    ChangeMesh(grainMesh);
                }

                ChangeCarriageStateTO(CarriageState.CarriageIdle);
            }
            else if (f.resourceOutput)
            {
                ChangeCarriageStateTO(CarriageState.CarriageWaitForResource);
            }
            else
            {
                ChangeCarriageStateTO(CarriageState.CarriageIdle);
            }
            break;
        }
    }