Beispiel #1
0
    public PROPAGATION onMessage(string message, object data)
    {
        if (message == "RClick")
        {
            Vector3 position = (Vector3)data;
            if (mouseDownPosition == Misc.VECTOR3_NULL)
            {
                // Right click when no object is active for rerouting
                InformationBase selectedObject = InformationBase.GetInformationBaseAtPosition(position);
                if (selectedObject != null)
                {
                    GameObject rerouteGameObject = selectedObject.gameObject;
                    IReroute   componentIReroute = rerouteGameObject.GetComponent <IReroute>();
                    if (componentIReroute.isRerouteOk())
                    {
                        mouseDownPosition      = position;
                        RerouteInfo.gameObject = rerouteGameObject;
                        RerouteInfo.iReroute   = componentIReroute;
                        RerouteInfo.isVehicle  = selectedObject.type == InformationBase.TYPE_VEHICLE;
                        RerouteInfo.iReroute.pauseMovement();
                        RerouteInfo.isReroute    = false;
                        RerouteInfo.originalPath = RerouteInfo.iReroute.getPath();
                        RerouteInfo.positionOriginalPathHalos();
                        Vector3 objectPosition = rerouteGameObject.transform.position;
                        haloObject.transform.localPosition = new Vector3(objectPosition.x, objectPosition.y, 0f);
                        haloObject.SetActive(true);
                        originalParentObj.SetActive(true);
                        rerouteParentObj.SetActive(false);
                        inactivateHaloObjects(reroutePathHalos);
                    }
                    else
                    {
                        // Re-routing not accepted, play sound
                        GenericSoundEffects.playRerouteUnavailable();
                    }
                }
            }
            else
            {
                if (RerouteInfo.isReroute && RerouteInfo.reroutePath.Count > 0)
                {
                    RerouteInfo.iReroute.setPath(RerouteInfo.reroutePath);
                }
                haloObject.SetActive(false);
                originalParentObj.SetActive(false);
                rerouteParentObj.SetActive(false);
                inactivateHaloObjects(originalPathHalos);
                inactivateHaloObjects(reroutePathHalos);
                RerouteInfo.iReroute.resumeMovement();

                RerouteInfo.gameObject = null;
                RerouteInfo.iReroute   = null;
                mouseDownPosition      = Misc.VECTOR3_NULL;
            }
        }
        else if (message == "RMove")
        {
            if (RerouteInfo.gameObject != null)
            {
                Vector3 mousePos        = (Vector3)data;
                Vector3 objectScreenPos = Game.instance.objectToScreenPos(RerouteInfo.gameObject);
                float   moveFromObject  = Misc.getDistance(mousePos, objectScreenPos);
                if (moveFromObject >= DISTANCE_FOR_REROUTE)
                {
// Get re-route pos object
                    Vector2 mousePosVector2 = Game.instance.screenToWorldPosInBasePlane(mousePos);
                    Pos     pos             = NodeIndex.getPosClosestTo(mousePosVector2, RerouteInfo.isVehicle);

                    int pathPoints   = RerouteInfo.originalPath.Count;
                    Pos addToPathPos = null;
                    Pos targetPos    = RerouteInfo.originalPath[RerouteInfo.originalPath.Count - 1];
                    if (targetPos.Id == -1L)
                    {
                        addToPathPos = targetPos;
                        targetPos    = RerouteInfo.originalPath[RerouteInfo.originalPath.Count - 2];
                        pathPoints--;
                    }

                    if (pathPoints > 2)
                    {
                        Pos startPos = RerouteInfo.originalPath[1];
                        RerouteInfo.reroutePath = Game.calculateCurrentPaths(startPos, targetPos, RerouteInfo.originalPath[0], pos, RerouteInfo.isVehicle, !RerouteInfo.isVehicle);

                        if (RerouteInfo.reroutePath.Count > 0)
                        {
                            RerouteInfo.reroutePath.Insert(0, Game.createTmpPos(RerouteInfo.gameObject.transform.position));
                            if (addToPathPos != null)
                            {
                                // Remove last path, if endPos is on this wayReference
                                if (!RerouteInfo.isVehicle && RerouteInfo.gameObject.GetComponent <HumanLogic>().endWay.hasNodes(RerouteInfo.reroutePath[RerouteInfo.reroutePath.Count - 2], RerouteInfo.reroutePath[RerouteInfo.reroutePath.Count - 1]))
                                {
                                    RerouteInfo.reroutePath.RemoveAt(RerouteInfo.reroutePath.Count - 1);
                                }

                                // Human should walk to end pos (tmp Pos object)
                                RerouteInfo.reroutePath.Add(addToPathPos);
                            }
//                        if (!RerouteInfo.isVehicle && isGoingFrontAndBackOnWay(RerouteInfo.originalPath)) {
//                            RerouteInfo.reroutePath.RemoveAt(1);
//                        }
                            RerouteInfo.isReroute = true;
                            RerouteInfo.positionReroutePathHalos();
                            rerouteParentObj.SetActive(true);
                            originalParentObj.SetActive(false);
                            inactivateHaloObjects(originalPathHalos);
                        }
                        else
                        {
                            RerouteInfo.isReroute = false;
                            originalParentObj.SetActive(true);
                            rerouteParentObj.SetActive(false);
                            inactivateHaloObjects(reroutePathHalos);
                        }
                    }
                }
            }
            else if (RerouteInfo.isReroute)
            {
                RerouteInfo.isReroute = false;
                originalParentObj.SetActive(true);
                rerouteParentObj.SetActive(false);
                inactivateHaloObjects(reroutePathHalos);
            }
//            Debug.Log(objectScreenPos + " - " + mousePos);

//            Vector3 objectPosition = Game.getCameraPosition(pos);
//            haloObject.transform.localPosition = new Vector3(objectPosition.x, objectPosition.y, 0f);
//            haloObject.SetActive(true);
        }
        else if (message == "Graphics:quality")
        {
            float quality = Game.instance.graphicsQuality;
            numberOfHalosInPath = Mathf.FloorToInt(NUMBER_HALOS_MIN + (quality * (NUMBER_HALOS_MAX - NUMBER_HALOS_MIN)));
//            activateHaloObjects(originalPathHalos);
//            activateHaloObjects(reroutePathHalos);
        }
        return(PROPAGATION.DEFAULT);
    }