Exemple #1
0
            public static StDefaultComponent SaveState(WorldWalker walker)
            {
                var storedWalker = new StWorldWalker
                {
                    Enabled = walker.Enabled,
                    Path    = walker.Path?.Save()
                };

                return(new StDefaultComponent {
                    WorldWalker = storedWalker
                });
            }
Exemple #2
0
        /// <summary>
        /// Creates new WorldWalker and attaches it to the Unit and its node.
        /// </summary>
        /// <typeparam name="T">Unit plugin that implements the <see cref="IUser"/> interface required for this component.</typeparam>
        /// <param name="plugin">Unit plugin of the unit this WorldWalker should be attached to.</param>
        /// <param name="level">Current level.</param>
        /// <returns>The newly created WorldWalker instance.</returns>
        public static WorldWalker CreateNew <T>(T plugin, ILevelManager level)
            where T : UnitInstancePlugin, IUser
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            var newInstance = new WorldWalker(plugin, level);

            plugin.Entity.AddComponent(newInstance);
            return(newInstance);
        }
Exemple #3
0
            public override void StartLoading()
            {
                var user = plugin as IUser;

                if (user == null)
                {
                    throw new
                          ArgumentException($"provided plugin does not implement the {nameof(IUser)} interface", nameof(plugin));
                }

                if (storedData.ComponentCase != StDefaultComponent.ComponentOneofCase.WorldWalker)
                {
                    throw new ArgumentException("Invalid component type data passed to loader", nameof(storedData));
                }

                var storedWorldWalker = storedData.WorldWalker;

                Walker = new WorldWalker(user,
                                         level,
                                         storedWorldWalker.Enabled,
                                         storedWorldWalker.Path != null ? Path.Load(storedWorldWalker.Path, level) : null);
            }