public static void SyncRenderer(SpriteRenderer from, UTinyEntityView view)
        {
            var registry = view.Registry;
            var entity   = view.EntityRef.Dereference(registry);

            var tinyRenderer = entity.GetComponent(registry.GetSprite2DRendererType());

            if (null != tinyRenderer)
            {
                SyncRenderer(from, tinyRenderer);
            }

            if (from.drawMode == SpriteDrawMode.Simple)
            {
                entity.RemoveComponent(registry.GetSprite2DRendererOptionsType());
            }
            else
            {
                var rendererOptions = entity.GetOrAddComponent(registry.GetSprite2DRendererOptionsType());
                if (null != rendererOptions)
                {
                    SyncRendererOptions(from, rendererOptions);
                }
            }
            TransformInversedBindings.SyncTransform(from.transform, view);
        }
        public override void Create(UTinyEntityView view, SpriteRenderer spriteRenderer)
        {
            var sr = new UTinyObject(Registry, GetMainTinyType());

            SyncRenderer(spriteRenderer, sr);

            UTinyObject srt = null;

            if (spriteRenderer.drawMode != SpriteDrawMode.Simple)
            {
                srt = new UTinyObject(Registry, Registry.GetSprite2DRendererOptionsType());
                SyncRendererOptions(spriteRenderer, srt);
            }

            var entity           = view.EntityRef.Dereference(Registry);
            var sprite2DRenderer = entity.GetOrAddComponent(GetMainTinyType());

            sprite2DRenderer.CopyFrom(sr);
            BindingsHelper.RunBindings(entity, sprite2DRenderer);

            if (null != srt)
            {
                var rendererOptions = entity.GetOrAddComponent(Registry.GetSprite2DRendererOptionsType());
                rendererOptions.CopyFrom(srt);
                BindingsHelper.RunBindings(entity, rendererOptions);
            }
        }
 private static void Register(UTinyEntityView view)
 {
     if (ActiveViews.Add(view) && ActiveViews.Count == 1)
     {
         Undo.postprocessModifications += HandlePostProcessModification;
     }
 }
        public void Create(UTinyEntityView view, Component from)
        {
            var c = (TComponent)from;

            Assert.IsNotNull(c);
            Create(view, c);
        }
        public sealed override void Create(UTinyEntityView view, Transform t)
        {
            UTinyEntity.Reference parentRef = UTinyEntity.Reference.None;
            if (t.parent)
            {
                parentRef = t.parent.GetComponent <UTinyEntityView>()?.EntityRef ?? UTinyEntity.Reference.None;
            }

            var graph = EntityGroupManager.GetSceneGraph(
                parentRef.Equals(UTinyEntity.Reference.None) ?
                EntityGroupManager.ActiveEntityGroup
                                        : (UTinyEntityGroup.Reference)parentRef.Dereference(Registry).EntityGroup);

            if (null == graph)
            {
                return;
            }

            var transform = new UTinyObject(Registry, GetMainTinyType());

            SyncTransform(t, transform);

            var entityNode = graph.CreateFromExisting(t, t.parent);
            var entity     = entityNode.Entity.Dereference(Registry);

            var tiny = entity.GetOrAddComponent(GetMainTinyType());

            tiny.CopyFrom(transform);

            BindingsHelper.RunBindings(entity, tiny);
        }
        public static void SyncCamera(Camera from, UTinyEntityView view)
        {
            var registry = view.Registry;
            var camera   = view.EntityRef.Dereference(registry).GetComponent(registry.GetCamera2DType());

            if (null != camera)
            {
                SyncCamera(from, camera);
            }
        }
        public static void SyncTransform(Transform from, UTinyEntityView view)
        {
            var registry      = view.Registry;
            var tinyTransform = view.EntityRef.Dereference(registry).GetComponent(registry.GetTransformType());

            if (null != tinyTransform)
            {
                SyncTransform(from, tinyTransform);
            }
        }
Example #8
0
        public static void SyncBoxCollider2D(BoxCollider2D from, UTinyEntityView view)
        {
            var registry = view.Registry;
            var collider = view.EntityRef.Dereference(registry).GetComponent(registry.GetRectColliderType());

            if (null != collider)
            {
                SyncBoxCollider2D(from, collider);
            }
        }
        public override void Create(UTinyEntityView view, Camera @from)
        {
            var camera = new UTinyObject(Registry, GetMainTinyType());

            SyncCamera(from, camera);

            var entity = view.EntityRef.Dereference(Registry);
            var tiny   = entity.GetOrAddComponent(GetMainTinyType());

            tiny.CopyFrom(camera);
            BindingsHelper.RunBindings(entity, tiny);
        }
Example #10
0
        public override void Create(UTinyEntityView view, BoxCollider2D from)
        {
            var collider = new UTinyObject(Registry, GetMainTinyType());

            SyncBoxCollider2D(from, collider);

            var entity       = view.EntityRef.Dereference(Registry);
            var rectCollider = entity.GetOrAddComponent(GetMainTinyType());

            rectCollider.CopyFrom(collider);
            BindingsHelper.RunBindings(entity, rectCollider);
        }
        public override void Create(UTinyEntityView view, TextMesh from)
        {
            var tr = new UTinyObject(Registry, GetMainTinyType());

            SyncTextMesh(from, tr);

            var entity       = view.EntityRef.Dereference(Registry);
            var textRenderer = entity.GetOrAddComponent(GetMainTinyType());

            textRenderer.CopyFrom(tr);
            BindingsHelper.RunBindings(entity, textRenderer);
        }
        public static void SyncTextMesh(TextMesh from, UTinyEntityView view)
        {
            var registry = view.Registry;
            var entity   = view.EntityRef.Dereference(registry);

            var tetRenderer = entity.GetComponent(registry.GetTextRendererType());

            if (null != tetRenderer)
            {
                SyncTextMesh(from, tetRenderer);
            }
        }
        private static void Unregister(UTinyEntityView view)
        {
            if (!ActiveViews.Remove(view))
            {
                return;
            }

            if (ActiveViews.Count == 0)
            {
                Undo.postprocessModifications -= HandlePostProcessModification;
            }

            // From this point, we know that the entity view is being destroyed. What we do not know is if the view is
            // being destroyed because we are unloading the scene or if the user deleted the entity through the hierarchy
            // or the scene view.
            var entity = view.EntityRef.Dereference(Registry);

            if (entity?.EntityGroup == null)
            {
                return;
            }

            var entityGroupRef = (UTinyEntityGroup.Reference)entity.EntityGroup;

            if (UnloadingEntityGroups.Contains(entityGroupRef))
            {
                return;
            }

            entity.View = null;

            var graph = EntityGroupManager.GetSceneGraph(entityGroupRef);

            if (null == graph)
            {
                return;
            }

            graph.Delete(graph.FindNode(view.EntityRef));
            UTinyHierarchyWindow.InvalidateSceneGraph();
        }
        private static void HandleRegistration(UTinyTrackerRegistration trackerRegistration, UTinyEntityView view)
        {
            switch (trackerRegistration)
            {
            case UTinyTrackerRegistration.Register:
                Register(view);
                break;

            case UTinyTrackerRegistration.Unregister:
                Unregister(view);
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
 public abstract void Create(UTinyEntityView view, TComponent from);