Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 public override void FromSnapshot(JediumBehaviourSnapshot snap)
 {
     if (snap.GetBehaviourType() != "Animation")
     {
         _log.Warn($"Wrong snapshot type: {snap.GetBehaviourType()}");
     }
 }
Ejemplo n.º 3
0
 public override void FromSnapshot(JediumBehaviourSnapshot snap)
 {
     if (snap.GetType() != typeof(JediumToucheableSnapshot))
     {
         //warn
     }
 }
Ejemplo n.º 4
0
 public override void FromSnapshot(JediumBehaviourSnapshot snap)
 {
     if (snap.GetBehaviourType() != "CharacterController")
     {
         _log.Warn($"Wrong snapshot type: {snap.GetBehaviourType()}");
     }
 }
 //TODO
 //HACK
 //Disabling transform for non-root-motion animators
 public override void Init(JediumBehaviourSnapshot snapshot)
 {
     base.Init(snapshot);
     if (!HasRootMotion)
     {
         JediumTransformBehaviour trans = GetComponent <JediumTransformBehaviour>();
         trans.AnimatorBased = true;
     }
 }
Ejemplo n.º 6
0
        public Task SetObjectBehaviour(Guid localId, JediumBehaviourSnapshot snap)
        {
            if (!sceneObjects.ContainsKey(localId))
            {
                _logger.Warn($"Object {localId} not found while trying to set behaviour");
                return(Task.FromResult(false));
            }

            return(sceneObjects[localId].Item2.SetBehaviourSnapshot(snap));
        }
Ejemplo n.º 7
0
        public override void Init(JediumBehaviourSnapshot snapshot)
        {
            base.Init(snapshot);

            Debug.Log("sgdf");

            JediumSitSnapshot sitSnap = (JediumSitSnapshot)snapshot;

            AttachPoint    = new Vector3(sitSnap.X, sitSnap.Y, sitSnap.Z);
            AttachRotation = new Quaternion(sitSnap.RotX, sitSnap.RotY, sitSnap.RotZ, sitSnap.RotW);
        }
Ejemplo n.º 8
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>();
        }
Ejemplo n.º 9
0
        public override void FromSnapshot(JediumBehaviourSnapshot snap)
        {
            if (snap.GetBehaviourType() != "UI")
            {
                Log.Warn($"Wrong snapshot type: {snap.GetBehaviourType()}");
            }

            JediumUISnapshot UISnap = (JediumUISnapshot)snap;

            this.dllName     = UISnap.dllName;
            this._bundleId   = UISnap.bundleId;
            this.xamlName    = UISnap.xamlName;
            this.archiveName = UISnap.archiveName;
        }
Ejemplo n.º 10
0
        public override void Init(JediumBehaviourSnapshot snapshot)
        {
            base.Init(snapshot);

            defaultUIPath = Path.Combine(Application.persistentDataPath, "UI");

            if (snapshot.BehaviourType != "UI")
            {
                return;
            }
            JediumUISnapshot t = (JediumUISnapshot)snapshot;

            this.dllName     = t.dllName;
            this.bundleId    = t.bundleId;
            this.xamlName    = t.xamlName;
            this.archiveName = t.archiveName;

            xamlPath = String.Empty;

            //check if base path exists
            if (!Directory.Exists(defaultUIPath))
            {
                Debug.Log("___CREATING UI PATH:" + defaultUIPath);
                Directory.CreateDirectory(defaultUIPath);
            }


            // string localPath = Path.Combine(Application.dataPath, "Resources", xamlName);

            string localPath = Path.Combine(defaultUIPath, xamlName);

            Debug.Log("___PATH 1:" + localPath);
            if (LoadXamlFromBundle(localPath))
            {
                xamlPath = Path.ChangeExtension(localPath, ".xaml");
            }
            Debug.Log("___PATH 2:" + xamlPath);
            // string archivePath = Path.Combine(Application.dataPath, "Resources", archiveName);

            string archivePath = Path.Combine(defaultUIPath, archiveName);

            string changedArchiveName = Path.ChangeExtension(archivePath, ".zip");

            Debug.Log("___PATH 3:" + changedArchiveName);

            LoadArchive(Path.Combine(changedArchiveName));

            Debug.Log("___Init");
            BindDependencies();
        }
