Beispiel #1
0
        public void SetBehaviourFromSnapshot(JediumBehaviourSnapshot snap)
        {
            var type = snap.BehaviourType;

            int index = TYPEBEHAVIOUR.GetTypeIndex(type);

            if (index == -1) //todo - log error
            {
                return;
            }

            if (_behaviours.ContainsKey(index))
            {
                _behaviours[index].FromSnapshot(snap);
            }
            else
            {
                //adding new behaviour
                Type            behType    = BehaviourTypeRegistry.BehaviourTypes[snap.BehaviourType];
                JediumBehaviour plugin_beh =
                    (JediumBehaviour)Activator.CreateInstance(behType, this);

                plugin_beh.FromSnapshot(snap);
                _behaviours.Add(index, plugin_beh);
            }
        }
Beispiel #2
0
        //Мы предполагаем, что компонент Transform есть всегда
        public JediumGameObject(IGameObjectSelfAccessor actor, List <JediumBehaviourSnapshot> behaviours,
                                Dictionary <string, JediumBehaviourDBSnapshot> db_snaps,
                                Guid ownerId, Guid localId)
        {
            Actor       = actor;
            OwnerId     = ownerId;
            LocalId     = localId;
            _behaviours = new Dictionary <int, JediumBehaviour>();


            foreach (var new_beh in db_snaps)
            {
                JediumBehaviour toAdd = null;


                if (BehaviourTypeRegistry.BehaviourTypes.ContainsKey(new_beh.Key))
                {
                    Type behType = BehaviourTypeRegistry.BehaviourTypes[new_beh.Key];


                    if (behType != null)
                    {
                        JediumBehaviour plugin_beh =
                            (JediumBehaviour)Activator.CreateInstance(behType, this);
                        plugin_beh.FromDBSnapshot(new_beh.Value);
                        toAdd = plugin_beh;
                    }
                }


                if (toAdd != null)
                {
                    _behaviours.Add(TYPEBEHAVIOUR.GetTypeIndex(new_beh.Key), toAdd);
                }
            }


            //OLD DB
            if (behaviours != null)
            {
                foreach (var beh in behaviours)
                {
                    if (BehaviourTypeRegistry.BehaviourTypes.ContainsKey(beh.GetBehaviourType()))
                    {
                        //loaded behaviour
                        string bname = beh.GetBehaviourType();

                        Type behType = BehaviourTypeRegistry.BehaviourTypes[bname];

                        if (behType != null)
                        {
                            JediumBehaviour plugin_beh =
                                (JediumBehaviour)Activator.CreateInstance(behType, this);
                            plugin_beh.FromSnapshot(beh);
                            _behaviours.Add(TYPEBEHAVIOUR.GetTypeIndex(bname), plugin_beh);
                        }
                    }
                }
            }

            //special - transform

            if (!_behaviours.ContainsKey(TYPEBEHAVIOUR.GetTypeIndex("Transform")))
            {
                _behaviours.Add(TYPEBEHAVIOUR.GetTypeIndex("Transform"),
                                new JediumTransform(this, JediumTransformSnapshot.Identity));
            }
        }