Esempio n. 1
0
        private void OnCreateRemoteObject(ref CreateRemoteObject p)
        {
            int index = p.Index;

            if ((index & 0xff) == localPlayerIndex)
            {
                return;
            }

            if (remoteActors.ContainsKey(index))
            {
                return;
            }

            EventType eventType = p.EventType;

            ushort[] eventParams = p.EventParams;
            Vector3  pos         = p.Pos;

            Root.DispatchToMainThread(delegate {
                ActorBase actor = EventSpawner.SpawnEvent(ActorInstantiationFlags.None, eventType, pos, eventParams);
                IRemotableActor remotableActor = actor as IRemotableActor;
                if (remotableActor == null)
                {
                    return;
                }

                remoteActors[index] = remotableActor;

                AddObject(actor);
            });
        }
Esempio n. 2
0
    //GameObject handle;
    //public Scrollbar scrollbar;

    void Start()
    {
        //UI = GameObject.Find ("Canvas");
        //handle = UI.transform.FindChild ("Scroll View").FindChild ("Scrollbar Vertical").FindChild ("Sliding Area").FindChild ("Handle").gameObject;
        content = this.transform.Find("Scroll View").Find("Viewport").Find("Content").gameObject;
        content.GetComponent <RectTransform> ().localPosition = Vector3.zero;
        EvSpa = GameObject.Find("EventSpawner").GetComponent <EventSpawner> ();

        Refresh();
    }
Esempio n. 3
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance == this)
     {
         Destroy(gameObject);
         return;
     }
     random = new System.Random();
 }
Esempio n. 4
0
        public LevelHandler(GameServer root, string episodeName, string levelName)
        {
            this.root = root;

            this.levelFileName = levelName;
            //this.episodeName = episodeName;
            difficulty = GameDifficulty.Multiplayer;

            gravity = DefaultGravity;

            collisions = new DynamicTreeBroadPhase <ActorBase>();

            eventSpawner = new EventSpawner(this);

            rootObject = new GameObject();
            rootObject.AddComponent(new LocalController(this));
            AddObject(rootObject);

            // Load level
            LoadLevel(levelFileName, episodeName);

            // Common sounds
            commonResources = ContentResolver.Current.RequestMetadata("Common/Scenery");

            // Preload frequently used metadata
            ContentResolver.Current.PreloadAsync("Common/Explosions");

            ContentResolver.Current.PreloadAsync("Interactive/PlayerJazz");
            ContentResolver.Current.PreloadAsync("Interactive/PlayerSpaz");
            ContentResolver.Current.PreloadAsync("Interactive/PlayerLori");

            ContentResolver.Current.PreloadAsync("Weapon/Blaster");
            ContentResolver.Current.PreloadAsync("Weapon/Bouncer");
            ContentResolver.Current.PreloadAsync("Weapon/Freezer");
            ContentResolver.Current.PreloadAsync("Weapon/Toaster");
            ContentResolver.Current.PreloadAsync("Weapon/RF");
            ContentResolver.Current.PreloadAsync("Weapon/Seeker");
            ContentResolver.Current.PreloadAsync("Weapon/TNT");
            ContentResolver.Current.PreloadAsync("Weapon/Pepper");
            ContentResolver.Current.PreloadAsync("Weapon/Electro");
            ContentResolver.Current.PreloadAsync("Weapon/Thunderbolt");
        }
Esempio n. 5
0
        //public bool isEvent;

        void Start()
        {
            EvSpa  = GameObject.Find("EventSpawner").GetComponent <EventSpawner> ();
            igLstr = transform.GetComponentInParent <igLister> ();
            btn    = gameObject.GetComponent <Button>();
            //btn = gameObject.GetComponent<UIElement> ();

            /*
             * if (btn.name.Equals ("Back")) {
             *      btn.onClick.AddListener (GoBack);
             * } else if (btn.name.Equals ("Refresh")) {
             *      btn.onClick.AddListener (Refresh);
             * } else {
             *      if (isEvent) {
             *              btn.onClick.AddListener (ChangeEvent);
             *      } else {
             *              btn.onClick.AddListener (ChangeRun);
             *      }
             * }*/
        }