Ejemplo n.º 11
0
        public Task SetBehaviourSnapshot(JediumBehaviourSnapshot snapshot)
        {
            _log.Info($"Setting snapshot for {snapshot.BehaviourType}");
            _gameObject.MarkedForSave = true;
            _gameObject.SetBehaviourFromSnapshot(snapshot);
            List <JediumBehaviourDBSnapshot> snaps = _gameObject.GetDbSnapshots();

            foreach (var s in snaps)
            {
                _log.Info($"Saving to DB: {s.LocalId}, {s.Type}");
                _database.StoreDBBehaviour(s).Wait();
            }

            return(Task.FromResult(true));
        }
        public override void Init(JediumBehaviourSnapshot snapshot)
        {
            base.Init(snapshot);

            if (snapshot.BehaviourType != "Transform")
            {
                return;
            }
            JediumTransformSnapshot t = (JediumTransformSnapshot)snapshot;

            _lastMessage = new JediumTransformMessage(t.X, t.Y, t.Z, t.RotX, t.RotY, t.RotZ, t.RotW, t.ScaleX, t.ScaleY, t.ScaleZ);

            transform.position   = new Vector3(t.X, t.Y, t.Z);
            transform.rotation   = new Quaternion(t.RotX, t.RotY, t.RotZ, t.RotW);
            transform.localScale = new Vector3(t.ScaleX, t.ScaleY, t.ScaleZ);
        }
Ejemplo n.º 13
0
        public override void Init(JediumBehaviourSnapshot snapshot)
        {
            base.Init(snapshot);


            if (snapshot.BehaviourType != "Take")
            {
                return;
            }
            JediumTakeSnapshot t = (JediumTakeSnapshot)snapshot;

            AttachPoint    = new Vector3(t.X, t.Y, t.Z);
            AttachRotation = new Quaternion(t.RotX, t.RotY, t.RotZ, t.RotW);

            Debug.Log("AttachP:" + AttachPoint);
            Debug.Log("AttachR: " + AttachRotation);
        }
Ejemplo n.º 14
0
        public override void FromSnapshot(JediumBehaviourSnapshot snap)
        {
            if (snap.GetBehaviourType() != "Take")
            {
                Log.Warn($"Wrong snapshot type: {snap.GetBehaviourType()}");
            }

            JediumTakeSnapshot takeSnap = (JediumTakeSnapshot)snap;

            posX = takeSnap.X;
            posY = takeSnap.Y;
            posZ = takeSnap.Z;
            RotX = takeSnap.RotX;
            RotY = takeSnap.RotY;
            RotZ = takeSnap.RotZ;
            RotW = takeSnap.RotW;
        }
Ejemplo n.º 15
0
        public override void FromSnapshot(JediumBehaviourSnapshot snap)
        {
            if (snap.GetBehaviourType() != "Transform")
            {
                _log.Warn($"Wrong snapshot type: {snap.GetBehaviourType()}");
                return;
            }

            JediumTransformSnapshot tsnap = (JediumTransformSnapshot)snap;

            _posX   = tsnap.X;
            _posY   = tsnap.Y;
            _posZ   = tsnap.Z;
            _quatX  = tsnap.RotX;
            _quatY  = tsnap.RotY;
            _quatZ  = tsnap.RotZ;
            _quatW  = tsnap.RotW;
            _scaleX = tsnap.ScaleX;
            _scaleY = tsnap.ScaleY;
            _scaleZ = tsnap.ScaleZ;
        }
        public override void Init(JediumBehaviourSnapshot snapshot)
        {
            base.Init(snapshot);
            _walkBeh = GetComponent <JediumCharacterAnimator>();


            if (Test.Instance._clientId == _parent.OwnerId)
            {
                //    JediumTransformBehaviour trans = GetComponent<JediumTransformBehaviour>();
                //   trans.AnimatorBased = true;
            }
            else
            {
                JediumTransformBehaviour trans = GetComponent <JediumTransformBehaviour>();
                trans.AnimatorBased = true;
                Animator a = GetComponent <Animator>();
                a.applyRootMotion = false;
            }

            _walkBeh.Init((Test.Instance._clientId == _parent.OwnerId));
        }
