Esempio n. 1
0
        CreateMethodDelegate
            (string methodName)
        {
            Type TargetType = Target.GetType();

            MyContract.RequireArgumentNotNull(TargetType, "targetType");
            MyContract.RequireFieldNotNull(Target, "Target");
            MethodInfo TargetMethodInfo
                = TargetType.GetMethod(methodName);

            MyContract.RequireArgument(
                TargetMethodInfo != null,
                "Is a method of the Target object",
                "Method " + methodName
                );

            return(delegate()
            {
                TargetMethodInfo.Invoke(Target, null);
            });
        }
        AnyShipDestroyedAction
            (Vector3 deathLocation,
             Vector3 deathEulerRotation)
        {
            Debug.Log("A player is dead!");

            // Create the explosion locally
            MyContract.RequireFieldNotNull(
                ExplosionPrefab,
                "ExplosionPrefab"
            );
            GameObject Explosion
                = Instantiate(
                    ExplosionPrefab,
                    deathLocation,
                    Quaternion.Euler(deathEulerRotation)
                );

            // Set self-destruct timer
            UnityEngine.GameObject.Destroy(Explosion, 2.0f);
        }
Esempio n. 3
0
        private Vector3 CalculateNewOffset(Vector2 rotationAngles)
        {
            MyContract.RequireFieldNotNull(
                PlanetCameraController, "PlanetCameraController"
                );
            MyContract.RequireFieldNotNull(
                PlanetCameraController.FollowTransform,
                "Follow Transform"
                );
            Vector3 CalculatedOffset
                = CalculateNewCameraOffset(
                      rotationAngles,
                      DesiredCameraOrbitRadius
                      );
            Vector3 NewOffset
                = PlanetCameraController
                  .FollowTransform
                  .InverseTransformDirection(CalculatedOffset);

            return(NewOffset);
        }
