public void Init(CharacterModle.CharacterInfo _info, CharacterModle.Skin _skin) { targetPoint = null; actionStep = 0; info = _info; skin = _skin; Transform root = transform.Find("/Scene/road"); foreach (Transform t in root) { movePoint[t.name] = t.position; } }
public void AddSprite(Sprite[] sprite, CharacterModle.Skin skin) { if (currentSprite == null) { currentSprite = transform.GetComponent <SpriteRenderer>(); if (currentSprite == null) { type = SpriteType.SpriteUI; currentUISprite = transform.GetComponent <Image>(); } } aniSprite = new Sprite[sprite.Length]; aniSprite = sprite; aniskin = skin; }
public ArrayList loadSkinXmlToArray() { //保存路径 string filepath = "Config/Character/skinConfig"; string _result = Resources.Load(filepath).ToString(); ArrayList skinList = new ArrayList(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(_result); XmlNodeList nodeList = xmlDoc.SelectSingleNode("SkinList").ChildNodes; foreach (XmlElement skin in nodeList) { CharacterModle.Skin _skin = new CharacterModle.Skin(); //读取node内属性,把string转化为对应的属性 if (skin.GetAttribute("SkinName") != "") { _skin.SkinName = skin.GetAttribute("SkinName"); } for (int i = 1; i <= skin.Attributes.Count - 1; i++) { string _att = "Action" + i.ToString(); if (skin.HasAttribute(_att)) { string _temp = skin.GetAttribute(_att); int index = _temp.IndexOf(":"); string _name = _temp.Substring(0, index); string[] _value = _temp.Substring(index + 1).Split(','); _skin.ActionList[_name] = new int[2]; _skin.ActionList[_name][0] = int.Parse(_value[0]); _skin.ActionList[_name][1] = int.Parse(_value[1]); } } //添加进itemList中 skinList.Add(_skin); } return(skinList); }
void CreateCharacter(CharacterModle.CharacterInfo c) { int range = Random.Range(0, 2); Vector3 _start = startPiont[range].transform.position; //设定角色出生点 c.startPiont = range; GameObject _char = Instantiate(charPrefab); _char.transform.position = _start; Rigidbody2D rigidbody2d = _char.AddComponent <Rigidbody2D>(); rigidbody2d.isKinematic = true; _char.AddComponent <BoxCollider2D>().isTrigger = true; //Dictionary<string, int[]> _actionList = new Dictionary<string, int[]>(); CharacterModle.Skin skin = new CharacterModle.Skin(); foreach (CharacterModle.Skin s in skinList) { if (s.SkinName == c.Skin) { skin = s; } } AniController.Get(_char).AddSprite(CharacterSprites[c.Skin]); MyCharacterController.Get(_char).Init(c, skin); MyCharacterController.Get(_char).speed = cSpeed; if (c.startPiont == 0) { MyCharacterController.Get(_char).SetTarget("finish2"); } else { MyCharacterController.Get(_char).SetTarget("finish1"); } }