Esempio n. 1
0
    public static void InstancePrefab(UIPrefabNode pi)
    {
        if (pi.prefabPath.Length == 0 || !pi.enabled)
        {
            return;
        }

        pi.enabled = false;

        string     sPath = CheckPath(pi.prefabPath);
        GameObject goPrefab;

#if UNITY_EDITOR
        goPrefab = AssetDatabase.LoadAssetAtPath(sPath, typeof(GameObject)) as GameObject;
#else
        goPrefab = Resources.Load(Trans2ResourcesPath(sPath), typeof(GameObject)) as GameObject;
#endif
        GameObject go    = GameObject.Instantiate(goPrefab) as GameObject;
        Quaternion rot   = go.transform.localRotation;
        Vector3    scale = go.transform.localScale;

        go.transform.parent = pi.transform;

        go.transform.localPosition = pi.prefabLocalPos;
        go.transform.localScale    = scale;
        go.transform.localRotation = rot;

        foreach (UIPrefabNode childPi in go.GetComponentsInChildren <UIPrefabNode>())
        {
            InstancePrefab(childPi);
        }
    }
Esempio n. 2
0
        public static void LoadNonWidgetTransformInfo(GameObject go, UIElement ui)
        {
            if (go != null && ui != null)
            {
                Vector3 pos = ui.transform.position;
                //GameObject[] children = EditorTool.GetSubChildren(go);
                //Vector3 inv_pos_delta = (go.transform.position - pos);

                go.transform.position = pos;

                BoxCollider box = ui.GetComponent <BoxCollider>();
                if (box != null)
                {
                    BoxCollider box_go = go.GetComponent <BoxCollider>();
                    if (box_go != null)
                    {
                        box_go.center = box.center;
                        box_go.size   = box.size;
                    }
                }

                UIPrefabNode uiPN = ui.GetComponent <UIPrefabNode>();
                if (uiPN != null)
                {
                    UIPrefabNode uiPN_go = go.GetComponent <UIPrefabNode>();
                    if (uiPN_go != null)
                    {
                        uiPN_go.prefabLocalPos = uiPN.prefabLocalPos;
                        uiPN_go.SavePivot      = uiPN.SavePivot;
                        uiPN_go.origPivot      = uiPN.origPivot;
                    }
                }
            }
        }