Esempio n. 4
0
        private void FadeAll(FadeFunction fadeFunction, Action fadeCallback)
        {
            MyContract.RequireFieldNotNull(CoroutineHost, "CoroutineHost");
            HashSet <int> ObjectsToFade    = new HashSet <int>();
            HashSet <int> FadedObjectsFlag = new HashSet <int>();

            foreach (var entry in RegisteredObjects)
            {
                Camera      Cam = entry.Value;
                int         Key = entry.Key;
                CameraFader FadeComponent
                    = Cam.gameObject.GetComponent <CameraFader>();

                if (FadeComponent != null)
                {
                    ObjectsToFade.Add(Key);
                    Action PartialFadeCallback = delegate()
                    {
                        FadedObjectsFlag.Add(Key);
                    };
                    fadeFunction(FadeComponent, PartialFadeCallback);
                }
                else
                {
                    //Debug.Log("Camera "
                    //        + Cam.gameObject.name
                    //        + " has no Camera Fader - Skipping");
                }
            }
            if (fadeCallback != null)
            {
                CoroutineHost.StartCoroutine(
                    FadeCallbackCoroutine(
                        ObjectsToFade,
                        FadedObjectsFlag,
                        fadeCallback
                        )
                    );
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Prerequisites: ssc_manager is instantiated
        /// </summary>
        private void InstantiateUIObjects()
        {
            PlayerScreenCanvas
                = GameObject.Instantiate(PlayerScreenCanvasPrefab);
            MyContract.RequireFieldNotNull(SSCManager, "SSCManager");

            ScreenSizeChangeTrigger SSCTrigger
                = PlayerScreenCanvas.GetComponent <ScreenSizeChangeTrigger>();

            if (SSCTrigger == null)
            {
                throw new InvalidOperationException(NO_SSCT_EXC);
            }
            SSCTrigger
            .ScreenResized
            .AddListener(SSCManager.OnScreenSizeChange);

            ComponentRegistry.KeyEnum = typeof(UIElements);
            ComponentRegistry.InitialiseAndRegisterUiPrefabs(
                UiComponentObjectPrefabs, SSCManager, PlayerScreenCanvas
                );
        }
Esempio n. 6
0
        private void InitialiseScreenFader()
        {
            CameraRegistry.CoroutineHost = this;
            ScreenFadeImageHost
            .transform
            .SetParent(PlayerScreenCanvas.transform, false);
            CameraFader Fader =
                CameraRegistry[(int)CameraRoles.FixedUi]
                .GetComponent <CameraFader>();

            MyContract.RequireFieldNotNull(
                Fader, "Fixed UI CameraFader component"
                );
            Fader.FadeImg = ScreenFadeImageHost.GetComponent <Image>();
            MyContract.RequireFieldNotNull(
                Fader.FadeImg, "ScreenFadeImageHost Image component"
                );
            PlayerScreenCanvas
            .GetComponent <ScreenSizeChangeTrigger>()
            .ScreenResizedInternal
            .AddListener(Fader.OnScreenSizeChange);
            Fader.OnScreenSizeChange(PlayerScreenCanvas.GetComponent <RectTransform>().rect);
        }
Esempio n. 7
0
        protected override void GenerateSelectionLabels()
        {
            SelectionNames = new List <string>();
            if (ObjectForMethodsToBeInvokedUpon != null ||
                TypeForMethodsToBeInvokedUpon != null)
            {
                MyContract.RequireFieldNotNull(MemberSourceType, "MemberSourceType");
                //Debug.Log("Got most derived type as " + MethodSourceType.ToString());
                var MemberSelection
                    = MemberSourceType
                      .GetFields(SelectionToShowFlags)
                      .Where(fi => fi.FieldType == typeof(UnityEvent))
                      .Select(fi => (MemberInfo)fi);
                Members = new List <MemberInfo>(MemberSelection);
                ClassHasNoRelevantMembersToShow = Members.Count == 0;
                if (ClassHasNoRelevantMembersToShow)
                {
                    Debug.Log("Class \""
                              + TypeForMethodsToBeInvokedUpon.ToString()
                              + "\" apparently has no UnityEvents.");
                }


                // Select guarantees the same ordering as the source
                // enumeration, so it's fine to use the index from
                // the selection_labels to index into the
                // listener_methods
                SelectionNames
                    = Members
                      .Select(x => x.Name)
                      .ToList();
            }
            else
            {
                //Debug.Log("Object is null, no SelectionLabels required");
            }
        }
Esempio n. 8
0
        private void ActivateUIElement(UIElements elementsToActivate, bool active)
        {
            MyContract.RequireArgument(
                elementsToActivate == UIElements.AccelerateButton ||
                elementsToActivate == UIElements.VirtualJoystick ||
                elementsToActivate == UIElements.FireButton ||
                elementsToActivate == UIElements.ClickInterceptor
                ,
                ActivateUIElementConditionDescription,
                "elementsToActivate"
                );
            GameObject go
                = ComponentRegistry[(int)elementsToActivate];

            MyContract.RequireFieldNotNull(
                go, elementsToActivate.ToString()
                );

            go.SetActive(active);
            foreach (Image i in go.GetComponentsInChildren <Image>())
            {
                i.raycastTarget = active;
            }
        }
Esempio n. 9
0
 public void PrintVariable(Rect variable)
 {
     MyContract.RequireArgumentNotNull(variable, "variable");
     MyContract.RequireFieldNotNull(Textbox, "textbox");
     Textbox.text = variable.ToString();
 }
 public Vector3 GetCurrentGameSolarSystemCoordinates()
 {
     MyContract.RequireFieldNotNull(Maths, "Maths");
     return(Maths.current_location_game_coordinates());
 }
Esempio n. 11
0
 // -- Methods --
 public void Start()
 {
     MyContract.RequireFieldNotNull(ScoreUiElementPrefab,
                                    "ScoreUiElementPrefab");
 }
Esempio n. 12
0
 public void setLayoutToMobile()
 {
     MyContract.RequireFieldNotNull(MobileLayout, "Mobile Layout");
     //Debug.Log("MainMenuManager setting layout to mobile");
     target_layout = MenuLayout.Mobile;
 }
        private void SpawnSpaceShip(SpaceShipClass spaceShipType)
        {
            lock (SpaceshipSpawnLock)
            {
                if (ShipSpawned)
                {
                    Debug.LogWarning(ShipAlreadySpawnedWarning);
                    return;
                }
                MyContract.RequireArgument(
                    spaceShipType != SpaceShipClass.NONE,
                    "is not NONE",
                    "spaceShipType"
                );
                MyContract.RequireFieldNotNull(
                    SpaceshipClassManager,
                    "Spaceship Class Manager"
                );
                GameObject SpaceshipPrefab
                    = SpaceshipClassManager.getSpaceShipPrefab(spaceShipType);
                MyContract.RequireFieldNotNull(SpaceshipPrefab, "Spaceship Prefab");

                // Should not remain null unless Unity.Instantiate can return null
                GameObject ServerSpaceship = null;
                if (CurrentSpaceship != null
                && ShipController.getSpaceshipClass() == spaceShipType)
                {
                    // current_spaceship was just despawned, not destroyed,
                    // so it simply needs to be respawned
                    ServerSpaceship = CurrentSpaceship;
                    ServerSpaceship.SetActive(true);
                    MyContract.RequireFieldNotNull(
                        ShipController,
                        "ShipController"
                    );
                    ShipController.Respawn();
                }
                else
                {
                    // Create the ship locally (local to the server)
                    // NB: the ship will be moved to an appropriate NetworkStartPosition
                    //     by the server so the location specified here is irrelevant
                    ServerSpaceship = (GameObject)Instantiate(
                        SpaceshipPrefab,
                        transform.TransformPoint(chooseSpawnLocation()),
                        transform.rotation);

                    ShipController = ServerSpaceship.GetComponent<PlayerShipController>();
                    ShipController.SetSpaceshipClass(spaceShipType);
                    ShipController.owner = PlayerIdentifier.CreateNew(this);
                    ShipController.EventDeath += ShipDestroyedServerAction;
                }
                MyContract.RequireFieldNotNull(
                    ServerSpaceship,
                    "Server Spaceship"
                );
                CanRespawn = false;
                ShipSpawned = true;

                // Spawn the ship on the clients
                NetworkServer.SpawnWithClientAuthority(
                    ServerSpaceship,
                    connectionToClient
                );
                CurrentSpaceship = ServerSpaceship; // Update [SyncVar]
                RpcPlayerShipSpawned(CurrentSpaceship);
            }
        }
Esempio n. 14
0
 public void setLayoutToDesktop()
 {
     MyContract.RequireFieldNotNull(DesktopLayout, "Desktop Layout");
     //Debug.Log("MainMenuManager setting layout to desktop");
     target_layout = MenuLayout.Desktop;
 }
Esempio n. 15
0
 public void UpdateValue(float newValue)
 {
     MyContract.RequireFieldNotNull(Slider, "Slider");
     Slider.value = newValue;
 }
 private void ToggleButton(ToggleSettingManager tsm, string settingName)
 {
     MyContract.RequireFieldNotNull(tsm, settingName);
     tsm.Toggle();
 }
Esempio n. 17
0
 public void Start()
 {
     MyContract.RequireFieldNotNull(OutputTextBox, "Output Textbox");
     timer.Start();
 }
 DisplayToggleSettingState
     (ToggleSettingManager tsm, string settingName, bool on)
 {
     MyContract.RequireFieldNotNull(tsm, settingName);
     tsm.SetInitialToggleGraphicState(on);
 }