Ejemplo n.º 17
0
        public override void FromSnapshot(JediumBehaviourSnapshot snap)
        {
            if (snap.GetType() != typeof(JediumTransformSnapshot))
            {
                //warn
                return;
            }

            JediumTransformSnapshot tsnap = (JediumTransformSnapshot)snap;

            _posX   = tsnap.X;
            _posY   = tsnap.Y;
            _posZ   = tsnap.Z;
            _quatX  = tsnap.RotX;
            _quatY  = tsnap.RotY;
            _quatZ  = tsnap.RotZ;
            _quatW  = tsnap.RotW;
            _scaleX = tsnap.ScaleX;
            _scaleY = tsnap.ScaleY;
            _scaleZ = tsnap.ScaleZ;
        }
Ejemplo n.º 18
0
        public static int LoadBehaviours(string path)
        {
            int ret = 0;

            _log.Info("-----------Start loading behaviour plugins---------------");
            _log.Info($"Path:{path}");

            List <Assembly> assemblies = new List <Assembly>();

            foreach (string dll in Directory.GetFiles(path, "*.dll"))
            {
                if (!dll.Contains("Jedium.Behaviours.Shared"))
                {
                    AssemblyName an       = AssemblyName.GetAssemblyName(dll);
                    Assembly     assembly = Assembly.Load(an);
                    assemblies.Add(assembly);
                    _log.Info($"Loaded assembly:{dll}");
                }
            }

            Type behaviourType = typeof(JediumBehaviour);

            //load behaviours first
            foreach (var assembly in assemblies)
            {
                try
                {
                    List <Type> types = assembly.GetLoadableTypes().ToList();



                    foreach (Type t in types)
                    {
                        if (t.IsAbstract || t.IsInterface)
                        {
                            continue;
                        }
                        else
                        {
                            if (t.BaseType == behaviourType)
                            {
                                // JediumBehaviour jb = (JediumBehaviour)Activator.CreateInstance(t, new object[] { null }); //not possible - behaviour
                                GameObject go    = new GameObject();
                                var        jb    = (JediumBehaviour)go.AddComponent(t);
                                string     btype = jb.GetComponentType();
                                GameObject.DestroyImmediate(go);
                                BehaviourTypeRegistry.RegisteredBehaviourTypes.Add(btype, t);

                                _log.Info($"Added behaviour:{btype},{t}");
                                ret++;
                            }
                        }
                    }
                }
                catch (ReflectionTypeLoadException e)
                {
                    var    loaderExceptions = e.LoaderExceptions;
                    string estr             = "";
                    for (int i = 0; i < loaderExceptions.Length; i++)
                    {
                        estr = estr + loaderExceptions[i].Message;
                    }
                    Debug.LogError(estr);
                    throw;
                }
            }

            //then snapshots
            Type snapshotType = typeof(JediumBehaviourSnapshot);

            foreach (var assembly in assemblies)
            {
                Type[] types = assembly.GetTypes();

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

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

            _log.Info("-----------Finished loading behaviour plugins---------------");

            return(ret);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
 public abstract void FromSnapshot(JediumBehaviourSnapshot snap);
Ejemplo n.º 21
0
 //like Awake
 public virtual void Init(JediumBehaviourSnapshot snapshot)
 {
     _initialized = true;
 }
Ejemplo n.º 22
0
 public override void FromSnapshot(JediumBehaviourSnapshot snap)
 {
 }
Ejemplo n.º 23
0
 //editor-related
 public Task SetBehaviourSnapshot(JediumBehaviourSnapshot snapshot)
 {
     return(Task.FromResult(false));
 }