Beispiel #1
0
        public static void ResetRouting(Sim sim)
        {
            if (sim == null)
            {
                return;
            }

            SimRoutingComponent component = sim.SimRoutingComponent;

            if (component != null)
            {
                if (component.LockedDoorsDuringPlan != null && component.LockedDoorsDuringPlan.Count > 0)
                {
                    foreach (Door door in component.LockedDoorsDuringPlan)
                    {
                        if (door == null)
                        {
                            continue;
                        }

                        PortalComponent portalComponent = door.PortalComponent;
                        if (portalComponent != null)
                        {
                            portalComponent.FreeAllRoutingLanes();
                        }

                        door.SetObjectToReset();
                    }
                }

                component.LockedDoorsDuringPlan = new List <Door>();
            }
        }
Beispiel #2
0
    public static void ViewDestinationPortal(string scenePath, int destinationId)
    {
        // Check if we are already in the scene
        bool inSceneAlready = SceneManager.GetActiveScene().path == scenePath ||
                              SceneManager.GetSceneByPath(scenePath).IsValid();

        if (!inSceneAlready)
        {
            // Require that modified scenes be saved before proceeding
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return;
            }

            Scene nextScene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
            if (!nextScene.IsValid())
            {
                Debug.LogError("Could not find scene asset \"" + scenePath + "\"");
                return;
            }
        }

        PortalComponent destination = PortalComponentCache.GetPortal(destinationId);

        if (destination == null)
        {
            Debug.LogError("Could not find the portal with id = " + destinationId + " in \"" + scenePath + "\"");
            return;
        }

        Selection.activeGameObject = destination.gameObject;
        SceneView.FrameLastActiveSceneView();
    }
 public static GpPacket GenerateGpPacket(this PortalComponent portal) => new GpPacket
 {
     PositionX        = portal.SourceX,
     PositionY        = portal.SourceY,
     DestinationMapId = portal.DestinationMapId,
     PortalType       = portal.Type,
     PortalId         = portal.PortalId,
     IsDisabled       = portal.IsDisabled
 };
Beispiel #4
0
    public override void OnInspectorGUI()
    {
        PortalComponent tar = target as PortalComponent;

        SerializedProperty id = serializedObject.FindProperty("id");
        SerializedProperty destinationScene = serializedObject.FindProperty("destinationScene");
        SerializedProperty destinationId    = serializedObject.FindProperty("destinationId");

        bool wideLayout = EditorGUIUtility.currentViewWidth > 450f;

        bool wantViewDestinationPortal = false;

        EditorGUI.BeginChangeCheck();
        GUILayout.Space(10);
        Horizontal(wideLayout, () => {
            LabelWidth(40f, wideLayout, () => {
                Vertical(() => {
                    GUILayout.Label("My Properties", EditorStyles.boldLabel);
                    EditorGUILayout.PropertyField(id);
                });
            });

            GUILayout.Space(15);

            LabelWidth(130f, wideLayout, () => {
                Vertical(() => {
                    GUILayout.Label("Destination", EditorStyles.boldLabel);
                    EditorGUILayout.PropertyField(destinationScene);
                    Enabled(tar.destinationScene.ScenePath != string.Empty, () => {
                        EditorGUILayout.PropertyField(destinationId);
                        if (tar.destinationScene.ScenePath == tar.gameObject.scene.path && tar.destinationId == tar.id)
                        {
                            GUILayout.Label("This portal connects to itself", red);
                        }
                    });
                    Enabled(tar.destinationScene.ScenePath != string.Empty, () => {
                        GUILayout.Space(10);
                        if (GUILayout.Button("View destination portal", GUILayout.Height(25)))
                        {
                            // Call to ViewDestinationPortal must be deferred until after all GUI operations
                            wantViewDestinationPortal = true;
                        }
                    });
                });
            });
        });
        GUILayout.Space(10);
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }

        if (wantViewDestinationPortal)
        {
            ViewDestinationPortal(tar.destinationScene.ScenePath, tar.destinationId);
        }
    }
Beispiel #5
0
 public PortalEntity(PortalDto portal) : base(VisualType.Portal, portal.Id)
 {
     Portal     = new PortalComponent(this, portal);
     Components = new Dictionary <Type, IComponent>
     {
         { typeof(PortalComponent), Portal },
         { typeof(VisibilityComponent), new VisibilityComponent(this) }
     };
 }
