Пример #1
0
    protected void BuildElement() {
        SceneElement element = target as SceneElement;
        if (element.tag == "Untagged") {
            element.tag = tagOptions[0];
        }
        SpriteRenderer sr = element.GetComponentInChildren<SpriteRenderer>();
        if (sr == null) {
            GameObject goPivot = new GameObject("pivot");
            goPivot.transform.parent = element.transform;
            goPivot.transform.localPosition = new Vector3(0, 0, -0.5f);
            
            GameObject go = new GameObject("sprite");
            go.transform.parent = goPivot.transform;
            go.transform.localPosition = new Vector3(0, 0, 0.5f);
            sr = go.AddComponent<SpriteRenderer>();
            sr.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd");
        }
        var sppos = sr.transform.localPosition;
        sr.transform.localPosition = new Vector3(sppos.x,0, sppos.z);
        sr.transform.localEulerAngles = new Vector3(90, 0, 0);

        BoxCollider bc = element.GetComponent<BoxCollider>();
        Vector3 size = bc.size;
        bc.size = new Vector3(size.x, 5, size.z);

        Rigidbody rig = element.GetComponent<Rigidbody>();
        if (rig == null) {
            rig = element.gameObject.AddComponent<Rigidbody>();
        }
        rig.isKinematic = true;
        rig.useGravity = false;
    }