Exemplo n.º 1
0
    //创建地图元素
    public void CreateElementInList()
    {
        if (createElementList == null || createElementList.Count == 0)
        {
            return;
        }

        string key = createElementList[0];

        createElementList.RemoveAt(0);
        MapElement     elementData = visionElementDic[key];
        MapElementInfo elementInfo = elementData.elementInfo;

        activeObj[elementData.elementKey] = null;

        GameObject tempObj = GetObjByDisable(elementData.elementType);

        if (tempObj != null)
        {
            elementLoader.PushCallBack(() =>
            {
                if (tempObj == null)
                {
                    return(false);
                }
                tempObj.transform.position    = elementInfo.Pos;
                tempObj.transform.eulerAngles = elementInfo.Angle;
                tempObj.transform.localScale  = elementInfo.Scale;
                tempObj.SetActive(true);
                activeObj[elementData.elementKey] = tempObj;
                return(true);
            });
        }
        else
        {
            string elementAssetPath = string.Format(MapDefine.MapElementPath, elementData.elementType);
            AssetManager.LoadAsset(elementAssetPath, (obj, str) =>
            {
                elementLoader.PushCallBack(() =>
                {
                    if (obj != null)//&& visionElementDic.ContainsKey(key))
                    {
                        if (activeObj.ContainsKey(elementData.elementKey))
                        {
                            GameObject assetTree = obj as GameObject;
                            Transform element    = GameObject.Instantiate(assetTree).transform;
                            element.SetParent(elementRoot.transform);
                            element.position    = elementInfo.Pos;
                            element.eulerAngles = elementInfo.Angle;
                            element.localScale  = elementInfo.Scale;
                            activeObj[elementData.elementKey] = element.gameObject;
                            return(true);
                        }
                        return(false);
                    }
                    return(false);
                });
            });
        }
    }
Exemplo n.º 2
0
    //清理地图元素(放入未激活列表)
    public void ClearElementInList()
    {
        if (disableElementList == null || disableElementList.Count == 0)
        {
            return;
        }
        string key = disableElementList[0];

        disableElementList.RemoveAt(0);
        if (activeObj.ContainsKey(key))
        {
            GameObject tempObj = activeObj[key];
            elementUnLoader.PushCallBack(() =>
            {
                if (tempObj != null)
                {
                    tempObj.SetActive(false);
                    disabelObj.Add(tempObj);
                    return(true);
                }
                return(false);
            });
            activeObj.Remove(key);
        }
    }
Exemplo n.º 3
0
 //销毁多余地图元素
 private void DestroyElementList(List <GameObject> destroyList)
 {
     if (destroyList == null)
     {
         return;
     }
     for (int index = 0; index < destroyList.Count; index++)
     {
         GameObject destroyObj = destroyList[index];
         elementUnLoader.PushCallBack(() =>
         {
             if (destroyObj == null)
             {
                 return(false);
             }
             GameObject.Destroy(destroyObj);
             return(true);
         });
     }
     destroyList.Clear();
 }
Exemplo n.º 4
0
    public void CreateElementInList()
    {
        while (createElementList.Count > 0)
        {
            string key = createElementList[0];
            createElementList.RemoveAt(0);
            MapElement     elementData = visionElementDic[key];
            MapElementInfo elementInfo = elementData.elementInfo;
            activeObj[elementData.elementKey] = null;

            GameObject tempObj = GetObjByCache(elementData.elementType);
            if (tempObj != null)
            {
                if (tempObj.activeSelf)
                {
                    SetElementTransform(tempObj.transform, elementInfo);
                    activeObj[elementData.elementKey] = tempObj;
                    return;
                }
                elementLoader.PushCallBack(() =>
                {
                    if (tempObj == null)
                    {
                        return(false);
                    }
                    if (!visionElementDic.ContainsKey(elementData.elementKey))
                    {
                        activeObj.Remove(elementData.elementKey);
                        return(false);
                    }
                    SetElementTransform(tempObj.transform, elementInfo);
                    tempObj.SetActive(true);
                    activeObj[elementData.elementKey] = tempObj;
                    return(true);
                });
            }
            else
            {
                string elementAssetPath = string.Format(MapDefine.MapElementPath, elementData.elementType);
                AssetManager.LoadAsset(elementAssetPath, (obj, str) =>
                {
                    elementLoader.PushCallBack(() =>
                    {
                        if (obj != null) //&& visionElementDic.ContainsKey(key))
                        {
                            if (activeObj.ContainsKey(elementData.elementKey))
                            {
                                if (!visionElementDic.ContainsKey(elementData.elementKey))
                                {
                                    return(false);
                                }
                                GameObject assetTree = obj as GameObject;
                                Transform element    = GameObject.Instantiate(assetTree).transform;
                                element.SetParent(data.root);
                                SetElementTransform(element, elementInfo);
                                activeObj[elementData.elementKey] = element.gameObject;
                                return(true);
                            }
                            return(false);
                        }
                        return(false);
                    });
                });
            }
        }
    }