FarmObject.Setup C# (CSharp) 메소드

Setup() 개인적인 메소드

private Setup ( ) : void
리턴 void
    private void Setup()
    {
        float x, y, z;
        float length, width, height;
        string name = "Unnamed";
        Vector3 scale, position;

        // Set object variables

        x = node ["x"].AsFloat;
        z = node ["y"].AsFloat;
        y = node ["z"].AsFloat;
        length = node ["length"].AsFloat;
        width = node ["width"].AsFloat;
        height = node ["height"].AsFloat;
        if (node["name"] != null)
        {
            name = node ["name"];
        }

        // Set object position, scale, parent, name

        // Set Name
        gameObject.name = name;
        // Set Scale
        scale = new Vector3 (length, height, width);
        transform.localScale = scale;
        // Set Parent gameObject (transform)
        transform.SetParent (parentTransform);
        // Set Position
        Vector3 plScale = transform.parent.lossyScale;
        position = new Vector3 (x / plScale.x, y / plScale.y, z / plScale.z);
        if (isUnityPrimitive)
        {
            Vector3 primitiveOffset = new Vector3(transform.localScale.x*0.5f - 0.5f, transform.localScale.y*0.5f - 0.5f, transform.localScale.z*0.5f - 0.5f);
            position += primitiveOffset;
        }
        transform.localPosition = position;

        InitializeResources ();

        if(isTray(myURL))
        {
            isTrayObject = true;
            FarmTray script = GetComponent<FarmTray>();
            script.node = node;
            script.PopulateTray();
        }

        // Check for children, and create as necessary

        if (node["children"] == null )
        {
            return;
        }

        JSONArray children = node["children"].AsArray;
        foreach (JSONNode child in children)
        {

            GameObject toCreate = genericFarmObject;
            // Check type for tray vs generic
            if(isTray (child))
            {
                toCreate = trayFarmObject;
            }

            // Instantiate correct object
            GameObject childObject = Instantiate(toCreate) as GameObject;
            // Set parent
            childObject.transform.GetComponent<FarmObject>().parentTransform = transform;
            childrenTransforms.Add(childObject.transform);
            // Call setup
            childObject.GetComponent<FarmObject>().Build(child);
        }
    }