Example #1
0
	/// <summary>
	/// Play the clip with this name.
	/// </summary>
	/// <param name="clipName">The clip name. Same as the name of the clip material.</param>
	public void PlayClip (string clipName)
	{
		SpriteClip clip = GetClip(clipName);

		if (clip != null)
		{
			if ((clip != activeClip) || RestartSameClip || Speed == 0f)
			{
				activeClip = clip;

				// Assigning to renderer.material from clip.Material instantiates the material.
				// We save the instance it back to clip.Material so we don't keep instantiating.
				renderer.material = clip.Material;
				clip.Material = renderer.material;

				frame = (PlayFromSecondFrame && clip.Frames > 1) ? 1 : 0;
				frameBuffer = 0f;
			}

			Speed = clip.Speed;
		}
	}
Example #2
0
    private void Update()
    {
        _accum += Time.deltaTime;
        var step = 1f / (float)FPS;

        while (_accum > step)
        {
            _accum -= step;
            _currentFrame++;
        }

        if (_currentFrame >= CurrentClip.Frames.Count)
        {
            if (!NextClip)
            {
                NextClip = CurrentClip;
            }
            CurrentClip   = NextClip;
            _currentFrame = 0;
        }

        Material.SetTexture(VariableName, CurrentClip.Frames[_currentFrame]);
    }
Example #3
0
	static void CreateSprite ()
	{
		GameObject go = new GameObject("Sprite");

		Undo.RegisterCreatedObjectUndo(go, "Create Sprite");

		// Adding a sprite component first will automatically add the other required components.
		Sprite sprite = go.AddComponent<Sprite>();

		// Use the awesome unit square mesh.
		go.GetComponent<MeshFilter>().sharedMesh =
			(Mesh)AssetDatabase.LoadAssetAtPath("Assets/Tuizi/Meshes/unit_square.asset", typeof(Mesh));

		SpriteClip clip = new SpriteClip();
		sprite.AddClip(clip);

		// Set the material for the sprite to a default, so it's not the nasty magenta.
		clip.Material = go.renderer.sharedMaterial =
			(Material)AssetDatabase.LoadAssetAtPath(
			"Assets/Tuizi/Materials/default_sprite_material.mat", typeof(Material));

		// Highlight the newly created sprite.
		Selection.activeGameObject = go;
	}
Example #4
0
        public bool Load(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);

            byte[] magic = br.ReadBytes(2);

            if (magic[0] != (byte)'A' || magic[1] != (byte)'C')
            {
                return(false);
            }

            _version = br.ReadInt16();

            if (_version != 0x200 && _version != 0x201 &&
                _version != 0x202 && _version != 0x203 &&
                _version != 0x204 && _version != 0x205)
            {
                return(false);
            }

            ushort actCount = br.ReadUInt16();

            br.ReadBytes(10);

            if (actCount > 0)
            {
                for (int i = 0; i < actCount; i++)
                {
                    Act act = new Act();

                    uint motionCount = br.ReadUInt32();
                    if (motionCount > 0)
                    {
                        act.Motions = new List <Motion>();

                        for (int n = 0; n < motionCount; n++)
                        {
                            Motion mo = new Motion();

                            mo.Range1.X      = br.ReadInt32();
                            mo.Range1.Y      = br.ReadInt32();
                            mo.Range1.Width  = br.ReadInt32();
                            mo.Range1.Height = br.ReadInt32();

                            mo.Range2.X      = br.ReadInt32();
                            mo.Range2.Y      = br.ReadInt32();
                            mo.Range2.Width  = br.ReadInt32();
                            mo.Range2.Height = br.ReadInt32();

                            uint clipCount = br.ReadUInt32();
                            if (clipCount > 0)
                            {
                                mo.Clips = new List <SpriteClip>();

                                for (int j = 0; j < clipCount; j++)
                                {
                                    SpriteClip sc = new SpriteClip();

                                    sc.Position.X = br.ReadInt32();
                                    sc.Position.Y = br.ReadInt32();

                                    sc.SpriteNumber = br.ReadInt32();
                                    sc.Mirror       = br.ReadInt32() == 1;
                                    sc.Mask         = new Color(255, 255, 255, 255);
                                    sc.Zoom         = new Vector2(1.0f);
                                    sc.Angle        = 0;
                                    sc.SpriteType   = 0;
                                    sc.Size         = new Point(0, 0);

                                    if (_version >= 0x200)
                                    {
                                        byte r = br.ReadByte();
                                        byte g = br.ReadByte();
                                        byte b = br.ReadByte();
                                        byte a = br.ReadByte();

                                        sc.Mask = new Color(r, g, b, a);

                                        if (_version >= 0x204)
                                        {
                                            sc.Zoom.X = br.ReadSingle();
                                            sc.Zoom.Y = br.ReadSingle();
                                        }
                                        else
                                        {
                                            sc.Zoom = new Vector2(br.ReadSingle());
                                        }

                                        sc.Angle      = br.ReadInt32();
                                        sc.SpriteType = br.ReadInt32();

                                        if (_version >= 0x205)
                                        {
                                            sc.Size.X = br.ReadInt32();
                                            sc.Size.Y = br.ReadInt32();
                                        }
                                    }

                                    mo.Clips.Add(sc);
                                }
                            }

                            mo.EventID = -1;
                            if (_version >= 0x200)
                            {
                                mo.EventID = br.ReadInt32();

                                if (_version == 0x200)
                                {
                                    mo.EventID = -1;
                                }
                            }

                            if (_version >= 0x203)
                            {
                                uint attachCount = br.ReadUInt32();

                                if (attachCount > 0)
                                {
                                    mo.AttachPoints = new List <AttachPoint>();

                                    for (int j = 0; j < attachCount; j++)
                                    {
                                        AttachPoint ap = new AttachPoint();

                                        br.ReadInt32();

                                        ap.Position.X = br.ReadInt32();
                                        ap.Position.Y = br.ReadInt32();
                                        ap.Attribute  = br.ReadInt32();

                                        mo.AttachPoints.Add(ap);
                                    }
                                }
                            }

                            act.Motions.Add(mo);
                        }
                    }

                    _actions.Add(act);
                }
            }

            if (_version >= 0x201)
            {
                uint eventCount = br.ReadUInt32();

                if (eventCount > 0)
                {
                    for (int i = 0; i < eventCount; i++)
                    {
                        _events.Add(br.ReadCString(40));
                    }
                }
            }

            if (_version >= 0x202)
            {
                if (_events.Count > 0)
                {
                    for (int i = 0; i < _events.Count; i++)
                    {
                        _delays.Add(br.ReadSingle());
                    }
                }
            }

            return(true);
        }
Example #5
0
 /// <summary>
 /// Add a clip to the list. No effect if clip is null.
 /// </summary>
 /// <param name="clip">The clip to add.</param>
 public void AddClip(SpriteClip clip)
 {
     if (clip != null)
         this.clips.Add(clip);
 }
Example #6
0
 /// <summary>
 /// Remove a clip from the list. No effect if clip is null.
 /// </summary>
 /// <param name="clip">The clip to remove.</param>
 public void RemoveClip(SpriteClip clip)
 {
     this.clips.Remove(clip);
 }
Example #7
0
 /// <summary>
 /// Insert a clip to the list at a certain point. No effect if clip is null.
 /// </summary>
 /// <param name="index">The index at which to insert the clip.</param>
 /// <param name="clip">The clip to insert.</param>
 public void InsertClip(int index, SpriteClip clip)
 {
     if (index <= this.clips.Count)
         this.clips.Insert(index, clip);
 }