Esempio n. 6
0
        public LevelHandler(App root, LevelInitialization data)
        {
            this.root = root;

            levelFileName = data.LevelName;
            episodeName   = data.EpisodeName;
            difficulty    = data.Difficulty;

            gravity = DefaultGravity;

            collisions = new DynamicTreeBroadPhase <ActorBase>();

            api          = new ActorApi(this);
            eventSpawner = new EventSpawner(api);

            rootObject = new GameObject();
            rootObject.AddComponent(new LocalController(this));
            AddObject(rootObject);

            // Load level
            LoadLevel(levelFileName, episodeName);

            // Create HUD
            Hud hud = rootObject.AddComponent <Hud>();

            // Process carry overs
            if (data.PlayerCarryOvers != null)
            {
                for (int i = 0; i < data.PlayerCarryOvers.Length; i++)
                {
                    Vector2 spawnPosition = eventMap.GetSpawnPosition(data.PlayerCarryOvers[i].Type);
                    if (spawnPosition == new Vector2(-1, -1))
                    {
                        spawnPosition = eventMap.GetSpawnPosition(PlayerType.Jazz);
                        if (spawnPosition == new Vector2(-1, -1))
                        {
                            continue;
                        }
                    }

                    Player player = new Player();
                    player.OnActivated(new ActorActivationDetails {
                        Api    = api,
                        Pos    = new Vector3(spawnPosition, PlayerZ),
                        Params = new[] { (ushort)data.PlayerCarryOvers[i].Type, (ushort)i }
                    });
                    AddPlayer(player);

                    if (i == 0)
                    {
                        player.AttachToHud(hud);
                    }

                    player.ReceiveLevelCarryOver(data.ExitType, ref data.PlayerCarryOvers[i]);
                }
            }

            Player  targetPlayer;
            Vector3 targetPlayerPosition;

            if (players.Count > 0)
            {
                targetPlayer         = players[0];
                targetPlayerPosition = targetPlayer.Transform.Pos;

                // Setup all cameras
                float relativeViewRange = (1f / players.Count);
                for (int i = 0; i < players.Count; i++)
                {
                    GameObject camera          = new GameObject(/*"MainCamera " + i*/);
                    Transform  cameraTransform = camera.AddComponent <Transform>();

                    Camera cameraInner = camera.AddComponent <Camera>();
                    cameraInner.NearZ          = NearZ;
                    cameraInner.FarZ           = FarZ;
                    cameraInner.Projection     = ProjectionMode.Orthographic;
                    cameraInner.VisibilityMask = VisibilityFlag.Group0 | VisibilityFlag.ScreenOverlay | (VisibilityFlag)(1 << i);

                    switch (players.Count)
                    {
                    case 1: cameraInner.TargetRect = new Rect(0f, 0f, 1f, 1f); break;

                    case 2: cameraInner.TargetRect = new Rect(0f, i * relativeViewRange, 1f, relativeViewRange); break;

                    case 3: cameraInner.TargetRect = new Rect(0f, i * relativeViewRange, 1f, relativeViewRange); break;

                    case 4: cameraInner.TargetRect = new Rect((i % 2) * 0.5f, (i / 2) * 0.5f, 0.5f, 0.5f); break;
                    }

                    // Create controller
                    CameraController cameraController = camera.AddComponent <CameraController>();
                    cameraController.ViewBounds = levelBounds;

                    // Bind camera to player
                    cameraInner.RenderingSetup = new LevelRenderSetup(this);

                    Player currentPlayer = players[i];
                    cameraTransform.Pos           = new Vector3(currentPlayer.Transform.Pos.Xy, 0);
                    cameraController.TargetObject = currentPlayer;

                    ((ICmpFixedUpdatable)cameraController).OnFixedUpdate(1f);
                    camera.Parent = rootObject;

                    cameras.Add(camera);

                    if (i == 0)
                    {
                        // First camera is always sound listener
                        DualityApp.Sound.Listener = camera;
                    }
                }
            }
            else
            {
                GameObject camera          = new GameObject(/*"MainCamera " + i*/);
                Transform  cameraTransform = camera.AddComponent <Transform>();

                Camera cameraInner = camera.AddComponent <Camera>();
                cameraInner.NearZ          = NearZ;
                cameraInner.FarZ           = FarZ;
                cameraInner.Projection     = ProjectionMode.Orthographic;
                cameraInner.VisibilityMask = VisibilityFlag.Group0 | VisibilityFlag.ScreenOverlay | (VisibilityFlag)(1 << 0);

                // Create controller
                CameraController cameraController = camera.AddComponent <CameraController>();
                cameraController.ViewBounds = levelBounds;

                // Bind camera to player
                cameraInner.RenderingSetup = new LevelRenderSetup(this);

                cameraTransform.Pos = new Vector3(levelBounds.Center, 0);

                ((ICmpUpdatable)cameraController).OnUpdate();
                camera.Parent = rootObject;

                cameras.Add(camera);

                // First camera is always sound listener
                DualityApp.Sound.Listener = camera;

                hud.BeginFadeIn(true);
            }

            // Common sounds
            commonResources = ContentResolver.Current.RequestMetadata("Common/Scenery");
        }
