Exemple #1
0
        protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            base.OnSetupCloneTargets(targetObj, setup);
            AnimSpriteRenderer target = targetObj as AnimSpriteRenderer;

            setup.HandleObject(this.customFrameSequence, target.customFrameSequence);
        }
Exemple #2
0
        protected override void OnCopyTo(Component target, Duality.Cloning.CloneProvider provider)
        {
            base.OnCopyTo(target, provider);
            AnimSpriteRenderer t = target as AnimSpriteRenderer;

            t.animDuration        = this.animDuration;
            t.animFirstFrame      = this.animFirstFrame;
            t.animFrameCount      = this.animFrameCount;
            t.animLoopMode        = this.animLoopMode;
            t.animTime            = this.animTime;
            t.customFrameSequence = this.customFrameSequence != null?this.customFrameSequence.ToList() : null;
        }
        public override bool Convert(ConvertOperation convert)
        {
            // If we already have a renderer in the result set, consider generating
            // another one to be not the right course of action.
            if (convert.Result.OfType<ICmpRenderer>().Any())
                return false;

            List<object> results = new List<object>();
            List<Material> availData = convert.Perform<Material>().ToList();

            // Generate objects
            foreach (Material mat in availData)
            {
                if (convert.IsObjectHandled(mat)) continue;
                Texture mainTex = mat.MainTexture.Res;
                Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null;
                GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault();

                if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0)
                {
                    SpriteRenderer sprite = convert.Result.OfType<SpriteRenderer>().FirstOrDefault();
                    if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<SpriteRenderer>();
                    if (sprite == null) sprite = new SpriteRenderer();
                    sprite.SharedMaterial = mat;
                    if (mainTex != null) sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight);
                    convert.SuggestResultName(sprite, mat.Name);
                    results.Add(sprite);
                }
                else
                {
                    AnimSpriteRenderer sprite = convert.Result.OfType<AnimSpriteRenderer>().FirstOrDefault();
                    if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<AnimSpriteRenderer>();
                    if (sprite == null) sprite = new AnimSpriteRenderer();
                    sprite.SharedMaterial = mat;
                    sprite.Rect = Rect.Align(Alignment.Center,
                        0.0f,
                        0.0f,
                        (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2,
                        (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2);
                    sprite.AnimDuration = 5.0f;
                    sprite.AnimFrameCount = basePixmap.AnimFrames;
                    convert.SuggestResultName(sprite, mat.Name);
                    results.Add(sprite);
                }

                convert.MarkObjectHandled(mat);
            }

            convert.AddResult(results);
            return false;
        }
Exemple #4
0
        protected override void OnCopyDataTo(object targetObj, ICloneOperation operation)
        {
            base.OnCopyDataTo(targetObj, operation);
            AnimSpriteRenderer target = targetObj as AnimSpriteRenderer;

            target.animFirstFrame = this.animFirstFrame;
            target.animFrameCount = this.animFrameCount;
            target.animDuration   = this.animDuration;
            target.animLoopMode   = this.animLoopMode;
            target.animTime       = this.animTime;
            target.animPaused     = this.animPaused;

            operation.HandleObject(this.customFrameSequence, ref target.customFrameSequence);
        }
Exemple #5
0
		void ICmpInitializable.OnInit(Component.InitContext context)
		{
			if (context == InitContext.Activate)
			{
				// Retrieve eye object references and initialize it
				GameObject eyeObject = this.GameObj.ChildByName("Eye");
				this.eye = eyeObject != null ? eyeObject.GetComponent<AnimSpriteRenderer>() : null;
				if (this.eye != null)
				{
					this.eye.AnimLoopMode = AnimSpriteRenderer.LoopMode.FixedSingle;
					this.eye.AnimDuration = 1.0f;
					this.eye.AnimTime = this.eyeOpenValue;
				}

				// Retrieve spike references
				GameObject[] spikeObj = new GameObject[4];
				spikeObj[0] = this.GameObj.ChildByName("SpikeTopRight");
				spikeObj[1] = this.GameObj.ChildByName("SpikeBottomRight");
				spikeObj[2] = this.GameObj.ChildByName("SpikeBottomLeft");
				spikeObj[3] = this.GameObj.ChildByName("SpikeTopLeft");
				this.spikes = new SpriteRenderer[spikeObj.Length];
				for (int i = 0; i < spikeObj.Length; i++)
				{
					this.spikes[i] = spikeObj[i] != null ? spikeObj[i].GetComponent<SpriteRenderer>() : null;
				}
			}
		}
Exemple #6
0
		public override bool Convert(ConvertOperation convert)
		{
			List<object> results = new List<object>();
			List<Material> availData = convert.Perform<Material>().ToList();

			// Generate objects
			foreach (Material mat in availData)
			{
				if (convert.IsObjectHandled(mat)) continue;
				Texture mainTex = mat.MainTexture.Res;
				GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault();

				if (mainTex == null || mainTex.AnimFrames == 0)
				{
					SpriteRenderer sprite = convert.Result.OfType<SpriteRenderer>().FirstOrDefault();
					if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<SpriteRenderer>();
					if (sprite == null) sprite = new SpriteRenderer();
					sprite.SharedMaterial = mat;
					if (mainTex != null) sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight);
					convert.SuggestResultName(sprite, mat.Name);
					results.Add(sprite);
				}
				else
				{
					AnimSpriteRenderer sprite = convert.Result.OfType<AnimSpriteRenderer>().FirstOrDefault();
					if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<AnimSpriteRenderer>();
					if (sprite == null) sprite = new AnimSpriteRenderer();
					sprite.SharedMaterial = mat;
					sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth / mainTex.AnimCols, mainTex.PixelHeight / mainTex.AnimRows);
					sprite.AnimDuration = 5.0f;
					sprite.AnimFrameCount = mainTex.AnimFrames;
					convert.SuggestResultName(sprite, mat.Name);
					results.Add(sprite);
				}

				convert.MarkObjectHandled(mat);
			}

			convert.AddResult(results);
			return false;
		}