Пример #1
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            var renderer = GetComponent <SpriteRenderer>(entity);

            renderer.size     = component.GetProperty <Vector2>("size");
            renderer.drawMode = Translate(component.GetProperty <TileMode>("mode"));
        }
Пример #2
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            var renderer = GetComponent <SpriteRenderer>(entity);

            renderer.size = component.GetProperty <Vector2>("size");
            SetDrawMode(renderer, component.GetProperty <DrawMode>("drawMode"));
        }
Пример #3
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            var transform = entity.View.transform;

            transform.localPosition = component.GetProperty <Vector3>("localPosition");
            transform.localRotation = component.GetProperty <Quaternion>("localRotation");
            transform.localScale    = component.GetProperty <Vector3>("localScale");
        }
Пример #4
0
        protected override void OnAddBinding(UTinyEntity entity, UTinyObject component)
        {
            var renderer = GetComponent <SpriteRenderer>(entity);

            renderer.drawMode = Translate(component.GetProperty <TileMode>("mode"));
            if (component.GetProperty <Vector2>("size") == Vector2.zero)
            {
                component.AssignPropertyFrom("size", renderer.size);
            }
        }
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            OnAddBinding(entity, component);
            var collider = GetComponent <BoxCollider2D>(entity);
            var pivot    = component.GetProperty <Vector2>("pivot");
            var width    = component.GetProperty <float>("width");
            var height   = component.GetProperty <float>("height");

            collider.size   = new Vector2(width, height);
            collider.offset = new Vector2(-(pivot.x - 0.5f) * width, -(pivot.y - 0.5f) * height);
        }
Пример #6
0
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var particleSystem = GetComponent <ParticleSystem>(entity);
                var registry       = entity.Registry;

                // [MP] @TODO: At some point, we'll have more than one type of source.
                var shape = particleSystem.shape;

                shape.shapeType = ParticleSystemShapeType.Box;

                var boxRect  = component.GetProperty <Rect>("rect");
                var boxScale = shape.scale;

                boxScale.x  = boxRect.width;
                boxScale.y  = boxRect.height;
                boxScale.z  = 1.0f;
                shape.scale = boxScale;

                var boxPosition = shape.position;

                boxPosition.x  = boxRect.x;
                boxPosition.y  = boxRect.y;
                boxPosition.z  = 0.0f;
                shape.position = boxPosition;

                var emission = particleSystem.emission;

                emission.enabled = boxRect.width != 0 || boxRect.height != 0;
            }
Пример #7
0
        private static void SetColorProperty(UTinyObject rendererComponent, MaterialPropertyBlock block)
        {
            Color color = Color.white;

            color = rendererComponent.GetProperty <Color>("color");
            block.SetColor("_Color", color);
        }
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var module   = entity.View.GetComponent <ParticleSystem>().main;
                var rotation = component.GetProperty <Range>("rotation");

                SetRotationRange(module, rotation);
            }
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var module = entity.View.GetComponent <ParticleSystem>().main;
                var scale  = component.GetProperty <Range>("scale");

                SetScaleRange(module, scale);
            }
Пример #10
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject sprite2DRenderer)
        {
#if UNITY_EDITOR
            try
            {
                OnAddBinding(entity, sprite2DRenderer);
                var sprite         = sprite2DRenderer.GetProperty <Sprite>("sprite");
                var spriteRenderer = GetComponent <SpriteRenderer>(entity);

                var block = new MaterialPropertyBlock();
                spriteRenderer.GetPropertyBlock(block);
                block.Clear();

                SetColorProperty(sprite2DRenderer, block);

                if (sprite)
                {
                    spriteRenderer.sprite = sprite;
                    var     blending = sprite2DRenderer.GetProperty <UTinyEnum.Reference>("blending").Value;
                    Vector2 blendMode;
                    if (s_BlendModes.TryGetValue(blending, out blendMode))
                    {
                        spriteRenderer.sharedMaterial.SetFloat("_SrcMode", blendMode.x);
                        spriteRenderer.sharedMaterial.SetFloat("_DstMode", blendMode.y);
                    }
                    else
                    {
                        Debug.Log($"{UTinyConstants.ApplicationName}: Unknown blending mode, of value '{blending}'");
                    }

                    block.SetTexture("_MainTex", sprite.texture);
                    SetColorProperty(sprite2DRenderer, block);
                }
                else
                {
                    spriteRenderer.sprite = null;
                }

                spriteRenderer.SetPropertyBlock(block);
            }
            finally
            {
                UnityEditor.SceneView.RepaintAll();
            }
#endif
        }
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            OnAddBinding(entity, component);

            var behaviour = GetComponent <RectHitBox2D>(entity);

            behaviour.Box = component.GetProperty <Rect>("box");
        }
        protected static void AssignIfDifferent(UTinyObject tiny, string propertyName, AudioClip value)
        {
            var current = tiny.GetProperty <AudioClip>(propertyName);

            if (current != value)
            {
                tiny.AssignPropertyFrom(propertyName, value);
            }
        }
        protected static void AssignIfDifferent <TValue>(UTinyObject tiny, string propertyName, TValue value)
        {
            var current = tiny.GetProperty <TValue>(propertyName);

            if (!current.Equals(value))
            {
                tiny.AssignPropertyFrom(propertyName, value);
            }
        }
        private void DrawClearFlags(UTinyObject tinyObject)
        {
            var fieldName = "clearFlags";

            DrawEnum(tinyObject, fieldName);
            if (tinyObject.GetProperty <CameraClearFlags>(fieldName) == CameraClearFlags.Color)
            {
                DrawSubObject(tinyObject, "backgroundColor");
            }
        }
