コード例 #1
0
        private DetailObject CreateDetailInstance(
            Dictionary <DetailTemplate, DetailObject> mapping,
            Dictionary <BehaviourTemplate, Behaviour> behaviours,
            DetailTemplate template,
            DetailObject parent)
        {
            Vector3 pos = Vector3.Zero;

            if (template.Position != null)
            {
                pos = template.GetPosition();
            }
            Shape shape = null;

            if (template.Shape != null)
            {
                shape = DetailHelper.CreateShape(template.Shape.GetSize());
            }

            DetailObject root = this.CreateDetail(template.Model, pos, parent, shape);

            if (template.Rotation != null)
            {
                root.Rotation = template.GetRotation();
            }

            if (template.Children != null)
            {
                foreach (var child in template.Children)
                {
                    CreateDetailInstance(mapping, behaviours, child, root);
                }
            }
            mapping.Add(template, root);

            if (template.Behaviours != null)
            {
                foreach (var behav in template.Behaviours)
                {
                    var type = Type.GetType(behav.Class);
                    if (type.IsSubclassOf(typeof(Behaviour)) == false)
                    {
                        throw new InvalidOperationException("Invalid behaviour type: " + behav.Class);
                    }
                    Behaviour behaviour = root.CreateBehaviour(type, true);
                    behaviours.Add(behav, behaviour);
                }
            }

            return(root);
        }
コード例 #2
0
        private List <DetailTemplate> Flatten(DetailTemplate t, List <DetailTemplate> list = null)
        {
            list = list ?? new List <DetailTemplate>();
            list.Add(t);

            if (t.Children != null)
            {
                foreach (var child in t.Children)
                {
                    Flatten(child, list);
                }
            }
            return(list);
        }
コード例 #3
0
        public DetailObject CreateDetail(DetailTemplate template, Vector3 position)
        {
            var mapping    = new Dictionary <DetailTemplate, DetailObject>();
            var behaviours = new Dictionary <BehaviourTemplate, Behaviour>();
            var root       = this.CreateDetailInstance(
                mapping,
                behaviours,
                template,
                null);

            // Connect behaviours
            {
                var namedBehaviours = new Dictionary <string, Behaviour>();
                foreach (var kv in behaviours)
                {
                    if (kv.Key.ID != null)
                    {
                        namedBehaviours.Add(kv.Key.ID, kv.Value);
                    }
                }
                foreach (var kv in behaviours)
                {
                    if (kv.Key.SlotConnections != null)
                    {
                        foreach (var con in kv.Key.SlotConnections)
                        {
                            var source = namedBehaviours[con.Source];
                            var signal = source.Signals[con.Signal];
                            var slot   = kv.Value.Slots[con.Slot];

                            slot.ConnectTo(signal);
                        }
                    }
                }
            }

            root.Position = position;

            return(root);
        }
コード例 #4
0
ファイル: World.cs プロジェクト: MasterQ32/BlocksWorld
        private List<DetailTemplate> Flatten(DetailTemplate t, List<DetailTemplate> list = null)
        {
            list = list ?? new List<DetailTemplate>();
            list.Add(t);

            if (t.Children != null)
            {
                foreach (var child in t.Children)
                {
                    Flatten(child, list);
                }
            }
            return list;
        }
コード例 #5
0
ファイル: World.cs プロジェクト: MasterQ32/BlocksWorld
        private DetailObject CreateDetailInstance(
			Dictionary<DetailTemplate, DetailObject> mapping,
			Dictionary<BehaviourTemplate, Behaviour> behaviours,
			DetailTemplate template,
			DetailObject parent)
        {
            Vector3 pos = Vector3.Zero;
            if (template.Position != null)
                pos = template.GetPosition();
            Shape shape = null;
            if(template.Shape != null)
            {
                shape = DetailHelper.CreateShape(template.Shape.GetSize());
            }

            DetailObject root = this.CreateDetail(template.Model, pos, parent, shape);
            if (template.Rotation != null)
                root.Rotation = template.GetRotation();

            if (template.Children != null)
            {
                foreach (var child in template.Children)
                {
                    CreateDetailInstance(mapping, behaviours, child, root);
                }
            }
            mapping.Add(template, root);

            if (template.Behaviours != null)
            {
                foreach (var behav in template.Behaviours)
                {
                    var type = Type.GetType(behav.Class);
                    if (type.IsSubclassOf(typeof(Behaviour)) == false)
                        throw new InvalidOperationException("Invalid behaviour type: " + behav.Class);
                    Behaviour behaviour = root.CreateBehaviour(type, true);
                    behaviours.Add(behav, behaviour);
                }
            }

            return root;
        }
コード例 #6
0
ファイル: World.cs プロジェクト: MasterQ32/BlocksWorld
        public DetailObject CreateDetail(DetailTemplate template, Vector3 position)
        {
            var mapping = new Dictionary<DetailTemplate, DetailObject>();
            var behaviours = new Dictionary<BehaviourTemplate, Behaviour>();
            var root = this.CreateDetailInstance(
                mapping,
                behaviours,
                template,
                null);

            // Connect behaviours
            {
                var namedBehaviours = new Dictionary<string, Behaviour>();
                foreach (var kv in behaviours)
                {
                    if (kv.Key.ID != null)
                        namedBehaviours.Add(kv.Key.ID, kv.Value);
                }
                foreach (var kv in behaviours)
                {
                    if (kv.Key.SlotConnections != null)
                    {
                        foreach (var con in kv.Key.SlotConnections)
                        {
                            var source = namedBehaviours[con.Source];
                            var signal = source.Signals[con.Signal];
                            var slot = kv.Value.Slots[con.Slot];

                            slot.ConnectTo(signal);
                        }
                    }
                }
            }

            root.Position = position;

            return root;
        }