private static XmlNode WriteAtlasList(OCAtlas[] list, XmlDocument document) {
		XmlNode node = document.CreateElement("OCAtlasList");
		foreach(OCAtlas atlas in list) {
			XmlNode childNode = WriteAtlas(atlas, document);
			node.AppendChild(childNode);
		}
		return node;
	}
示例#2
0
        private static OCAtlas[] ReadAtlasList(XmlNode blockSetNode)
        {
            XmlNode        atlasListNode = FindNodeByName(blockSetNode, "OCAtlasList");
            List <OCAtlas> list          = new List <OCAtlas>();

            foreach (XmlNode node in atlasListNode.ChildNodes)
            {
                OCAtlas atlas = ReadAtlas(node);
                list.Add(atlas);
            }
            return(list.ToArray());
        }
	private static XmlNode WriteAtlas(OCAtlas atlas, XmlDocument document) {
		XmlNode node = document.CreateElement("OCAtlas");
		FieldInfo[] fields = GetFields(atlas.GetType());
		foreach(FieldInfo field in fields) {
			if(field.FieldType.IsSubclassOf( typeof(UnityEngine.Object) )) {
				XmlNode childNode = WriteAssetField(field, atlas, document);
				node.AppendChild(childNode);
			} else {
				XmlNode childNode = WriteField(field, atlas, document);
				node.AppendChild(childNode);
			}
		}
		return node;
	}
示例#4
0
        private static OCAtlas ReadAtlas(XmlNode node)
        {
            OCAtlas atlas = new OCAtlas();

            foreach (XmlNode fieldNode in node)
            {
                FieldInfo field = GetField(atlas.GetType(), fieldNode.Name);
                if (field.FieldType.IsSubclassOf(typeof(UnityEngine.Object)))
                {
                    ReadResourceField(fieldNode, atlas);
                }
                else
                {
                    ReadField(fieldNode, atlas);
                }
            }
            return(atlas);
        }
	private static void DrawAtlasEditor(OCAtlas atlas) {
		GUILayout.BeginVertical(GUI.skin.box);
			Material material = (Material) EditorGUILayout.ObjectField("Material", atlas.Material, typeof(Material), true);
			atlas.Material = material;
				
			int w = EditorGUILayout.IntField("Width", atlas.Width);
			if(w < 1) w = 1; 
			atlas.Width = w;
				
			int h = EditorGUILayout.IntField("Height", atlas.Height);
			if(h < 1) h = 1; 
			atlas.Height = h;
				
			bool alpha = EditorGUILayout.Toggle("Alpha", atlas.IsAlpha);
			atlas.IsAlpha = alpha;
		GUILayout.EndVertical();
	}
	private static void DrawFaceEditor(ref int face, OCAtlas atlas, ref Matrix4x4 matrix) {
		GUILayout.BeginVertical(GUI.skin.box);
			Texture texture = atlas.Texture;
			Rect rect = GUILayoutUtility.GetAspectRect((float)texture.width/texture.height);
		GUILayout.EndVertical();
		
		Matrix4x4 rectMatrix = Matrix4x4.Scale( new Vector3(rect.width, rect.height, 0) ) * matrix;
		Matrix4x4 invRectMatrix = matrix.inverse * Matrix4x4.Scale( new Vector3(1/rect.width, 1/rect.height, 0) );
		Matrix4x4 invertY = Matrix4x4.TRS(new Vector2(0, 1), Quaternion.identity, new Vector2(1, -1));
		
		bool mouseInRect = rect.Contains(Event.current.mousePosition);
		
		GUI.BeginGroup(rect);
		{
			Vector2 mouse = invRectMatrix.MultiplyPoint(Event.current.mousePosition); // local mouse [0..1]
			
			if(Event.current.type == EventType.Repaint) {
				Rect texturePosition = Mul(new Rect(0,0,1,1), rectMatrix);
				Rect faceRet = atlas.ToRect(face);
				faceRet = Mul(faceRet, rectMatrix*invertY);
				GUI.DrawTexture(texturePosition, texture);
				EditorGUIUtils.DrawRect( faceRet, Color.green );
			}
			
			if(Event.current.type == EventType.MouseDown && Event.current.button == 0 && mouseInRect) {
				Vector2 invMouse = invertY.MultiplyPoint( mouse );
				if(invMouse.x >= 0 && invMouse.x <= 1 && invMouse.y >= 0 && invMouse.y <= 1) {
					int posX = Mathf.FloorToInt( invMouse.x*atlas.Width );
					int posY = Mathf.FloorToInt( invMouse.y*atlas.Height );
					face = posY*atlas.Width + posX;
				
					GUI.changed = true;
					Event.current.Use();
				}
			}
			
			if(Event.current.type == EventType.MouseDrag && Event.current.button == 1 && mouseInRect) {
				Vector3 delta = Event.current.delta;
				delta.x /= rect.width;
				delta.y /= rect.height;
				
				Matrix4x4 offsetMatrix = Matrix4x4.TRS(delta, Quaternion.identity, Vector3.one);
				matrix = offsetMatrix*matrix;
			
				GUI.changed = true;
				Event.current.Use();
			}
			
			if(Event.current.type == EventType.ScrollWheel && mouseInRect) {
				float s = 0.95f;
				if(Event.current.delta.y < 0) s = 1.0f/s;
				
				Matrix4x4 offsetMatrix = Matrix4x4.TRS(mouse, Quaternion.identity, Vector3.one);
				matrix *= offsetMatrix;
				
				Matrix4x4 scaleMatrix = Matrix4x4.Scale(Vector3.one*s);
				matrix *= scaleMatrix;
				
				offsetMatrix = Matrix4x4.TRS(-mouse, Quaternion.identity, Vector3.one);
				matrix *= offsetMatrix;
			
				GUI.changed = true;
				Event.current.Use();
			}
		}
		GUI.EndGroup();
	}
	private static OCAtlas ReadAtlas(XmlNode node) {
		OCAtlas atlas = new OCAtlas();
		foreach(XmlNode fieldNode in node) {
			FieldInfo field = GetField(atlas.GetType(), fieldNode.Name);
			if(field.FieldType.IsSubclassOf(typeof(UnityEngine.Object))) {
				ReadResourceField(fieldNode, atlas);
			} else {
				ReadField(fieldNode, atlas);
			}
		}
		return atlas;
	}