示例#1
0
    public static T newUIObject <T>(string name, txUIObject parent, GameLayout layout, GameObject gameObj) where T : txUIObject, new()
    {
        T obj = new T();

        obj.setParent(parent);
        if (parent != null)
        {
            parent.addChild(obj);
            if (gameObj.transform.parent != parent.mObject.transform)
            {
                gameObj.transform.parent = parent.mObject.transform;
            }
        }
        obj.init(layout, gameObj);
        return(obj);
    }
示例#2
0
 //set
 //-------------------------------------------------------------------------------------------------------------------------------------
 public void setParent(txUIObject parent)
 {
     if (mParent == parent)
     {
         return;
     }
     // 从原来的父节点上移除
     mParent?.removeChild(this);
     // 设置新的父节点
     mParent = parent;
     if (parent != null)
     {
         parent.addChild(this);
         if (mTransform.parent != parent.getTransform())
         {
             mTransform.SetParent(parent.getTransform());
         }
     }
 }