コード例 #1
0
ファイル: EnergyBarUGUIBase.cs プロジェクト: DevZhav/error
        public static T CreateChild <T>(Transform parent, string name, bool disabled = false) where T : Component
        {
            GameObject go;

            if (parent is RectTransform)
            {
                go = new GameObject(name, typeof(RectTransform));
            }
            else
            {
                go = new GameObject(name);
            }
            if (disabled)
            {
                MadGameObject.SetActive(go, false);
            }

            go.transform.SetParent(parent);
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = Vector3.zero;
            T obj = go.GetComponent <T>();

            if (obj == null)
            {
                obj = go.AddComponent <T>();
            }
            if (MadTransform.registerUndo)
            {
                MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
            }
            return(obj);
        }
コード例 #2
0
    protected T CreateHidden<T>(string name, Transform parent = null) where T : Component {
        if (container == null) {
            // create container
            container = new GameObject("_container").transform;

#if !MAD_DEBUG
            container.gameObject.hideFlags = HideFlags.HideAndDontSave;
#else
            container.gameObject.hideFlags = HideFlags.DontSave;
#endif
        }

        if (parent == null) {
            parent = container;
        }

        var obj = MadTransform.CreateChild<T>(parent, name, true);

        // if created object is mad sprite, then assign the panel
        if (obj is MadSprite) {
            var sprite = obj as MadSprite;
            sprite.panel = panel;

            if (obj.GetType() == typeof(MadSprite)) {
                sprite.hasPremultipliedAlpha = premultipliedAlpha;
            }
        }

        MadGameObject.SetActive(obj.gameObject, true);

        #if !MAD_DEBUG
        obj.gameObject.hideFlags = HideFlags.HideAndDontSave;
        #else
        obj.gameObject.hideFlags = HideFlags.DontSave;
        #endif

        hiddenObjects.Insert(0, obj.gameObject);

        return obj;
    }