반응형

3.x 코딩을 작업하다가 4.x로 작업하다보면 경고 메세지가 뜨는 부분이 있다. 

문서를 자세히 살펴봤으면 미리 수정할 수 있는 부분이지만, 경고메세지를 먼저 보게되어

해당 관련 이슈를 찾아 보니 있어 남겨 놓는다. 

 warning CS0618: `UnityEngine.GameObject.SetActiveRecursively(bool)' is obsolete: `gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.'

바로 위의 경고 메세지가 나왔을때 대처 할 수 있는 내용은 http://bit.ly/YBUvaf 페이지를 통해서 확인후 수정이 가능하다. 

기존에 사용하던 GameObject.SetActiveRecursively() 함수는 더이상 사용되지 않는다. 

4.x 버전에서는 해당 오브젝트 하위의 노드까지 알아서 정리하게 된다.

고로, GameObject.SetActive() 함수로 대체 되어야 한다. 

 

반응형
반응형

using UnityEngine;
using System;
using System.Xml;
using System.IO;
 
[ExecuteInEditMode]
[Serializable]
public static class RyXmlTools
{
    public static XmlDocument loadXml(TextAsset xmlFile)
    {
        MemoryStream assetStream = new MemoryStream(xmlFile.bytes);
        XmlReader reader = XmlReader.Create(assetStream);
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(reader);
        }
        catch (Exception ex)
        {
            Debug.Log("Error loading "+ xmlFile.name + ":\n" + ex);
        }
        finally
        {
            Debug.Log(xmlFile.name + " loaded");
        }
 
        return xmlDoc;
    }
 
    public static void writeXml(string filepath, XmlDocument xmlDoc)
    {
        if (File.Exists(filepath))
        {
            using (TextWriter sw = new StreamWriter(filepath, false, System.Text.Encoding.UTF8)) //Set encoding
            {
                xmlDoc.Save(sw);
            }
        }
    }
}

사용 방법 :

읽어오기 방법

TextAsset m_XmlTextAsset = (TextAsset)Resources.Load("FileNameWhitoutFileExtention", typeof(TextAsset));
XmlDocument m_xmlDoc = RyXmlTools.loadXml(m_XmlTextAsset);

저장하기

private static string m_XmlTextAssetPath = Application.dataPath.ToString() + "/resources/FileName.xml";
RyXmlTools.writeXml(m_XmlTextAssetPath , m_xmlDoc);


아래 코드는 Ressources.Load() 함수를 이용한 로드 방법이다.

TextAsset textAsset = (TextAsset) Resources.Load("MyXMLFile");  
XmlDocument xmldoc = new XmlDocument ();
xmldoc.LoadXml ( textAsset.text );

참고 사이트 : http://answers.unity3d.com/questions/59466/loading-xml-file-from-resources-file-after-build.html


반응형
반응형

using UnityEngine; 
using System.Collections.Generic; 
using System.Xml; 
using System.Xml.Serialization; 
using System.IO; 
using System.Text; 

public class GameXML : MonoBehaviour 
{ 
 string _FileLocation,_FileName; 
 StreamWriter _writer;
 TextReader _reader;
 
 void Start () { 
  // Where we want to save and load to and from 
  _FileLocation=Application.dataPath; 
  _FileName="GameTurnData.xml"; 
 } 
 
 public void OpenSaveFileForWrite()
 {
  FileInfo t = new FileInfo(_FileLocation+"\\"+ _FileName); 
  if(!t.Exists) 
  { 
   _writer = t.CreateText(); 
  } 
  else 
  { 
   t.Delete(); 
   _writer = t.CreateText(); 
  } 
 }
 
 public void OpenSaveFileForRead()
 {
  FileInfo t = new FileInfo(_FileLocation+"\\"+ _FileName); 
  if(t.Exists) 
  { 
   _reader = t.OpenText(); 
  } 
  else 
  { 
   Debug.Log("SaveFile NotFound");
  } 
 }

 public void CloseSaveFile()
 {
  _writer.Close(); 
 }
 
