Beispiel #1
0
    }                              // only here so start can be called from level manager because boat start needs to run before character start

    protected void OnStart(int buoyancyTotal)
    {
        //SortCompLayerChange(Consts.DrawLayers.BoatLevel1);

        buoyancy.CurrentValue = buoyancyTotal;

        // Default boat, no load, max buoyancy
        weightLoad.CurrentValue  = 0;
        weightTotal.CurrentValue = 0;

        distLeakAbove.CurrentValue = 0;
        distLeakBelow.CurrentValue = 0;

        // Add people - increasing load weight & reducing buoyancy
        foreach (SpriteTossable sprite in spriteTossableSet)
        {
            // Items held/worn by a character have their weight added to the total with the character, so ignore them here.
            if (sprite is ItemBase)
            {
                if ((sprite as ItemBase).CharHeldBy != null)
                {
                    continue;
                }
            }
            weightLoad.CurrentValue += sprite.Weight;
        }
        weightTotal.CurrentValue += weightLoad.CurrentValue;

        // Account current water load
        weightWater.CurrentValue  = waterStartWeight;
        weightTotal.CurrentValue += weightWater.CurrentValue;

        // Set height of boat based on current buoyancy and water's surface (usually set to 0)
        sinkHeightIncr = SubmergableAreaRef.height / buoyancyTotal;
        AdjustBoatDepth();

        // Put hole(s) in boat
        // Use width of Submergable area reference to determine x position
        float xWidth = SubmergableAreaRef.XMax - SubmergableAreaRef.XMin;

        for (var i = 0; i < holeDataSet.Length; i++)
        {
            // Calulate proper height
            float yPos = SubmergableAreaRef.YMin + (holeDataSet[i].yByBuoyancy * sinkHeightIncr);

            GameObject holeObj = Instantiate(hole, new Vector3(SubmergableAreaRef.XMin + (holeDataSet[i].xByPercent * xWidth), yPos, transform.position.z - 0.1f), transform.rotation, transform) as GameObject;
            Hole       newHole = holeObj.GetComponent <Hole>();
            newHole.Init(lvlMngr, (int)holeDataSet[i].leakType, holeDataSet[i].yByBuoyancy);

            if (yPos <= lvlMngr.WaterSurfaceYPos)
            {
                holesSubm.Add(newHole);
            }
            else
            {
                holesSurf.Add(newHole);
            }

            if (holeDataSet[i].leakType == Consts.LeakTypesAndRates.Pinhole)
            {
                Pinholes.Add(newHole);
            }
        }

        AllLeaksToWaterUIUpdate();
        uiUpdate.RaiseEvent();
    }