コード例 #1
0
    public static void WriteXMLSpawned(SpawnedData spawnedData)
    {
        DataContainer DataCollection = new DataContainer();

        DataCollection.SpawnedData = spawnedData;
        DataCollection.Save(Path.Combine(dataPath, Program.gameScene.Terreno.name + ".Spawned" + ".xml"));
    }
コード例 #2
0
    public void SaveData()
    {
        //Debug.Log("Called SaveData");

        spawnedData = new SpawnedData();
        spawnedData.AllSpawnedObj = AllSpawnedDataList;
        spawnedData.TerraMshCntrlAllVertexIndexCount = p.MeshController.AllVertexs.Count;
        XMLSerie.WriteXMLSpawned(spawnedData);
    }
コード例 #3
0
 void AddToAllSpawnedDataOnSpecificIndex(SpawnedData sData, bool replantTree)
 {
     if (replantTree)
     {
         AllSpawnedDataList.Insert(0, sData);
     }
     else
     {
         AllSpawnedDataList.Add(sData);
     }
 }
コード例 #4
0
ファイル: Registro.cs プロジェクト: Cdrix/SM
    /// <summary>
    /// todo...
    /// to be used only when loading a brand new Terra Spawner file
    ///
    /// if spawnedData is in the closest9 regions will check if needs to remove itself bz
    /// could fall into a building
    /// </summary>
    /// <param name="spawnedData"></param>
    /// <param name="closest9"></param>
    internal void MarkTerraIfNeeded(SpawnedData spawnedData, List <RegionD> closest9)
    {
        var index = closest9.FindIndex(a => a.Region == spawnedData.Region);

        if (index == -1)
        {
            return;
        }

        for (int i = 0; i < AllBuilding.Count; i++)
        {
            AllBuilding.ElementAt(i).Value.CheckOnMarkTerra();
        }
    }
コード例 #5
0
    /// <summary>
    /// How To create new Spawned Data for terrain
    ///
    /// make  :
    ///spawnedData = XMLSerie.ReadXMLSpawned(true)
    ///spawnedData = XMLSerie.ReadXMLSpawned()
    ///
    /// </summary>
    public void LoadData()
    {
        try
        {
            if (!Program.gameScene.IsDefaultTerreno())
            {
                spawnedData = XMLSerie.ReadXMLSpawned();

                if (spawnedData == null)
                {
                    Debug.Log("spawnedData == null big");
                }
            }
            else//the first teraain to load
            {
                spawnedData = XMLSerie.ReadXMLSpawned(true);//true once Terrain.Spawned is created

                if (spawnedData == null)
                {
                    Debug.Log("spawnedData == null DefaultLoad");
                }
            }
        }
        catch (Exception exception)
        { print("error loading XMLSerie.ReadXMLSpawned()." + exception.GetBaseException().Message); }

        //print(spawnedData.TerraMshCntrlAllVertexIndexCount + "spawnedData.TerraMshCntrlAllVertexIndexCount");
        //print(Terreno.MeshController.AllVertexs.Count + "Terreno.MeshController.AllVertexs.Count");

        if (spawnedData == null)
        {
            return;
        }
        if (spawnedData.TerraMshCntrlAllVertexIndexCount != p.MeshController.AllVertexs.Count)
        {
            print("subMesh loaded not the same as the one was the spawned obj created with");
            IsToSave = true;
            ClearCurrentFileAndList();
            return;
        }

        AllSpawnedDataList = spawnedData.AllSpawnedObj;
        p.TerraSpawnController.IsToLoadFromFile = true;
    }
コード例 #6
0
 //Save all the data into AllSpawnedDataList
 void SaveOnListData(General obj, H typeP, int rootToSpawnIndex, int indexPass, bool replantTree, int region)
 {
     if (obj == null)
     {
         return;
     }
     if (obj is StillElement)
     {
         SpawnedData sData = new SpawnedData(obj.transform.position, obj.transform.rotation, typeP,
                                             rootToSpawnIndex, indexPass, region: region);
         AddToAllSpawnedDataOnSpecificIndex(sData, replantTree);
     }
     else
     {
         SpawnedData sData = new SpawnedData(obj.transform.position, obj.transform.rotation, typeP, rootToSpawnIndex,
                                             indexPass, region: region);
         AddToAllSpawnedDataOnSpecificIndex(sData, replantTree);
     }
 }
