示例#1
0
    private void MakeTier(int Height, int TierCode, float Rotation)
    {
        // go get the tier data (an int [24]) from the "Tier Data" object
        int[] data = TD.GetTierData(TierCode);

        // instantiate primary section = this will have the Tag and control script (further segments are childed to it)
        // IMPORTANT ... Segment 0 ALWAYS should be 1 (a solid vanilla platform)
        Transform Seg0 = (Transform)Instantiate(Seg15, new Vector3(0, Height - (Controller.BallScale.y) / 2, 0), Quaternion.Euler(0, Rotation, 0));

        Seg0.gameObject.tag       = Height.ToString();       // set tag
        Seg0.transform.localScale = Controller.SegmentScale; // set scale
        Seg0.gameObject.AddComponent <TierScript>();         // add tier control script (and configure it)
        Seg0.gameObject.GetComponent <TierScript>().myData   = data;
        Seg0.gameObject.GetComponent <TierScript>().rotation = Rotation;
        Color safeColour;

        ColorUtility.TryParseHtmlString(hexColours[baseColour], out safeColour);
        Seg0.gameObject.GetComponentsInChildren <Renderer>()[0].material.color = safeColour;

        // make each 15 degree segment fanning around from the "base segement .. (above)"
        for (int i = 1; i < 24; i++)
        {
            if (data[i] > 0)
            {
                Transform segClone = (Transform)Instantiate(Seg15, new Vector3(0, Height - (Controller.BallScale.y) / 2, 0), Quaternion.Euler(0, (i * 15) + Rotation, 0));
                segClone.transform.localScale = Controller.SegmentScale;
                segClone.gameObject.GetComponentsInChildren <Renderer>()[0].material.color = safeColour;
                if (data[i] == 2)
                {
                    segClone.transform.localScale = Vector3.Scale(segClone.transform.localScale, Controller.HazardScaleModifier);
                    Color hazardColour;
                    ColorUtility.TryParseHtmlString(hexColours[contrastColour], out hazardColour);
                    segClone.gameObject.GetComponentsInChildren <Renderer>()[0].material.color = hazardColour;
                }
                segClone.transform.parent = Seg0.transform;
            }
        }
    }