public UnityBoneDisplay (TextureAtlas textureAtlas, string fullName, float pivotX, float pivotY) { //TODO: build vetex and mesh PivotX = pivotX; PivotY = pivotY; _uvs = new float[8]; _verticesOrigin = new float[8]; _vertices = new float[8]; TextureData textureData = textureAtlas.AtlasData.GetTextureData (fullName); _uvs [0] = textureData.X / (float)textureAtlas.Texture.width; _uvs [1] = 1-textureData.Y / (float)textureAtlas.Texture.height; _uvs [2] = (textureData.X +textureData.Width) / (float)textureAtlas.Texture.width; _uvs [3] = 1-textureData.Y / (float)textureAtlas.Texture.height; _uvs [4] = (textureData.X +textureData.Width) / (float)textureAtlas.Texture.width; _uvs [5] = 1-(textureData.Y + textureData.Height) / (float)textureAtlas.Texture.height; _uvs [6] = textureData.X / (float)textureAtlas.Texture.width; _uvs [7] = 1-(textureData.Y + textureData.Height) / (float)textureAtlas.Texture.height; _vertices[0] = _verticesOrigin [0] = -pivotX; _vertices[1] = _verticesOrigin [1] = -pivotY; _vertices[2] = _verticesOrigin [2] = textureData.Width-pivotX; _vertices[3] = _verticesOrigin [3] = -pivotY; _vertices[4] = _verticesOrigin [4] = textureData.Width-pivotX ; _vertices[5] = _verticesOrigin [5] = textureData.Height-pivotY; _vertices[6] = _verticesOrigin [6] = -pivotX; _vertices[7] = _verticesOrigin [7] = textureData.Height-pivotY; //Debug.Log("added"); }
/** @private */ override protected System.Object generateDisplay(TextureAtlas textureAtlas, string fullName, float pivotX, float pivotY) { UnityBoneDisplay display = new UnityBoneDisplay (textureAtlas, fullName, pivotX, pivotY); /* Sprite subTexture = _textures[Array.IndexOf(_names, fullName)]; if (subTexture!=null) { //Logger.Log("generate display " + fullName); GameObject imageContainer = new GameObject(); //GameObject image = new GameObject(); SpriteRenderer spriteRenderer = imageContainer.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer; spriteRenderer.sprite = subTexture; //image.transform.parent = imageContainer.transform; //image.transform.localPosition = new Vector3( -pivotX/100 , -pivotY/100, 1); return imageContainer; } return null; */ return display; }
public UnityArmatureDisplay(TextureAtlas atlas) { _display = new GameObject (); filter = _display.AddComponent("MeshFilter") as MeshFilter; _display.AddComponent("MeshRenderer"); mesh = new Mesh(); filter.sharedMesh = mesh; _display.renderer.sharedMaterial = atlas.Material; }
void Start() { //read and parse skeleton josn into SkeletonData TextAsset jsonReader = (TextAsset)Resources.Load("skeleton.json", typeof(TextAsset)); TextReader reader = new StringReader (jsonReader.text); Dictionary<String, System.Object> skeletonRawData = Json.Deserialize (reader) as Dictionary<String, System.Object>; SkeletonData skeletonData = ObjectDataParser.ParseSkeletonData (skeletonRawData); //read and parse texture atlas josn into TextureAtlas Texture _textures = Resources.Load<Texture>("texture"); jsonReader = (TextAsset)Resources.Load("texture.json", typeof(TextAsset)); reader = new StringReader (jsonReader.text); Dictionary<String, System.Object> atlasRawData = Json.Deserialize (reader) as Dictionary<String, System.Object>; AtlasData atlasData = AtlasDataParser.ParseAtlasData (atlasRawData); TextureAtlas textureAtlas = new TextureAtlas (_textures, atlasData); //use the above data to make factory UnityFactory factory = new UnityFactory (); factory.AddSkeletonData (skeletonData, skeletonData.Name); factory.AddTextureAtlas (textureAtlas); //add 20 centaur into scene at some random positions. System.Random random = new System.Random(); for (int i=0; i<2; i++) { for (int j=0; j<5; j++) { Armature armature = factory.BuildArmature ("centaur/charactor", null, "charactor_all"); armature.AdvanceTime (0f); float r0 = (float)random.NextDouble() + 0.5f; float r1 = 0;//(float)random.NextDouble(); float r2 = (float)random.NextDouble(); ((armature.Display as UnityArmatureDisplay).Display as GameObject).transform.position = new Vector3((float)j+r0*20f, 1, r2*15f); WorldClock.Clock.Add (armature); armature.Animation.GotoAndPlay ("run", -1, -1, 0); } } //add 20 bird into scene at some random positions. for (int i=0; i<2; i++) { for (int j=0; j<5; j++) { Armature armature = factory.BuildArmature ("bird/charactor", null, "charactor_all"); armature.AdvanceTime (0f); float r0 = (float)random.NextDouble() + 0.5f; float r1 = (float)random.NextDouble() + 1; float r2 = (float)random.NextDouble(); ((armature.Display as UnityArmatureDisplay).Display as GameObject).transform.position = new Vector3((float)j+r0*20f, (float)i*3f+r1*5f, r2*15f); WorldClock.Clock.Add (armature); armature.Animation.GotoAndPlay ("fly", -1, -1, 0); } } }
/** * Add a textureAtlas to this BaseFactory instance. * @example * <listing> * factory.addTextureAtlas(textureatlas, 'dragon'); * </listing> * @param A textureAtlas to add to this BaseFactory instance. * @param (optional) A name for this TextureAtlas. */ public void AddTextureAtlas(TextureAtlas textureAtlas, string name = null) { if(_textureAtlasDic == null) { _textureAtlasDic = new Dictionary<string, TextureAtlas>(); } if(textureAtlas==null) { throw new ArgumentException(); } if(name==null && textureAtlas is TextureAtlas) { name = textureAtlas.Name; } if(name==null) { throw new ArgumentException("Unnamed data!"); } _textureAtlasDic[name] = textureAtlas; }
/** * Generates a DisplayObject * @param textureAtlas The TextureAtlas. * @param fullName A qualified name. * @param pivotX A pivot x based value. * @param pivotY A pivot y based value. * @return */ protected virtual Object generateDisplay(TextureAtlas textureAtlas, string fullName, float pivotX, float pivotY) { return null; }