Esempio n. 1
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform transform = entity.GetOrCreate <Transform>("Transform");

            entity.CannotSuspendByDistance = true;

            PlayerTrigger   trigger    = entity.GetOrCreate <PlayerTrigger>("Trigger");
            PlayerSpawn     spawn      = entity.GetOrCreate <PlayerSpawn>("PlayerSpawn");
            VoxelAttachable attachable = VoxelAttachable.MakeAttachable(entity, main);

            this.SetMain(entity, main);

            attachable.EditorProperties();

            if (main.EditorEnabled)
            {
                entity.Add("Spawn Here", new Command
                {
                    Action = delegate()
                    {
                        main.Spawner.StartSpawnPointGUID.Value = entity.GUID;
                        Action go = delegate()
                        {
                            main.EditorEnabled.Value = false;
                            IO.MapLoader.Load(main, main.MapFile);
                        };

                        Editor editor = main.Get("Editor").First().Get <Editor>();
                        if (editor.NeedsSave)
                        {
                            editor.SaveWithCallback(go);
                        }
                        else
                        {
                            go();
                        }
                    },
                }, Command.Perms.Executable);
            }

            spawn.Add(new TwoWayBinding <Vector3>(transform.Position, spawn.Position));
            spawn.Add(new Binding <float, Quaternion>(spawn.Rotation, delegate(Quaternion value)
            {
                Vector3 x = Vector3.Transform(Vector3.Forward, value);
                return(((float)Math.PI * -0.5f) - (float)Math.Atan2(x.Z, x.X));
            }, transform.Quaternion));
            spawn.EditorProperties();

            trigger.Enabled.Value = true;
            trigger.Add(new TwoWayBinding <Vector3>(transform.Position, trigger.Position));
            trigger.Add(new CommandBinding(trigger.PlayerEntered, spawn.Activate));

            trigger.EditorProperties();
        }