コード例 #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);
            }
        }
コード例 #2
0
        /// <summary>
        /// Создание Behaviours object
        /// </summary>
        void AddBehaviourComponents(GameObject pobj)
        {
            //process already added components
            List <JediumBehaviour> componentList = new List <JediumBehaviour>();

            componentList = pobj.gameObject.GetComponentsInChildren <JediumBehaviour>().ToList();

            foreach (JediumBehaviour o in componentList)
            {
                o.SetParent(this);
                o.SetUpdater(_updater);
            }


            //NEW WAY

            foreach (var snap in _snapshot.Snapshots)
            {
                if (BehaviourTypeRegistry.RegisteredBehaviourTypes.ContainsKey(snap.Key))
                {
                    Type            ctype = BehaviourTypeRegistry.RegisteredBehaviourTypes[snap.Key];
                    JediumBehaviour oBeh  = (JediumBehaviour)pobj.AddComponent(ctype);
                    oBeh.SetParent(this);
                    oBeh.SetUpdater(_updater);
                    componentList.Add(oBeh);
                }
                else
                {
                    _log.Error($"Can't find type for behaviour with name {snap.Key}");
                }
            }

            ////run Init() on them
            foreach (var comp in componentList)
            {
                //JediumBehaviourSnapshot snap = null;

                // if (_snapshot.Snapshots.ContainsKey(comp.GetComponentType()))
                JediumBehaviourSnapshot snap = _snapshot.Snapshots[comp.GetComponentType()];
                comp.Init(snap);
            }

            var localBehaviours = pobj.gameObject.GetComponents <JediumLocalBehaviour>();

            foreach (var lcomp in localBehaviours)
            {
                lcomp.Init(this);
            }

            //add context menu
            pobj.gameObject.AddComponent <MainGUIContextMenu>();
        }
コード例 #3
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));
            }
        }
コード例 #4
0
        static void LoadPluginFromManifest(BehaviourPluginManifest man, string path)
        {
            if (!File.Exists(Path.Combine(path, man.ServerDLL)) || !File.Exists(Path.Combine(path, man.SharedDLL)))
            {
                _log.Warn($"Can't find DLLs for plugin {man.Name}");
                return;
            }

            AssemblyName san = AssemblyName.GetAssemblyName(Path.Combine(path, man.ServerDLL));

            Assembly sas = Assembly.Load(san);

            Type behaviourType = typeof(JediumBehaviour);

            Type dbType = typeof(JediumBehaviourDBSnapshot);

            Type[] types = sas.GetTypes();

            foreach (Type t in types)
            {
                if (t.IsAbstract || t.IsInterface)
                {
                }
                else
                {
                    if (t.BaseType == behaviourType)
                    {
                        JediumBehaviour jb    = (JediumBehaviour)Activator.CreateInstance(t, new object[] { null });
                        string          btype = jb.GetBehaviourType();
                        BehaviourTypeRegistry.BehaviourTypes.Add(btype, t);
                        //we also need to add type to TYPEBEHAVOUR
                        TYPEBEHAVIOUR.AddRegisteredType(btype);
                        _log.Info($"Added behaviour:{btype},{t}");
                    }

                    if (t.BaseType == dbType)
                    {
                        BehaviourTypeRegistry.DBTypes.Add(t);
                        _log.Info($"Registered DB snapshot type:{t}");
                    }
                }
            }

            AssemblyName shan = AssemblyName.GetAssemblyName(Path.Combine(path, man.SharedDLL));

            Assembly shas = Assembly.Load(shan);

            Type snapshotType = typeof(JediumBehaviourSnapshot);

            types = shas.GetTypes();

            Type messageType = typeof(JediumBehaviourMessage);

            foreach (Type t in types)
            {
                if (t.IsAbstract || t.IsInterface)
                {
                }
                else
                {
                    if (t.BaseType == snapshotType)
                    {
                        JediumBehaviourSnapshot jb = (JediumBehaviourSnapshot)Activator.CreateInstance(t);
                        string btype = jb.GetBehaviourType();
                        RegisteredSnapshotTypes.Add(btype, t);

                        _log.Info($"Added snapshot:{btype},{t}");
                    }

                    if (t.GetInterface(messageType.FullName) != null)
                    {
                        RegisteredMessageTypes.Add(t);


                        _log.Info($"Added message:{t}");
                    }
                }
            }

            _log.Info("Finished loading behaviour plugin " + man.Name + " ,v. " + man.Version);
        }
コード例 #5
0
 public void RegisterComponent(JediumBehaviour cmpnt)
 {
     _registeredComponents.Add(cmpnt.GetComponentTypeIndex(), cmpnt);
 }