 public void WriteGameDataAndTurnSequence(GameSaveGame SGDat )
 {
  string _data = SerializeGame(SGDat); 
  Debug.Log("Game Sequence looks like:" + _data); 

  _writer.Write(_data); 
 }
 
 public GameSaveGame ReadSaveGame()
 {
  OpenSaveFileForRead();
  return DeserializeGame(_reader);
 }
 
 

string SerializeGame( GameSaveGame pArr)
{
   string XmlizedString = null; 
   MemoryStream memoryStream = new MemoryStream(); 
   XmlSerializer xs = new XmlSerializer(typeof(GameSaveGame)); 
   XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); 
    
   xs.Serialize(xmlTextWriter, pArr); 
    
   memoryStream = (MemoryStream)xmlTextWriter.BaseStream; 
   XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray()); 
   return XmlizedString; 
} 
   
 // Here we deserialize it back into its original form 
GameSaveGame DeserializeGame(TextReader file) 
 { 
   XmlSerializer xdsg = new XmlSerializer(typeof(GameSaveGame)); 
   GameSaveGame newGame;
   newGame = (GameSaveGame)xdsg.Deserialize(_reader); 
   _reader.Close();
    return newGame;
   
} 
 /* The following metods came from the referenced URL */ 
   string UTF8ByteArrayToString(byte[] characters) 
   {      
      UTF8Encoding encoding = new UTF8Encoding(); 
      string constructedString = encoding.GetString(characters); 
      return (constructedString); 
   } 
    
   byte[] StringToUTF8ByteArray(string pXmlString) 
   { 
      UTF8Encoding encoding = new UTF8Encoding(); 
      byte[] byteArray = encoding.GetBytes(pXmlString); 
      return byteArray; 
   } 
}
// this simple class holds all the "settings" data relevent to a game
public class GameData 
{ 
  public GameData(){}
  public int DimensionsOfPlay;
  public int SpacesPerAxis;
  public bool Player1IsRobot;
  public bool Player2IsRobot;
  public int PlayerTurn; // ID of the player who's turn it was/willbe when saved/loaded 
  public Quaternion GFProtate; // rotaton of the game grid
  public Quaternion VRrotate; // rotaton of the game grid
}

// this class holds all the data that represents a single turn in the game
public class TurnData 
{ 
 public TurnData (){ Unconditional = false; SequenceNum = 0;}
 public TurnData ( int x, int y, int z, int PID, bool cond, int seq)
 {
  X = x; 
  Y = y; 
  Z = z; 
  PlayerID = PID;
  Unconditional = cond;
  SequenceNum = seq;
 }

 public int X; 
 public int Y; 
 public int Z; 
 public int PlayerID;
 public bool Unconditional; // if this is true, the objec is just placed without executing the move rule, this is used for the game starting condition
 public int SequenceNum;
} 

public class GameSaveGame
{
 public GameData GameSettings;
 public GameSequence Turns;
 
 public GameSaveGame()
 { 
  GameSettings = new GameData();
  Turns = new GameSequence();
 }
  
 public GameSaveGame(GameData pData, GameSequence pGS)
 { 
  GameSettings = pData;
  Turns = pGS;
 }
}

public class GameSequence
{
 public List TurnList = new List();
 private int Sequence = 0; 
 
 public GameSequence () { }
 
 public void AddTurn(TurnData aTurn)
 {
   TurnList.Add(aTurn);
 }
 public void AddTurn( int x, int y, int z, int PlayerID, bool cond)
 {
  Sequence++;
  TurnData dat = new TurnData(x,y,z,PlayerID,cond,Sequence);
  AddTurn(dat);
 }
 public void AddTurn( int x, int y, int z, int PlayerID)
 {
  Sequence++;
  TurnData dat = new TurnData(x,y,z,PlayerID,false,Sequence);
  AddTurn(dat);
 }
 public void Reset()
 {
  TurnList.Clear();
  TurnList.TrimExcess();
  Sequence = 0;
 }
 public int numOfTurns()
 {
   return (int)TurnList.Count;
 }
 public TurnData GetTurnNum(int turnNum)
 {
   return (TurnData)TurnList[turnNum];
 }
 
}

출처 : http://blog.naver.com/hurinmon/70140238120

반응형

+ Recent posts