コード例 #1
0
    public static void SaveLand()
    {
        GameObject landObj    = GameObject.Find("Land");
        BWLand     bwland     = landObj.GetComponent <BWLand>();
        int        landWidth  = bwland.Width;
        int        landHeight = bwland.Height;
        int        i          = 0;

        GameObject[] gos = GameObject.FindGameObjectsWithTag("Land");

        for (int x = 0; x < landHeight; x++)
        {
            for (int y = 0; y < landWidth; y++)
            {
                GameObject go = gos[i];
                go.name = "Land" + x + "," + y;

                LandOS _landOS = ScriptableObject.CreateInstance <LandOS>();
                _landOS.X        = x;
                _landOS.Y        = y;
                _landOS.CellSize = bwland.CellSize;
                _landOS.name     = "landsX" + x + "," + y + ".asset";

                LoadWorldAsset(ref _landOS, go);

                AssetDatabase.CreateAsset(_landOS, "Assets/Lands/" + _landOS.name);
                i++;
            }
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
        }
    }
コード例 #2
0
 private static void LoadWorldAsset(ref LandOS los, GameObject go)
 {
     Transform[] trans = go.GetComponentsInChildren <Transform>();
     for (int n = 0; n < trans.Length; n++)
     {
         Transform t = trans[n];
         if (t.gameObject.tag.Equals("Tree"))
         {
             los.TreeList.Add(t.gameObject);
         }
     }
 }