Esempio n. 7
0
        public LevelHandler(Controller root, LevelInitialization data)
        {
            this.root = root;

            //levelName = data.LevelName;
            levelFileName = data.LevelName;
            episodeName   = data.EpisodeName;
            difficulty    = data.Difficulty;

            gravity = DefaultGravity;

            collisions = new DynamicTreeBroadPhase();

            api          = new ActorApi(this);
            eventSpawner = new EventSpawner(api);

            rootObject = new GameObject("LevelManager");
            rootObject.AddComponent(new LocalController(this));
            AddObject(rootObject);

            // Setup camera
            camera = new GameObject("MainCamera");
            Transform cameraTransform = camera.AddComponent <Transform>();

            Camera cameraInner = camera.AddComponent <Camera>();

            cameraInner.NearZ       = NearZ;
            cameraInner.FarZ        = FarZ;
            cameraInner.Perspective = PerspectiveMode.Flat;

            CameraController cameraController = camera.AddComponent <CameraController>();

            // Load level
            LoadLevel(levelFileName, episodeName);

            // Process carry overs
            if (data.PlayerCarryOvers != null)
            {
                for (int i = 0; i < data.PlayerCarryOvers.Length; i++)
                {
                    Vector2 spawnPosition = eventMap.GetSpawnPosition(data.PlayerCarryOvers[i].Type);
                    if (spawnPosition == new Vector2(-1, -1))
                    {
                        spawnPosition = eventMap.GetSpawnPosition(PlayerType.Jazz);
                        if (spawnPosition == new Vector2(-1, -1))
                        {
                            continue;
                        }
                    }

                    Player player = new Player();
                    player.OnAttach(new ActorInstantiationDetails {
                        Api    = api,
                        Pos    = new Vector3(spawnPosition, PlayerZ),
                        Params = new[] { (ushort)data.PlayerCarryOvers[i].Type, (ushort)i }
                    });
                    AddPlayer(player);

                    player.ReceiveLevelCarryOver(data.ExitType, ref data.PlayerCarryOvers[i]);
                }
            }

            Player  targetPlayer;
            Vector3 targetPlayerPosition;

            if (players.Count > 0)
            {
                targetPlayer         = players[0];
                targetPlayerPosition = targetPlayer.Transform.Pos;
            }
            else
            {
                Debug.WriteLine("No spawn point found, used default location instead!");

                targetPlayerPosition = new Vector3(120, 160, PlayerZ);

                targetPlayer = new Player();
                targetPlayer.OnAttach(new ActorInstantiationDetails {
                    Api    = api,
                    Pos    = targetPlayerPosition,
                    Params = new[] { (ushort)PlayerType.Jazz, (ushort)0 }
                });
                AddPlayer(targetPlayer);
            }

            // Bind camera to player
            cameraInner.RenderingSetup = new LevelRenderSetup(this);

            cameraTransform.Pos = new Vector3(targetPlayerPosition.X, targetPlayerPosition.Y, 0);

            cameraController.TargetObject = targetPlayer;
            ((ICmpUpdatable)cameraController).OnUpdate();
            camera.Parent = rootObject;

            DualityApp.Sound.Listener = camera;

            // Attach player to UI
            targetPlayer.AttachToHud(rootObject.AddComponent <Hud>());

            // Common sounds
            commonResources = ContentResolver.Current.RequestMetadata("Common/Scenery");
        }
Esempio n. 8
0
 void Awake()
 {
     es = GameObject.Find("EventSpawner").GetComponent <EventSpawner> ();
     sm = GameObject.Find("SettingsManager").GetComponent <SettingsManager> ();
 }
Esempio n. 9
0
 void Awake()
 {
     // Initialise variables.
     Instance = this;
 }