xml 파일, 데이터 저장 및 추출, PlayerPrefs
                                            
 6996 단어  unity3d
                    
PlayerPrefs 는 유 니 티 가 자체 적 으로 가지 고 있 는 데이터 구조 로 유 니 티 Engine 네 임 스페이스 에서 정수, 부동 소수점, 문자열 3 가지 유형의 데 이 터 를 조작 할 수 있 습 니 다.
PlayerPrefs 키 조합 규칙 사용
PlayerPrefs.SetInt(“Number”, num);//  ,       ,       int num = PlayerPrefs.GetInt(“Number”);//    float PI = 3.14f; 
PlayerPrefs.SetFloat(“PI”, PI);
PI = PlayerPrefs.GetFloat(“PI”);   String str = “neworigin”;
PlayerPrefs.SetString(“Str”, str); 
Str5 =PlayerPrefs.GetFloat(“Str”);   xml 파일 에 대한 추가 삭제 및 검사 작업 핵심 코드:
using UnityEngine;
using System.Collections;
using System.Xml;
public class heng : MonoBehaviour {
    public string xmlFileName = "/test.xml";//   
    public string xmlFilePath = string.Empty;//  
    public XmlNode _root;// 
    public XmlNode node;//  
    public XmlNode child node;//   
    public XmlDocument _doc;//     
    void Awake(){   
        xmlFilePath = Application.streamingAssetsPath + xmlFileName;//
    }
    void Start () {
        _doc = new XmlDocument ();
        _doc.Load (xmlFilePath);//          
        _root = _doc.SelectSingleNode ("plist");//   
        XmlElement element = _doc.CreateElement ("mystring");//  
        element.InnerText = "dsfsdfgd";
        //add ("key",element);//  
        //remove("array","string3");//  
        //find ("string5");//  
        replace ("array","string5",element);//  
    }
    // Update is called once per frame
    void Update () {
    }
    //    
    void load(XmlNode _root,string parentelement,string childelement = ""){
        foreach(XmlNode element in _root){
            if(element.Name.Equals(parentelement)){
                node = element;
            }
            if(element.Name.Equals(childelement)){
                childnode = element;
            }
            load(element,parentelement,childelement);
        }
    }
    //  
    void add(string parentelement,XmlElement newelement){
        load (_root,parentelement);
        if (node != null) {
            Debug.Log("SDSDA");
            node.AppendChild (newelement);
            _doc.Save(xmlFilePath);
        }
    }
    //  
    void remove(string parentname,string childname){
        load (_root,parentname,childname);
        if(node!=null&&childnode!=null){
            Debug.Log("remove");
            node.RemoveChild(childnode);
            _doc.Save(xmlFilePath);
        }
    }
    //  
    void find(string nodename){
        load (_root,nodename);
        if (node!=null) {
            Debug.Log("find");
            Debug.Log(node.InnerText);
        }
    }
    //  
    void replace(string parentname,string oldchildname,XmlElement newchilename){
        load (_root,parentname,oldchildname);
        if(node!=null&&childnode!=null){
            Debug.Log("replace");
            node.ReplaceChild(newchilename,childnode);
            _doc.Save(xmlFilePath);
        }
    }
}

  foreach (XmlElement childNode in _root) {
        if(childNode.Name.Equals("dict")){
            foreach(XmlElement grandSon in childNode){
                //grandSon.AppendChild(element);
                if(grandSon.Name.Equals("array"))
                    //grandSon.AppendChild(element);//add
                //grandSon.RemoveChild(grandSon,grandSon.LastChild);
                //grandSon.RemoveChild(element,grandSon.LastChild);
                {
                    foreach(XmlElement maternal in grandSon){
                        Debug.Log(maternal.InnerText);
                    }
                }
            }
        }
    }
  “`
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Unity용 VLC 소개 - Android 에디션숙련된 Unity 개발자는 유명한 Big Buck Bunny 비디오를 재생하는 VLC 플러그인을 보여주기 위해 편집된 유명한 Unity 장면 을 인식할 것입니다. 이 Unity 플러그인을 사용하면 Unity 기반 A...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.