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 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);
            }
        }
Example #3
0
        public static EntityGroupGraph CreateFromEntityGroup(UTinyEntityGroup entityGroup)
        {
            var graph = new EntityGroupGraph(entityGroup);

            graph.SyncFromUTiny();
            foreach (var entity in entityGroup.Entities.Select(entityRef => entityRef.Dereference(entityGroup.Registry)))
            {
                if (null == entity)
                {
                    continue;
                }
                entity.EntityGroup = entityGroup;
                graph.CreateLink(entity);
            }

            graph.CommitToUnity();

            foreach (var entity in entityGroup.Entities.Select(entityRef => entityRef.Dereference(entityGroup.Registry)))
            {
                if (null == entity)
                {
                    continue;
                }
                BindingsHelper.RunAllBindings(entity);
            }

            return(graph);
        }
Example #4
0
        private void HandleUndoOperation()
        {
            BindingsHelper.RemoveAllBindingsOnLoadedEntities();
            int version = -1;

            try
            {
                do
                {
                    // 0 is basically you loaded the project
                    if (m_UndoableChanges.Count > 1)
                    {
                        //Debug.Log("Undo operation");
                        var changes = m_UndoableChanges.Last();
                        foreach (var change in changes)
                        {
                            var originator = m_Registry.FindById <IRegistryObject>(change.Id) as IOriginator;
                            version = change.Version;
                            if (null == originator)
                            {
                                originator = change.RegistryObject as IOriginator;
                            }

                            // We have no previous version, which means that the originator must have been created.
                            // Knowing this, we shall remove it from the registry.
                            if (null == change.PreviousVersion)
                            {
                                m_Registry.Unregister(originator as IRegistryObject);
                            }
                            // Otherwise, restore the previous version.
                            else
                            {
                                originator.Restore(change.PreviousVersion);
                            }
                        }
                        m_UndoableChanges.RemoveAt(m_UndoableChanges.Count - 1);
                        m_RedoableChanges.Add(changes);
                    }
                    else
                    {
                        break;
                    }
                }while (version > m_Undo.Version);
            }
            finally
            {
                RefreshAll();
                OnUndoPerformed?.Invoke();
                m_Caretaker.OnObjectChanged -= HandleUndoableChange;
                m_Caretaker.Update();
                m_Registry.ClearUnregisteredObjects();
                m_Caretaker.OnObjectChanged += HandleUndoableChange;
                BindingsHelper.RunAllBindingsOnLoadedEntities();
            }
        }
Example #5
0
        private static void UpdateMeshes()
        {
            var repaint = false;
            var context = UTinyEditorApplication.EditorContext;

            if (null == context)
            {
                return;
            }

            // We want to make sure that all the renderers are "ordered" by hierarchy oder.
            var currentQueue = 3000;
            var scene        = UTinyEditorApplication.EntityGroupManager.UnityScratchPad;

            if (scene.isLoaded && scene.IsValid())
            {
                foreach (var go in scene.GetRootGameObjects())
                {
                    foreach (var renderer in go.GetComponentsInChildren <Renderer>())
                    {
                        var r = currentQueue;

                        if (renderer.gameObject.GetComponent <TextMesh>())
                        {
                            r += 2000;
                        }

                        repaint |= renderer.sharedMaterial.renderQueue != r;
                        renderer.sharedMaterial.renderQueue = r;

                        currentQueue++;

                        var view = go.GetComponent <UTinyEntityView>();
                        if (!view)
                        {
                            continue;
                        }

                        var entity = view.EntityRef.Dereference(context.Registry);

                        if (null != entity)
                        {
                            entity.View = view;
                            // Update mesh information.
                            BindingsHelper.RunBindings(entity, entity.GetComponent(context.Registry.GetSprite2DRendererType()));
                        }
                    }
                }
            }

            if (repaint)
            {
                SceneView.RepaintAll();
            }
        }
