private static Dictionary <string, AnimationDef> ReadAnimation(XmlDocument doc) { XmlNodeList animations = doc.SelectNodes("//animation"); Dictionary <string, AnimationDef> animationDefinitions = new Dictionary <string, AnimationDef>(); foreach (XmlNode n in animations) { AnimationDef a = new AnimationDef() { Name = n.Attributes["name"].Value, Sequence = n.Attributes["sequence"].Value.Split(','), }; if (n.Attributes["randomSeqStart"] == null) { a.RandomSeqStart = false; } else { a.RandomSeqStart = n.Attributes["randomSeqStart"].Value.Equals("true", StringComparison.InvariantCultureIgnoreCase); } XmlNodeList frames = n.SelectNodes("frame"); foreach (XmlNode f in frames) { FrameDef fd = new FrameDef() { X = int.Parse(f.Attributes["x"].Value), Y = int.Parse(f.Attributes["y"].Value), Image = f.Attributes["img"].Value, Width = int.Parse(f.Attributes["width"].Value), Height = int.Parse(f.Attributes["height"].Value), Delay = int.Parse(f.Attributes["delay"].Value), }; if (f.Attributes["basex"] == null) { fd.BaseX = 0; } else { fd.BaseX = int.Parse(f.Attributes["basex"].Value); } if (f.Attributes["basey"] == null) { fd.BaseY = 0; } else { fd.BaseY = int.Parse(f.Attributes["basey"].Value); } a.Frames.Add(fd); } animationDefinitions.Add(a.Name, a); } return(animationDefinitions); }
internal void _AddFrameDef(ReferencesTableDataFrame frame) { var fd = new FrameDef(); Frames.Add(fd); fd.MasterSaveId = frame.MasterFrame.PersistString; fd.SaveId = frame.PersistString; fd.ReferenceDef = frame.RefDef; }
public void LoadFromXml(XmlElement xml) { foreach (XmlElement fx in xml.SelectNodes("Frame")) { var fd = new FrameDef(); fd.LoadProperties(fx); Frames.Add(fd); } var layx = xml.FindElement("Layout"); if (layx != null) { m_layout = new XmlDocument(); m_layout.AppendChild(m_layout.ImportNode(layx, true)); } }
private FrameDef TweenFrame(FrameDef pre_frameDef, FrameDef post_frameDef, float t) { FrameDef midFrameDef = new FrameDef (); if(post_frameDef==null){ midFrameDef = pre_frameDef; return midFrameDef; } midFrameDef.visible = post_frameDef.visible; if(post_frameDef.visible == false || pre_frameDef.visible == false){ midFrameDef = post_frameDef; }else{ midFrameDef.pos = Vector3.Lerp (pre_frameDef.pos, post_frameDef.pos, t); if (pre_frameDef.matrix!=null && post_frameDef.matrix!=null) { midFrameDef.matrix = new Vector3[2]; midFrameDef.matrix[0] = Vector3.Lerp (pre_frameDef.matrix[0], post_frameDef.matrix[0], t); midFrameDef.matrix[1] = Vector3.Lerp (pre_frameDef.matrix[1], post_frameDef.matrix[1], t); } else { midFrameDef.localScale = Vector3.Lerp (pre_frameDef.localScale, post_frameDef.localScale, t); midFrameDef.rotation = Quaternion.Lerp (pre_frameDef.rotation, post_frameDef.rotation, t); } if (isSupportAlpha) { midFrameDef.alpha = pre_frameDef.alpha; } } if(post_frameDef.visible == false){ post_frameDef = defaultInvisibleFrame; } return midFrameDef; }
private FrameDef LerpFrame(FrameDef orignFrame, FrameDef attachFrame) { return attachFrame; // lerp not work properly, leave it here if (IsNullFrame (attachFrame) || IsNullFrame (orignFrame)) return attachFrame; FrameDef result = new FrameDef (); if (attachFrame.visible == false || orignFrame.visible == false) { result = attachFrame; }else{ result.visible = attachFrame.visible; float Weight = 0.6f; result.pos = Vector3.Lerp (orignFrame.pos, attachFrame.pos, Weight); if(attachFrame.matrix!=null){ result.matrix = new Vector3[2]; if(orignFrame.matrix !=null){ result.matrix[0] = Vector3.Lerp(orignFrame.matrix[0],attachFrame.matrix[0],Weight); result.matrix[1] = Vector3.Lerp(orignFrame.matrix[1],attachFrame.matrix[1],Weight); // Debug.Log("orignFrame: v="+ orignFrame.visible + " m = "+orignFrame.matrix); }else{ result.matrix[0] = attachFrame.matrix[0]; result.matrix[1] = attachFrame.matrix[1]; // Debug.Log("attachFrame: v="+ attachFrame.visible + " m = "+attachFrame.matrix); } }else{ result.localScale = Vector3.Lerp (orignFrame.localScale, attachFrame.localScale, Weight); result.rotation = Quaternion.Lerp (orignFrame.rotation, attachFrame.rotation, Weight); } // Debug.Log("result: v="+ result.visible + " m = "+result.matrix); if (isSupportAlpha) { result.alpha = orignFrame.alpha; } } if(result.visible == false){ result = defaultInvisibleFrame; } return result; }
private bool IsNullFrame(FrameDef frameDef) { return (null == frameDef || false == frameDef.visible); }
private void FillContainerTransform(string key, FrameDef frameDef) { ArrayList ary = partHash [key] as ArrayList; if(ary == null) { Debug.LogError(key); } GameObject container = (GameObject)ary [0]; container.transform.localPosition = frameDef.pos; GameObject entry = (GameObject)ary [1]; if (frameDef.matrix != null) { PackedSprite spt = entry.GetComponent<PackedSprite> (); if(!frameDef.visible) { // if(!spt.IsAnimating()) // { if(!spt.IsHidden()) { spt.StopAnim(); spt.Hide(true); } // } } else { if(spt.IsHidden()) { spt.Hide(false); if(spt.animations.Length > 0 && !spt.IsAnimating()) { spt.PlayAnim(0); } } SpriteMesh_Managed sm_m = (SpriteMesh_Managed)spt.spriteMesh; if (sm_m.origialVertices == null) { sm_m.myVertices = sm_m.myVertices; } Vector3[] vertices = sm_m.origialVertices; if (vertices == null) vertices = sm_m.myVertices; for (int n = 0; n<vertices.Length; n++) { Vector3 oldv = vertices [n]; vertices [n] = new Vector3 ( Vector3.Dot (vertices [n]*fat, frameDef.matrix [0]), Vector3.Dot (vertices [n], frameDef.matrix [1]*fat), frameDef.pos.z); } sm_m.myVertices = vertices; if (isUseManager) { if (spt.drawLayer != -frameDef.pos.z) { spt.SetDrawLayer ((int)(-frameDef.pos.z)); } } if(!spt.IsAnimating()) { container.transform.localScale = Vector3.one; //frameDef.localScale; container.transform.rotation = Quaternion.Euler (Vector3.zero); } } } else { PackedSprite spt = entry.GetComponent<PackedSprite> (); if(spt != null) { spt.Hide(false); } container.transform.localScale = frameDef.localScale; container.transform.rotation = frameDef.rotation; if (isSupportAlpha) { UISprite uisprite = entry.GetComponent<UISprite> (); if (uisprite != null) { uisprite.alpha = frameDef.alpha; } } if (isUseManager) { if (spt.drawLayer != -frameDef.pos.z) { spt.SetDrawLayer ((int)(-frameDef.pos.z)); } } } if (isSupportAlpha) { PackedSprite sp = entry.GetComponent<PackedSprite>(); if (null != sp){ sp.SetColor(new Color(sp.color.r, sp.color.g, sp.color.b, frameDef.alpha)); } } }
private void AdjustFrameLayer(string part, FrameDef frameDef) { ArrayList ary = partHash [part] as ArrayList;//ArrayList of GameObject GameObject entry = (GameObject)ary [1]; if (isUseManager) { PackedSprite spt = entry.GetComponent<PackedSprite> (); if (spt.drawLayer != -frameDef.pos.z) { spt.SetDrawLayer ((int)(-frameDef.pos.z)); } } }
protected void initDefaultFrame() { //string ss = this.gameObject.name+" :"; foreach(ActData ad in actList.Values){ foreach(string k in ad.data.Keys){ if(allPartNames.Contains(k)) continue; allPartNames.Add(k); // ss +=k+","; } } //Debug.LogError(ss); defaultInvisibleFrame = new FrameDef(); defaultInvisibleFrame.visible = false; defaultInvisibleFrame.matrix = new Vector3[2]; defaultInvisibleFrame.matrix[0] = new Vector3(0.001f,0,0); defaultInvisibleFrame.matrix[1] = new Vector3(0,0.001f,0); defaultInvisibleFrame.matrix = new Vector3[2]; defaultInvisibleFrame.pos = Vector3.zero; defaultInvisibleFrame.localScale = new Vector3(0.001f,0.001f,1); defaultInvisibleFrame.rotation = Quaternion.Euler(Vector3.zero); }
public static Hashtable xmllistToHash(XmlNodeList Xmllist) { //bodypart //---|_frameDef Hashtable rootHash = new Hashtable (); int length = Xmllist.Count; for (int i=0; i<length; i++) { XmlNode bodyPardNode = Xmllist [i]; rootHash [bodyPardNode.Name] = new Hashtable (); XmlNodeList dataList = bodyPardNode.ChildNodes; int dataLen = dataList.Count; for (int j=0; j<dataLen; j++) { XmlNode dataNode = dataList [j]; Hashtable frames = rootHash [bodyPardNode.Name] as Hashtable; FrameDef fd = new FrameDef (); //// string posStr = dataNode.Attributes ["pos"].Value; string[] posAry = posStr.Split ('|'); fd.pos = new Vector3 (float.Parse (posAry [0]), float.Parse (posAry [1]), -i); ///// XmlAttribute attr = dataNode.Attributes ["v"]; fd.visible = (attr == null); if (isSupportAlpha) { if (dataNode.Attributes ["a"] == null) { fd.alpha = 1; } else { string attrAlpha = dataNode.Attributes ["a"].Value; fd.alpha = float.Parse (attrAlpha); } } //// /// /// int frame = int.Parse (dataNode.Attributes ["frame"].Value); //Debug.Log(typeNode.Name + "FRAME "+frame +":"+fd); if (dataNode.Attributes ["m"] != null) { string ms = dataNode.Attributes ["m"].Value; fd.matrix = new Vector3[2]; string[] msf = ms.Split ('|'); fd.matrix [0] = new Vector3 (float.Parse (msf [0]), float.Parse (msf [2]), 0); fd.matrix [1] = new Vector3 (float.Parse (msf [1]), float.Parse (msf [3]), 0); // fd.matrix [2] = new Vector3 (float.Parse (msf [4]), float.Parse (msf [5]), 0); } else { string scaleStr = dataNode.Attributes ["scale"].Value; string[] scaleAry = scaleStr.Split ('|'); float rotation = float.Parse (dataNode.Attributes ["rotation"].Value); fd.rotation = Quaternion.Euler (new Vector3 (0, 0, rotation)); if (fd.visible) { fd.localScale = new Vector3 (float.Parse (scaleAry [0]), float.Parse (scaleAry [1]), 0); } else { fd.localScale = new Vector3 (0.001f, 0.001f, 0); } } frames [frame] = fd; } } return rootHash; }