Пример #15
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            var camera = GetComponent <Camera>(entity);

            if (camera && camera != null)
            {
                camera.transparencySortMode = TransparencySortMode.CustomAxis;
                camera.transparencySortAxis = component.GetProperty <Vector3>("axis");
            }
        }
Пример #16
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
        {
            component.Refresh();
            OnAddBinding(entity, component);
            var camera        = entity.View.gameObject.GetComponent <Camera>();
            var clearFlagsRef = component.GetProperty <UTinyEnum.Reference>("clearFlags");

            if (clearFlagsRef.Name == "SolidColor")
            {
                camera.clearFlags = CameraClearFlags.SolidColor;
            }
            else
            {
                camera.clearFlags = CameraClearFlags.Depth;
            }
            var backgroundColor = component.GetProperty <Color>("backgroundColor");

            camera.backgroundColor     = backgroundColor;
            camera.orthographic        = true;
            camera.orthographicSize    = component.GetProperty <float>("halfVerticalSize");
            camera.nearClipPlane       = 0;
            camera.depth               = -101.0f;
            camera.useOcclusionCulling = false;
            camera.allowHDR            = false;
            camera.allowMSAA           = false;
#if UNITY_2017_3_OR_NEWER
            camera.allowDynamicResolution = false;
#endif
            camera.cullingMask = component.GetProperty <int>("layerMask");
            camera.rect        = component.GetProperty <Rect>("rect");
            camera.depth       = component.GetProperty <float>("depth");
        }
Пример #17
0
        protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject textRenderer)
        {
            OnAddBinding(entity, textRenderer);
#if UNITY_EDITOR
            try
            {
                var textMesh = GetComponent <TextMesh>(entity);

                textMesh.text     = textRenderer.GetProperty <string>("text");
                textMesh.fontSize = textRenderer.GetProperty <int>("fontSize");

                var bold   = textRenderer.GetProperty <bool>("bold");
                var italic = textRenderer.GetProperty <bool>("italic");

                if (bold && italic)
                {
                    textMesh.fontStyle = FontStyle.BoldAndItalic;
                }
                else if (bold)
                {
                    textMesh.fontStyle = FontStyle.Bold;
                }
                else if (italic)
                {
                    textMesh.fontStyle = FontStyle.Italic;
                }
                else
                {
                    textMesh.fontStyle = FontStyle.Normal;
                }

                textMesh.characterSize = 10;
                textMesh.lineSpacing   = 1;
                textMesh.richText      = false;
                textMesh.alignment     = TextAlignment.Left;
                textMesh.anchor        = textRenderer.GetProperty <TextAnchor>("anchor");
                textMesh.color         = textRenderer.GetProperty <Color>("color");
                textMesh.font          = textRenderer.GetProperty <Font>("font");

                if (textMesh.font)
                {
                    var renderer = GetComponent <MeshRenderer>(entity);
                    var block    = new MaterialPropertyBlock();
                    renderer.GetPropertyBlock(block);
                    block.Clear();
                    block.SetTexture("_MainTex", textMesh.font.material.mainTexture);
                    renderer.SetPropertyBlock(block);
                }
            }
            finally
            {
                UnityEditor.SceneView.RepaintAll();
            }
#endif
        }
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var module         = GetComponent <ParticleSystem>(entity).colorOverLifetime;
                var registry       = entity.Registry;
                var gradientRef    = component.GetProperty <UTinyEntity.Reference>("gradient");
                var gradientEntity = gradientRef.Dereference(registry);
                var colorGradient  = gradientEntity?.GetComponent(registry.GetGradientType());

                if (null == gradientEntity || null == colorGradient)
                {
                    module.enabled = false;
                }
                else
                {
                    module.enabled = true;
                    module.color   = new ParticleSystem.MinMaxGradient(colorGradient.As <Gradient>());
                }
            }