Example #6
0
        private UTinyEntityView CreateLink(UTinyEntity entity)
        {
            try
            {
                var entityRef = (UTinyEntity.Reference)entity;
                if (null != entity.View && entity.View)
                {
                    entity.View.EntityRef = entityRef;
                    entity.View.Registry  = entity.Registry;
                    entity.View.gameObject.SetActive(entity.Enabled);
                    entity.View.gameObject.layer = entity.Layer;
                    return(null);
                }

                // We may have recreated the entity, try to find an active view
                {
                    var scene = UTinyEditorApplication.EntityGroupManager.UnityScratchPad;
                    foreach (var r in scene.GetRootGameObjects())
                    {
                        foreach (var v in r.GetComponentsInChildren <UTinyEntityView>())
                        {
                            if (v.EntityRef.Equals(entityRef))
                            {
                                entity.View           = v;
                                entity.View.EntityRef = entityRef;
                                entity.View.Registry  = entity.Registry;
                                v.gameObject.SetActive(entity.Enabled);
                                v.gameObject.layer = entity.Layer;
                                return(null);
                            }
                        }
                    }
                }

                var go   = new GameObject(entity.Name);
                var view = go.AddComponent <UTinyEntityView>();
                view.gameObject.SetActive(entity.Enabled);
                view.gameObject.layer = entity.Layer;
                view.EntityRef        = entityRef;
                view.Registry         = entity.Registry;
                entity.View           = view;

                return(view);
            }
            finally
            {
                // At this point, it is not clear if the bindings have been added or not (we may have undo-ed something).
                entity.OnComponentAdded   -= HandleComponentAdded;
                entity.OnComponentRemoved -= HandleComponentRemoved;
                entity.OnComponentAdded   += HandleComponentAdded;
                entity.OnComponentRemoved += HandleComponentRemoved;
                BindingsHelper.RunAllBindings(entity);
            }
        }
        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 #8
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);
        }
        private void RunAllTheBidings()
        {
            var entityGroupManager = UTinyEditorApplication.EntityGroupManager;
            var registry           = UTinyEditorApplication.Registry;

            if (null == entityGroupManager || null == registry)
            {
                return;
            }
            foreach (var entity in entityGroupManager.LoadedEntityGroups.Deref(registry).SelectMany(s => s.Entities).Deref(registry))
            {
                BindingsHelper.RunAllBindings(entity);
            }
        }
        private bool AddToEntity(UTinyEntity.Reference entityRef, Sprite sprite, bool runBindings)
        {
            var entity = entityRef.Dereference(m_Context.Registry);

            entity.Name = sprite?.name ?? "NullSprite";

            var renderer = entity.GetOrAddComponent(Registry.GetSprite2DRendererType());

            renderer["sprite"] = sprite;

            if (runBindings)
            {
                BindingsHelper.RunAllBindings(entity);
            }

            UTinyHierarchyWindow.InvalidateSceneGraph();
            return(true);
        }
        private bool AddToEntity(UTinyEntity.Reference entityRef, Font font, bool runBindings)
        {
            var entity = entityRef.Dereference(m_Context.Registry);

            entity.Name = font.name;

            var renderer = entity.GetOrAddComponent(Registry.GetTextRendererType());

            renderer["text"] = "Sample Text";
            renderer["font"] = font;

            if (runBindings)
            {
                BindingsHelper.RunAllBindings(entity);
            }

            UTinyHierarchyWindow.InvalidateSceneGraph();
            return(true);
        }
        private bool AddToEntity(UTinyEntity.Reference entityRef, AudioClip audioClip, bool runBindings)
        {
            var entity = entityRef.Dereference(m_Context.Registry);

            entity.Name = audioClip.name;

            var audioSource = entity.GetOrAddComponent(Registry.GetAudioSourceType());

            audioSource.Refresh();
            audioSource["clip"]   = audioClip;
            audioSource["volume"] = 1.0f;

            if (runBindings)
            {
                BindingsHelper.RunAllBindings(entity);
            }
            UTinyHierarchyWindow.InvalidateSceneGraph();
            return(true);
        }
Example #14
0
        private bool AddToEntity(UTinyEntity.Reference entityRef, Sprite sprite, bool runBindings)
        {
            var entity = entityRef.Dereference(m_Context.Registry);

            entity.Name = sprite?.name ?? "NullSprite";

            var renderer = entity.GetOrAddComponent(Registry.GetSprite2DRendererType());

            renderer["sprite"] = sprite;

            if (runBindings)
            {
                BindingsHelper.RunAllBindings(entity);
            }

            UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.SceneGraph);

            return(true);
        }
Example #15
0
        private bool AddToEntity(UTinyEntity.Reference entityRef, Font font, bool runBindings)
        {
            var entity = entityRef.Dereference(m_Context.Registry);

            entity.Name = font.name;

            var renderer = entity.GetOrAddComponent(Registry.GetTextRendererType());

            renderer["text"] = "Sample Text";
            renderer["font"] = font;

            if (runBindings)
            {
                BindingsHelper.RunAllBindings(entity);
            }

            UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.SceneGraph);

            return(true);
        }
        private bool AddToEntity(UTinyEntity.Reference entityRef, Texture2D texture, bool runBindings)
        {
            var entity = entityRef.Dereference(m_Context.Registry);

            entity.Name = texture.name;

            var image2d = entity.GetOrAddComponent(Registry.GetImage2DType());

            image2d.Refresh();
            image2d["imageFile"] = texture;

            // @TODO Pull from texture importer
            image2d["pixelsToWorldUnits"] = 1.0f;

            if (runBindings)
            {
                BindingsHelper.RunAllBindings(entity);
            }
            UTinyHierarchyWindow.InvalidateSceneGraph();
            return(true);
        }