public void OnInit(InitContext context)
        {
            if (context != InitContext.Activate)
                return;

            _player = Scene.Current.FindComponent<Player>();
            _playerWood = _player.GameObj.GetComponent<WoodComponent>();
            _woodComponent = GameObj.GetComponent<WoodComponent>();
            _spriteRenderer = GameObj.Renderer as SpriteRenderer;
        }
        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;
        }
Beispiel #3
0
        /// <summary>
        /// This returns the area on screen that is currently occupied by the SpriteRenderer.
        /// For simplicity, this works only if it is set with the ScreenOverlay flag.
        /// 
        /// A full 2.5D implementation (no ScreenOverlay) would require more complex calculations.
        /// </summary>
        /// <returns></returns>
        public Rect GetAreaOnScreen()
        {
            if (this.sprite == null)
                this.sprite = this.GameObj.GetComponent<SpriteRenderer>();

            // Determine position and scale of this menu button on the screen
            Camera mainCamera = this.GameObj.ParentScene.FindComponent<Camera>();
            Vector3 screenBasePos = mainCamera.GetScreenCoord(this.GameObj.Transform.Pos);
            float screenScale = mainCamera.GetScaleAtZ(this.GameObj.Transform.Pos.Z);

            Rect result = this.sprite.Rect
                .Scaled(screenScale, screenScale)
                .WithOffset(screenBasePos.Xy);

            return result;
        }
Beispiel #4
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;
		}