Beispiel #6
0
        private void CreateWorld()
        {
            WorldHead = new PortalComponent("Black Hole");
            WorldHead.AddComponent(new PortalComponent("White Hole??"));
            IWorldComponent FirstLevel  = new LocationComponent(new Location("???", "easy", "i don`t know", "I DON`T KNOW!!", new List <string>()));
            IWorldComponent SecondLevel = new LocationComponent(new Location("Lviv", "easy", "12pm", "summer", new List <string>()));
            IWorldComponent Portal2     = new PortalComponent("!@)(*&(");

            FirstLevel.AddComponent(SecondLevel);
            SecondLevel.AddComponent(Portal2);
            WorldHead.AddComponent(FirstLevel);
        }
Beispiel #7
0
        protected override bool PrivatePerform(Door obj)
        {
            PortalComponent portalComponent = obj.PortalComponent;

            if (portalComponent != null)
            {
                portalComponent.FreeAllRoutingLanes();
            }

            obj.SetObjectToReset();

            return(true);
        }
 private void OnDrawGizmos()
 {
     GizmosUtils.DrawText(GUI.skin, " " + id, transform.position + Vector3.down * 1.5f, Color.yellow, 16, 0);
     if (destinationScene.ScenePath == this.gameObject.scene.path)
     {
         PortalComponent destinationPortalRef = PortalComponentCache.GetPortal(destinationId);
         if (destinationPortalRef != null)
         {
             GizmosUtils.DrawArrow(transform.position, destinationPortalRef.transform.position, Color.yellow, 2.0f);
         }
     }
     else if (destinationScene.ScenePath != string.Empty)
     {
         Gizmos.color = Color.yellow;
         Gizmos.DrawWireSphere(transform.position, 0.7f);
         Gizmos.DrawWireSphere(transform.position, 0.5f);
     }
 }
        public void Init()
        {
            GameObject[] portals        = GameObject.FindGameObjectsWithTag("Portal");
            var          channelDict    = new Dictionary <int, EcsEntity>();
            var          filledChannels = new HashSet <int>();

            foreach (GameObject portal in portals)
            {
                int?channelNum = GetChannelFrom(portal);
                if (!channelNum.HasValue)
                {
                    Debug.LogError($"Portal {portal.name} has wrong name!");
                    continue;
                }

                int channel = channelNum.Value;
                if (filledChannels.Contains(channel))
                {
                    Debug.LogError($"Channel {channel.ToString()} for portal {portal.name} already used!");
                    continue;
                }

                EcsEntity portalEntity = _ecsWorld.NewEntityWith(
                    out PortalComponent portalComponent,
                    out CreateWorldObjectEvent createEvt);
                createEvt.Transform = portal.transform;

                if (channelDict.ContainsKey(channel))
                {
                    filledChannels.Add(channel);
                    EcsEntity otherPortalEntity = channelDict[channel];
                    portalComponent.OtherPortalEntity = channelDict[channel];

                    PortalComponent otherPortal = otherPortalEntity.Get <PortalComponent>();
                    otherPortal.OtherPortalEntity = portalEntity;
                }
                else
                {
                    channelDict.Add(channel, portalEntity);
                }
            }
        }
Beispiel #10
0
        public void Run()
        {
            WorldComponent world = _world.Components1[0];

            foreach (int i in _moveableObjects)
            {
                Vector2Int newPosition   = _moveableObjects.Components1[i].NewPosition;
                int        movableEntity = _moveableObjects.Entities[i];

                foreach (int entity in world.WorldField[newPosition.x][newPosition.y])
                {
                    var portal = _ecsWorld.GetComponent <PortalComponent>(entity);
                    if (portal == null || portal.EstimateReloadTime > 0)
                    {
                        continue;
                    }

                    int otherPortalEntity = portal.OtherPortalEntity;
                    var otherPortal       = _ecsWorld.GetComponent <PortalComponent>(otherPortalEntity);

                    Vector2Int otherPortalPosition = _ecsWorld
                                                     .GetComponent <PositionComponent>(otherPortalEntity)
                                                     .Position;
                    _ecsWorld.AddComponent <TeleportingComponent>(movableEntity).NewPosition = otherPortalPosition;

                    portal.EstimateReloadTime      = PORTAL_RELOAD_TIME;
                    otherPortal.EstimateReloadTime = PORTAL_RELOAD_TIME;
                }
            }

            foreach (int i in _portals)
            {
                PortalComponent portalComponent = _portals.Components1[i];
                if (portalComponent.EstimateReloadTime > 0)
                {
                    portalComponent.EstimateReloadTime -= Time.deltaTime;
                }
            }
        }