Пример #19
0
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var module      = GetComponent <ParticleSystem>(entity).sizeOverLifetime;
                var registry    = entity.Registry;
                var curveRef    = component.GetProperty <UTinyEntity.Reference>("curve");
                var curveEntity = curveRef.Dereference(registry);
                var curve       = curveEntity?.GetComponent(registry.GetCurveType());

                if (null == curveEntity || null == curve)
                {
                    module.enabled = false;
                }
                else
                {
                    module.enabled      = true;
                    module.separateAxes = false;
                    module.size         = new ParticleSystem.MinMaxCurve(1.0f, curve.As <AnimationCurve>());
                }
            }
            public static Gradient ConvertToAlphaGradient(UTinyObject obj)
            {
                var gradient = new Gradient();

                gradient.mode = (GradientMode)obj.GetProperty <UTinyEnum.Reference>("mode").Value;

                List <GradientAlphaKey> offsets = new List <GradientAlphaKey>();

                var stops = obj["stops"] as UTinyList;

                for (int i = 0; i < stops.Count; ++i)
                {
                    var stop   = stops[i] as UTinyObject;
                    var offset = stop.GetProperty <float>("offset");
                    var value  = stop.GetProperty <float>("value");
                    offsets.Add(new GradientAlphaKey(value, offset));
                }

                gradient.alphaKeys = offsets.ToArray();
                return(gradient);
            }
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var module      = GetComponent <ParticleSystem>(entity).colorOverLifetime;
                var registry    = entity.Registry;
                var curveRef    = component.GetProperty <UTinyEntity.Reference>("curve");
                var curveEntity = curveRef.Dereference(registry);
                var curve       = curveEntity?.GetComponent(registry.GetCurveType());

                if (UsesLifetimeColor(entity))
                {
                    return;
                }

                if (null == curveEntity || null == curve)
                {
                    module.enabled = false;
                }
                else
                {
                    module.enabled = true;
                    module.color   = new ParticleSystem.MinMaxGradient(ConvertToAlphaGradient(curve));
                }
            }
Пример #22
0
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                var module      = GetComponent <ParticleSystem>(entity).rotationOverLifetime;
                var registry    = entity.Registry;
                var curveRef    = component.GetProperty <UTinyEntity.Reference>("curve");
                var curveEntity = curveRef.Dereference(registry);
                var curve       = curveEntity?.GetComponent(registry.GetCurveType());

                if (null == curveEntity || null == curve)
                {
                    // This should be false, but for some reason, the particle system continues to rotate.
                    module.separateAxes = true;
                    module.x            = module.y = module.z = NoCurve;
                    module.enabled      = true;
                }
                else
                {
                    module.enabled      = true;
                    module.separateAxes = true;
                    module.x            = module.y = NoCurve;
                    module.z            = new ParticleSystem.MinMaxCurve(1.0f * Mathf.Deg2Rad, curve.As <AnimationCurve>());
                }
            }
            protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
            {
                OnAddBinding(entity, component);
                var registry       = entity.Registry;
                var particleSystem = GetComponent <ParticleSystem>(entity);

                var main = particleSystem.main;

                main.maxParticles = (int)component.GetProperty <uint>("maxParticles");
                main.startDelay   = component.GetProperty <float>("startDelay");
                // float => bool conversion.
                main.prewarm = component.GetProperty <float>("prewarmPercent") >= 0.5f;
                var lifetime = component.GetProperty <Range>("lifetime");

                main.startLifetime = new ParticleSystem.MinMaxCurve(lifetime.start, lifetime.end);

                var emission = particleSystem.emission;

                emission.rateOverTime = component.GetProperty <float>("emitRate");

                // Renderer settings
                {
                    var renderer = particleSystem.GetComponent <ParticleSystemRenderer>();
                    renderer.renderMode = ParticleSystemRenderMode.Mesh;

                    var particleRef      = (UTinyEntity.Reference)component["particle"];
                    var particle         = particleRef.Dereference(registry);
                    var sprite2DRenderer = particle?.GetComponent(registry.GetSprite2DRendererType());

                    if (null == particle || null == sprite2DRenderer)
                    {
                        SyncMesh(renderer.mesh, null, Vector3.zero);
                    }
                    else
                    {
                        var sprite = sprite2DRenderer.GetProperty <Sprite>("sprite");
                        var particleSpriteRenderer = GetComponent <SpriteRenderer>(particle);
                        if (null == particleSpriteRenderer || !particleSpriteRenderer)
                        {
                            SyncMesh(renderer.mesh, sprite, Vector3.zero);
                            return;
                        }
                        SyncMesh(renderer.mesh, sprite, GetComponent <Transform>(particle)?.localScale ?? Vector3.zero);

                        MaterialPropertyBlock sprite2DBlock = new MaterialPropertyBlock();
                        particleSpriteRenderer.GetPropertyBlock(sprite2DBlock);

                        MaterialPropertyBlock particle2DBlock = new MaterialPropertyBlock();
                        renderer.GetPropertyBlock(particle2DBlock);
                        particle2DBlock.Clear();

                        if (null != sprite)
                        {
                            particle2DBlock.SetTexture("_MainTex", sprite.texture);
                        }
                        main.startColor = sprite2DBlock.GetColor("_Color");

                        renderer.SetPropertyBlock(particle2DBlock);

                        // Transfer blending mode
                        var particleMaterial = particleSpriteRenderer.sharedMaterial;
                        renderer.sharedMaterial.SetFloat("_SrcMode", particleMaterial.GetFloat("_SrcMode"));
                        renderer.sharedMaterial.SetFloat("_DstMode", particleMaterial.GetFloat("_DstMode"));
                    }
                }
            }
 protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component)
 {
     SetSortingLayerOrder(entity, component.GetProperty <int>("layer"), component.GetProperty <int>("order"));
 }