コード例 #7
0
    SpawnedData CreateApropData(TerrainRamdonSpawner ele)
    {
        SpawnedData sData = null;

        if (ele.HType == H.Tree)
        {
            var still = (StillElement)ele;

            sData = new SpawnedData(ele.transform.position, ele.transform.rotation, ele.HType,
                                    ele.RootToSpawnIndex, ele.IndexAllVertex, still.Height, still.SeedDate, still.MaxHeight,
                                    still.TreeFall, still.Weight, ele.Region);
        }
        else
        {
            sData = new SpawnedData(ele.transform.position, ele.transform.rotation, ele.HType,
                                    ele.RootToSpawnIndex, ele.IndexAllVertex, ele.Region);
        }

        return(sData);
    }
コード例 #8
0
    /// <summary>
    /// read on caller of this if trying to create Terrain.Spawner file
    /// </summary>
    /// <param name="defaultP"></param>
    /// <returns></returns>
    public static SpawnedData ReadXMLSpawned(bool defaultP = false)
    {
        DataContainer loaded = null;

        if (defaultP)
        {
            //which is a small Spawed terrain of bayAndMountain1River
            loaded =
                DataContainer.Load(Path.Combine(ReturnRightSpawnerRoot(), "DefaultLoad.xml"));
        }
        else
        {
            loaded =
                DataContainer.Load(Path.Combine(ReturnRightSpawnerRoot(), Program.gameScene.Terreno.name + ".Spawned" + ".xml"));
        }

        SpawnedData res = null;

        if (loaded != null)
        {
            res = loaded.SpawnedData;
        }
        return(res);
    }
コード例 #9
0
    public static GameObject SetupRoomObject(GameObject go, RoomObject obj)
    {
        go.name = obj.prefabName + "_" + obj.ID;
        go.transform.localPosition = new Vector3(obj.coords.x, obj.coords.y, go.transform.localPosition.z);
        SpawnedData spawnedData = go.GetComponent <SpawnedData>();

        if (obj.data != null && obj.data.Length != 0)
        {
            if (spawnedData == null)
            {
                Debug.LogError("Spawned prefab not have SpawnedData script: " + go.name);
                return(null);
            }

            spawnedData.spawnedData = obj.data;
        }
        if (spawnedData != null)
        {
            spawnedData.roomObject = obj;
        }

        if (go.GetComponent <TypedObject>() != null)
        {
            TypedObject.Type type = go.GetComponent <TypedObject>().Types[obj.type];
            go.GetComponent <TypedObject>().TypeIndex = obj.type;
            go.transform.localScale = new Vector3(type.Size.x, type.Size.y, go.transform.localScale.z);
            for (int i = 0; i < go.transform.childCount; i++)
            {
                go.transform.GetChild(i).position = go.transform.position + go.transform.GetChild(i).localPosition;
            }

            Mesh mesh = MonoBehaviour.Instantiate(GameManager.singleton.OnePlane);
            mesh.SetUVs(0, new List <Vector2>()
            {
                new Vector2(type.MinUV.x, type.MinUV.y),
                new Vector2(type.MaxUV.x, type.MinUV.y),
                new Vector2(type.MaxUV.x, type.MaxUV.y),
                new Vector2(type.MinUV.x, type.MaxUV.y)
            });
            go.GetComponent <MeshFilter>().mesh = mesh;
        }

        MeshFilter filter = go.GetComponent <MeshFilter>();

        if (filter != null && filter.mesh != null)
        {
            Mesh mesh = filter.mesh;
            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
            mesh.RecalculateTangents();
        }

        if (obj.mirrorX)
        {
            Vector3[] a = go.GetComponent <MeshFilter>().mesh.vertices;
            a = null;
        }

        go.transform.localScale = new Vector3(go.transform.localScale.x * (obj.mirrorX ? -1 : 1), go.transform.localScale.y * (obj.mirrorY ? -1 : 1), go.transform.localScale.z);
        if (filter != null && filter.mesh != null)
        {
            try {
                go.transform.position += new Vector3(
                    obj.mirrorX
                                                ? (filter.mesh.vertices[1].x -
                                                   filter.mesh.vertices[0].x) * -go.transform.localScale.x
                                                : 0,
                    obj.mirrorY
                                                ? (filter.mesh.vertices[2].y -
                                                   filter.mesh.vertices[0].y) * -go.transform.localScale.y
                                                : 0, 0); // mark
            }
            catch (IndexOutOfRangeException e) {
                Debug.Log("OutOfRange");
            }
        }

        int childCount = go.transform.childCount;

        if (go.GetComponent <SimpleObject>().NotMirrorChildrensOnSpawn)
        {
            for (int i = 0; i < childCount; i++)
            {
                go.transform.GetChild(i).localScale = new Vector3(go.transform.GetChild(i).localScale.x *(obj.mirrorX ? -1 : 1), go.transform.GetChild(i).localScale.y *(obj.mirrorY ? -1 : 1), go.transform.GetChild(i).localScale.z);
            }
        }

        return(go);
    }