Beispiel #11
0
        public void Run()
        {
            foreach (int i in _moveObjects)
            {
                Vector2Int newPosition   = _moveObjects.Get1[i].NewPosition;
                EcsEntity  movableEntity = _moveObjects.Entities[i];

                foreach (EcsEntity entity in _worldService.WorldField[newPosition.x][newPosition.y])
                {
                    var portal = entity.Get <PortalComponent>();
                    if (portal == null || portal.EstimateReloadTime > 0)
                    {
                        continue;
                    }

                    EcsEntity otherPortalEntity = portal.OtherPortalEntity;
                    var       otherPortal       = otherPortalEntity.Get <PortalComponent>();

                    Vector2Int otherPortalPosition = otherPortalEntity.Get <PositionComponent>().Position;
                    movableEntity.Set <TeleportedComponent>().NewPosition = otherPortalPosition;

                    portal.EstimateReloadTime      = _gameDefinitions.portalDefinition.portalReloadTime;
                    otherPortal.EstimateReloadTime = _gameDefinitions.portalDefinition.portalReloadTime;
                }
            }

            float dt = Time.deltaTime;

            foreach (int i in _portals)
            {
                PortalComponent portalComponent = _portals.Get1[i];
                if (portalComponent.EstimateReloadTime > 0)
                {
                    portalComponent.EstimateReloadTime -= dt;
                }
            }
        }
    private IEnumerator TeleportOperation(string scenePath, int id, Scene[] scenesToUnload)
    {
        // Exit early if scene cannot be found in build settings
        if (SceneUtility.GetBuildIndexByScenePath(scenePath) == -1)
        {
            Debug.LogError("The scene " + scenePath + " could not be found in the build settings. This error happens fairly often and can be fixed easily. Just clear all scenes from your build setting, and drag the scenes back into the build settings.");
            teleporting = false;
            yield break;
        }

        if (OnTeleportStart != null)
        {
            OnTeleportStart(scenePath);
        }

        // Change scenes if necessary
        if (SceneManager.GetActiveScene().path != scenePath)
        {
            // Start scene operations for loading the next scene and unloading the specified scenes
            List <AsyncOperation> sceneOperations = new List <AsyncOperation> ();
            if (scenesToUnload != null)
            {
                foreach (Scene s in scenesToUnload)
                {
                    sceneOperations.Add(SceneManager.UnloadSceneAsync(s));
                }
            }

            // Load next scene
            AsyncOperation nextSceneLoad = SceneManager.LoadSceneAsync(scenePath, LoadSceneMode.Additive);
            nextSceneLoad.allowSceneActivation = false;

            // Wait for all scene operations to finish
            foreach (AsyncOperation s in sceneOperations)
            {
                yield return(new WaitUntil(() => s.isDone));
            }

            // Wait for next scene to finish loading
            yield return(new WaitUntil(() => nextSceneLoad.progress >= 0.9f));

            // Wait until scene activation is allowed
            yield return(new WaitUntil(() => allowSceneActivation));

            // Activate next scene
            nextSceneLoad.allowSceneActivation = true;
            yield return(new WaitUntil(() => nextSceneLoad.isDone));

            SceneManager.SetActiveScene(SceneManager.GetSceneByPath(scenePath));
        }

        PortalComponent exitPortal = PortalComponentCache.GetPortal(id);

        if (exitPortal == null)
        {
            Debug.LogError("Could not find destination portal with id = " + id + " in scene \"" + SceneManager.GetActiveScene().path + "\"");
        }
        else
        {
            exitPortal.Exit();
        }

        teleporting = false;

        if (OnTeleportFinish != null)
        {
            OnTeleportFinish(scenePath);
        }
    }