Ejemplo n.º 1
0
    private static void ParseSceneConfig(string sceneName, XmlNodeList nodeList)
    {
        if (nodeList == null)
        {
            return;
        }
        SceneInfo sceneInfo = new SceneInfo();

        sceneInfo.SceneName = sceneName;
        XmlElement  node      = nodeList[0] as XmlElement;
        XmlNodeList childList = node.GetElementsByTagName("a");
        int         count     = childList.Count;

        for (int j = 0; j < count; ++j)
        {
            GameObjectInfo gameObjectInfo = new GameObjectInfo();
            XmlElement     child          = childList[j] as XmlElement;
            string         nn             = child.GetAttribute("n");
            string         value          = child.InnerXml;
            if (nn == "G")
            {
                string[] values = value.Split(',');
                gameObjectInfo.PrefabName = values[0];
                gameObjectInfo.X          = float.Parse(values[1]);
                gameObjectInfo.Y          = float.Parse(values[2]);
                gameObjectInfo.Z          = float.Parse(values[3]);
                gameObjectInfo.RotationX  = float.Parse(values[4]);
                gameObjectInfo.RotationY  = float.Parse(values[5]);
                gameObjectInfo.RotationZ  = float.Parse(values[6]);
                gameObjectInfo.ScaleX     = float.Parse(values[7]);
                gameObjectInfo.ScaleY     = float.Parse(values[8]);
                gameObjectInfo.ScaleZ     = float.Parse(values[9]);
                gameObjectInfo.Type       = int.Parse(values[10]);
                sceneInfo.AddGameObjectInfo(gameObjectInfo);
            }
            else if (nn == "GS")
            {
                sceneInfo.GridsContent = value;
            }
        }
        sceneResConfigInfos.Add(sceneName, sceneInfo);
    }