Esempio n. 3
0
        private static bool CheckSubPrefabImpl(GameObject go, int nCookie)
        {
            UIPrefabNode node = go.GetComponent <UIPrefabNode>();

            if (node != null)
            {
                nCookie++;
            }

            if (nCookie >= 2)
            {
                return(false);
            }

            GameObject[] children = EditorTool.GetSubChildren(go);
            foreach (GameObject child in children)
            {
                if (!CheckSubPrefabImpl(child, nCookie))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 4
0
        public static bool ProcessSubPrefabBeforeExport(GameObject root)
        {
            UIElement rootUIElement = root.GetComponent <UIElement>();

            if (rootUIElement == null)
            {
                Debug.Log("Export Root Obj Has No UIElement Component");
                return(false);
            }

            if (!CheckSubPrefab(root))
            {
                EditorUtility.DisplayDialog("", "���Ͽؼ����ڶ����������������ã��޷�������", "ȷ��");
                return(false);
            }

            UIPrefabNode[] coms = root.GetComponentsInChildren <UIPrefabNode>();
            foreach (UIPrefabNode node in coms)
            {
                if (node.prefabPath.Length == 0)
                {
                    Debug.Log("UIPrefabNode prefabPath is empty");
                    continue;
                }
                string    sPath = UIPrefabNode.CheckPath(node.prefabPath);
                UIElement ue    = node.GetComponent <UIElement>();
                if (ue == null)
                {
                    Debug.Log("UIPrefabNode has no UIElement");
                    continue;
                }
                string sFullPath = ue.FullPathName;
                if (sFullPath.Length == 0)
                {
                    Debug.Log("FullPathName is empty");
                    continue;
                }

                GameObject obj = node.gameObject;

                // GameObject goPrefab = Resources.LoadAssetAtPath(sPath, typeof(GameObject)) as GameObject;
#if UNITY_EDITOR
                GameObject goPrefab = AssetDatabase.LoadAssetAtPath(sPath, typeof(GameObject)) as GameObject;
#else
                GameObject goPrefab = Resources.Load(Trans2ResourcesPath(sPath), typeof(GameObject)) as GameObject;
#endif
                if (goPrefab == null)
                {
                    Debug.Log(string.Format("Load Prefab: {0} Failed", sPath));
                    continue;
                }
                GameObject go    = GameObject.Instantiate(goPrefab) as GameObject;
                Quaternion rot   = go.transform.localRotation;
                Vector3    scale = go.transform.localScale;

                go.transform.parent        = obj.transform;
                go.transform.localPosition = node.prefabLocalPos;
                go.transform.localScale    = scale;
                go.transform.localRotation = rot;
                go.name = goPrefab.name;

                node.SavePivot = false;
                UIWidget uiW = go.GetComponent <UIWidget>();
                if (uiW != null)
                {
                    if (uiW.pivot != UIWidget.Pivot.BottomLeft)
                    {
                        node.SavePivot = true;
                        node.origPivot = uiW.pivot;
                    }
                }

                sFullPath = sFullPath + "/" + go.name;
                UIElement.SubPrefabPair pp;
                pp.sGameObjPath = sFullPath;
                pp.sPrefabPath  = sPath;
                rootUIElement.SubPrefabInfos.Add(pp);
            }
            return(true);
        }
Esempio n. 5
0
    public void SyncPrefabObjLock(bool bLock)//这里有UIPrefabNode脚本的同类prefab也要同步lock
    {
        List <UIElement> vUISync = new List <UIElement>();

        if (m_SubPrefabParent == null)
        {
            UIPrefabNode uipn = GetComponent <UIPrefabNode>();
            if (uipn == null)
            {
                return;
            }
            if (transform.childCount == 1)
            {
                GameObject    childObj  = transform.GetChild(0).gameObject;
                string        sFullPath = GetGameObjectFullPathName(childObj, m_rootUI.gameObject);
                List <string> sAllObj   = m_rootUI.FindAllObjPathWithSamePrefab(sFullPath);
                foreach (string s in sAllObj)
                {
                    string sObj = s;
                    int    n    = s.LastIndexOf('/');
                    if (n >= 0)
                    {
                        sObj = s.Substring(0, n);
                    }

                    GameObject obj = FindObject(sObj);
                    if (obj != null)
                    {
                        UIElement ui = obj.GetComponent <UIElement>();
                        ui.Lock = bLock;
                        vUISync.Add(ui);
                    }
                }
            }
            else
            {
                Debug.Log("Logic Error: UIPrefabNode has more than one child");
            }
        }
        else
        {
            if (m_rootUI == null)
            {
                Debug.Log("Logic Error: rootUI is empty");
                return;
            }
            string        sFullPath           = GetGameObjectFullPathName(m_SubPrefabParent, m_rootUI.gameObject);
            List <string> sAllObj             = m_rootUI.FindAllObjPathWithSamePrefab(sFullPath);
            string        sRelPathToSubPrefab = GetRelPathToSubPrefab();
            foreach (string s in sAllObj)
            {
                string     sObj = s + sRelPathToSubPrefab;
                GameObject obj  = FindObject(sObj);
                if (obj != null)
                {
                    UIElement ui = obj.GetComponent <UIElement>();
                    ui.Lock = bLock;
                    vUISync.Add(ui);
                }
            }
        }

        if (vUISync.Count > 0)
        {
            if (funcSyncUITreeLockForSubPrefab != null)
            {
                funcSyncUITreeLockForSubPrefab(vUISync);
            }
        }
    }