Ejemplo n.º 2
0
    public static void AutoMakeScene()
    {
        UnityEngine.SceneManagement.Scene scene = EditorSceneManager.GetActiveScene();
        Debug.Log("scene name:" + scene.name + " / scene path:" + scene.path);
        GameObject[] gos       = scene.GetRootGameObjects();
        SceneInfo    sceneInfo = new SceneInfo();

        sceneInfo.SaveGridsByBytes = IsSaveByBytes;
        int count = 0;
        int j;

        bool       isHaveTerrain = false;
        GameObject nonblocks     = null;
        GameObject terrainGo     = null;

        for (int i = 0; i < gos.Length; ++i)
        {
            GameObject     go = gos[i];
            Transform      ts;
            GameObjectInfo gameObjectInfo;
            if (go.name == GameObjectTags.Terrain)
            {
                //地形
                count = go.transform.childCount;
                if (count > 1)
                {
                    throw new System.Exception("地形节点下只允许有一个地形GameObject!!!");
                }
                else if (count == 0)
                {
                    throw new System.Exception("地形节点没有一个地形GameObject,请添加!!!");
                }
                isHaveTerrain = true;
                ts            = go.transform.GetChild(0);
                terrainGo     = ts.gameObject;
                if (ts.tag != GameObjectTags.Terrain)
                {
                    throw new System.Exception("地形节点下有名称为:" + ts.name + "的GameObject的Tag不为terrain,请重新设置!!!");
                }

                Collider collider = ts.GetComponent <Collider>();
                if (collider == null)
                {
                    throw new System.Exception("地形节点下有名称为:" + ts.name + "的GameObject的不带有碰撞组件,请添加!!!");
                }
                Renderer render = ts.GetComponent <Renderer>();
                if (render == null || (render != null && !render.enabled))
                {
                    if (render == null)
                    {
                        throw new System.Exception("地形节点下有名称为:" + ts.name + "的GameObject不带有渲染组件,请添加渲染组件!!!");
                    }
                    else
                    {
                        throw new System.Exception("地形节点下有名称为:" + ts.name + "的GameObject的渲染组件未激活,请激活渲染组件!!!");
                    }
                }
                gameObjectInfo = GetGameObjectInfo(ts, GameObjectTypes.Terrain);
                sceneInfo.AddGameObjectInfo(gameObjectInfo);
            }
            else if (go.name == "nonblocks")
            {
                //非阻挡
                count     = go.transform.childCount;
                nonblocks = go;
                for (j = 0; j < count; ++j)
                {
                    ts = go.transform.GetChild(j);
                    if (!ts.gameObject.activeSelf)
                    {
                        continue;
                    }
                    if (ts.tag != GameObjectTags.NON_Block)
                    {
                        throw new System.Exception("非阻挡节点下有名称为:" + ts.name + "的GameObject的Tag不为nonblock,请重新设置!!!");
                    }
                    Collider collider = ts.GetComponent <Collider>();
                    if (collider != null)
                    {
                        throw new System.Exception("非阻挡节点下有名称为:" + ts.name + "的GameObject带有碰撞组件,请删除!!!");
                    }
                    Renderer render = ts.GetComponent <Renderer>();
                    if (render == null || (render != null && !render.enabled))
                    {
                        if (render == null)
                        {
                            throw new System.Exception("非阻挡节点下有名称为:" + ts.name + "的GameObject不带有渲染组件,请添加渲染组件!!!");
                        }
                        else
                        {
                            throw new System.Exception("非阻挡节点下有名称为:" + ts.name + "的GameObject的渲染组件未激活,请激活渲染组件!!!");
                        }
                    }

                    //Debug.LogError("render.lightmapIndex:" + render.lightmapIndex);
                    //Debug.LogError("render.lightmapScaleOffset:" + render.lightmapScaleOffset);
                    //    render.lightmapScaleOffset
                    //    render.lightProbeAnchor
                    //    render.lightProbeProxyVolumeOverride
                    //    render.lightProbeUsage
                    //    render.realtimeLightmapIndex
                    //    render.realtimeLightmapScaleOffset
                    //    render.useLightProbes

                    gameObjectInfo = GetGameObjectInfo(ts, GameObjectTypes.NonBlock);
                    sceneInfo.AddGameObjectInfo(gameObjectInfo);
                }
            }
            else if (go.name == "blocks")
            {
                count = go.transform.childCount;
                for (j = 0; j < count; ++j)
                {
                    ts = go.transform.GetChild(j);
                    if (!ts.gameObject.activeSelf)
                    {
                        continue;
                    }
                    if (ts.tag != GameObjectTags.Block)
                    {
                        throw new System.Exception("阻挡节点下有名称为:" + ts.name + "的GameObject的Tag不为block,请重新设置!!!");
                    }
                    Collider collider = ts.GetComponent <Collider>();
                    if (collider == null || (collider != null && !collider.enabled))
                    {
                        if (collider == null)
                        {
                            throw new System.Exception("阻挡节点下有名称为:" + ts.name + "的GameObject没有碰撞组件,请添加!!!");
                        }
                        else
                        {
                            throw new System.Exception("阻挡节点下有名称为:" + ts.name + "的GameObject碰撞组件未激活,请激活!!!");
                        }
                    }
                    Renderer render = ts.GetComponent <Renderer>();
                    if (render != null)
                    {
                        throw new System.Exception("阻挡节点下有名称为:" + ts.name + "的GameObject带有渲染组件,请删除渲染组件!!!");
                    }
                    gameObjectInfo = GetGameObjectInfo(ts, GameObjectTypes.Block);
                    sceneInfo.AddGameObjectInfo(gameObjectInfo);
                }
            }
            else if (go.name == "effects")
            {
                count = go.transform.childCount;
                for (j = 0; j < count; ++j)
                {
                    ts = go.transform.GetChild(j);
                    if (!ts.gameObject.activeSelf)
                    {
                        continue;
                    }
                    if (ts.tag != GameObjectTags.Scene_Effect)
                    {
                        throw new System.Exception("场景特效节点下有名称为:" + ts.name + "的GameObject的Tag不为scene_effect,请重新设置!!!");
                    }
                    gameObjectInfo = GetGameObjectInfo(ts, GameObjectTypes.Effect);
                    sceneInfo.AddGameObjectInfo(gameObjectInfo);
                }
            }
            else if (go.name == "lights")
            {
                count = go.transform.childCount;
                for (j = 0; j < count; ++j)
                {
                    ts = go.transform.GetChild(j);
                    if (!ts.gameObject.activeSelf)
                    {
                        continue;
                    }
                    gameObjectInfo = GetGameObjectInfo(ts, GameObjectTypes.Light);
                    sceneInfo.AddGameObjectInfo(gameObjectInfo);
                }
            }
        }
        if (!isHaveTerrain)
        {
            throw new System.Exception("该地图没有地形GameObject,请添加!!!");
        }
        if (nonblocks != null)
        {
            nonblocks.SetActive(false);
        }
        if (sceneInfo.SaveGridsByBytes)
        {
            MakeGridToBytes(terrainGo, sceneInfo);
        }
        else
        {
            MakeGridToString(terrainGo, sceneInfo);
        }
        if (nonblocks != null)
        {
            nonblocks.SetActive(true);
        }

        SaveConfig(sceneInfo, scene.path);

        AssetDatabase.Refresh();
    }