Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        /*if(!GetComponentInChildren<cakeslice.Outline>())
         * {
         *  outline = gameObject.AddComponent<cakeslice.Outline>();
         *          outline.enabled = false;
         * }
         * else outline = gameObject.GetComponentInChildren<cakeslice.Outline>();*/

        // make sure to copy material, so every clickable object can change its material independantely
        selectionCircle = ScriptedParent().GetComponentInChildren <Projector>();
        if (selectionCircle == null)
        {
            selectionCircle          = Instantiate(GameManager.Instance.selectionCirclePrefab, ScriptedParent()).GetComponent <Projector>();
            selectionCircle.material = new Material(selectionCircle.material);
            SetOutline(false);
        }
        if (selectionCircle.orthographicSize != radius)
        {
            SetSelectionCircleRadius(radius);
        }

        selectedOutline = true;
        highlightable   = true;
        showSmallInfo   = true;

        if (!customOrigin)
        {
            orgPosition = selectionCircle.transform.position;
        }

        ps = transform.GetComponent <PersonScript>();

        UpdateSelectionCircleMaterial();
    }
Exemplo n.º 2
0
    public PersonScript CreatePerson()
    {
        GameObject   person = Instantiate(PersonPrefab);
        PersonScript ps     = person.GetComponent <PersonScript>();

        ps.Eyes  = Eyes;
        ps.Shoes = Shoes;
        ps.Skin  = Skin;

        if (Random.value < hairProb)
        {
            ps.Hair = Hairs[Random.Range(0, Hairs.Length)];
        }
        if (Random.value < accProb)
        {
            ps.Accessory = Accessories[Random.Range(0, Accessories.Length)];
        }
        if (Random.value < outerProb)
        {
            ps.Outer = Outers[Random.Range(0, Outers.Length)];
        }
        ps.Top    = Tops[Random.Range(0, Tops.Length)];
        ps.Bottom = Bottoms[Random.Range(0, Bottoms.Length)];

        return(ps);
    }
Exemplo n.º 3
0
    void Spawn()
    {
        if (Constants.Endless)
        {
            spawnTimer = spawnTime;
            spawnTime *= Constants.EndlessSpawnDecay;

            int from = Random.Range(Constants.MinNote, Constants.MaxNote + 1);
            int to   = Random.Range(Constants.MinNote, Constants.MaxNote + 1);
            while (to == from)
            {
                to = Random.Range(Constants.MinNote, Constants.MaxNote + 1);
            }

            floorManager.LightOn(from, true);
            PersonScript person = factory.CreatePerson();
            person.Appear(from, to);
            clients.Add(person);
        }
        else
        {
            int from = Constants.Level[curIdx];
            int to   = Constants.Level[curIdx + 1];

            string noteName = PitchManager.NoteToName(from);
            UpText.text   = noteName;
            DownText.text = noteName;
            floorManager.LightOn(from, true);
            PlayNote(from);
            PersonScript person = factory.CreatePerson();
            person.Appear(from, to);
            clients.Add(person);
        }
    }
Exemplo n.º 4
0
 public bool Unemploy(PersonScript ps)
 {
     if (ps == null)
     {
         return(false);
     }
     return(gameBuilding.workingPeople.Remove(ps.Nr));
 }
Exemplo n.º 5
0
 public bool Employ(PersonScript ps)
 {
     if (ps == null)
     {
         return(false);
     }
     gameBuilding.workingPeople.Add(ps.Nr);
     return(true);
 }
    private void addAPerson(Vector2 xBorders, Vector2 yBorders)
    {
        Vector3 pos = new Vector3(Random.Range(xBorders.x, xBorders.y), Random.Range(yBorders.x, yBorders.y), 0f);

        GameObject person = GameObject.Instantiate(PersonPrefab, pos, new Quaternion(0, 0, 0, 0), PeopleContainer) as GameObject;

        person.transform.Find("PersonVisual").localScale = new Vector3(personScale, personScale, personScale);

        PersonScript PS = person.GetComponent <PersonScript>();

        PS.initialData(this);
    }
Exemplo n.º 7
0
 public void Hit(int damage, PersonScript attacker)
 {
     if (damage < 0)
     {
         Debug.Log("taken damage < 0 for anmial");
     }
     this.attacker             = attacker;
     gameAnimal.currentHealth -= damage;
     if (gameAnimal.currentHealth < 0)
     {
         gameAnimal.currentHealth = 0;
     }
 }
    private void updateQueue(QueueObj queueObj, int newSize, EleDirection?dir)
    {
        int sizeDiff = Mathf.Abs(newSize - queueObj.q.Count);

        if (newSize > queueObj.q.Count)
        {
            for (int i = 0; i < sizeDiff; i++)
            {
                GameObject currCicle = Instantiate(person);
                currCicle.transform.SetParent(this.transform);
                currCicle.SetActive(true);
                currCicle.transform.position = queueObj.offset - Vector3.right * xSpace * queueObj.q.Count;
                PersonScript currCircleScript = currCicle.GetComponent <PersonScript>();
                if (dir == EleDirection.UP)
                {
                    Transform arrowTransform = currCicle.transform.GetChild(0);
                    arrowTransform.gameObject.SetActive(true);
                }
                if (dir == EleDirection.DOWN)
                {
                    Transform arrowTransform = currCicle.transform.GetChild(0);
                    arrowTransform.Rotate(0, 0, 180, Space.Self);
                    arrowTransform.gameObject.SetActive(true);
                }
                queueObj.q.Enqueue(currCicle);
            }
        }
        if (newSize < queueObj.q.Count)
        {
            for (int i = 0; i < sizeDiff; i++)
            {
                lastPerson       = queueObj.q.Peek();
                lastPersonScript = lastPerson.GetComponent <PersonScript>();
                lastPersonScript.animateDestroy();
                //lastPerson.transform.position += xSpace * Vector3.right;
                //lastPerson.transform.SetParent(elevatorObj.transform);
                queueObj.q.Dequeue();
            }

            foreach (GameObject curr in queueObj.q)
            {
                personTransitionList.Add(new GameObjectTransition(curr, curr.transform.position + sizeDiff * Vector3.right * xSpace));
            }
        }
        else
        {
            return;
        }
    }
Exemplo n.º 9
0
    // Select people in rect
    public void SelectPeople(Rect selection)
    {
        if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
        {
            PersonScript.DeselectAll();
        }

        foreach (PersonScript ps in PersonScript.allPeople)
        {
            Vector3 pos = Camera.main.WorldToScreenPoint(ps.transform.position);
            if (selection.Contains(new Vector2(pos.x, pos.y)))
            {
                ps.OnSelect();
            }
        }
    }
Exemplo n.º 10
0
    public static void MouseOverClickableUnit(Transform script, ClickableUnit cu)
    {
        bool leftClick = Input.GetMouseButtonDown(0);

        //bool rightClick = Input.GetMouseButtonDown(1);

        // Handle UI Hover and Click stuff
        if (leftClick && !LeftClickHandled && cu.clickable)
        {
            PersonScript ps = script.GetComponent <PersonScript>();
            if (ps)
            {
                ps.OnClick();
            }
            LeftClickHandled = true;
        }
    }
Exemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        OpenPoints();
        for (int i = 0; i < num_people; i++)
        {
            Transform person;
            person = Instantiate(personPrefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
            PersonScript ps = person.gameObject.GetComponent <PersonScript>();

            Vector2[] person_points = new Vector2[num_points];
            for (int j = 0; j < num_points; j++)
            {
                person_points[j] = points[i, j];
            }
            ps.points = person_points;
        }
    }
Exemplo n.º 12
0
    public void GenerateLine(GameObject target)
    {
        //From the target, we get the name and a Vector3 position
        string       tarName = target.name;
        PersonScript person  = worldMover.continentsMain.transform.Find(tarName).GetComponent <PersonScript>();

        //Get the local version of the positions
        Vector3 localTar    = worldMover.curContinent.transform.InverseTransformPoint(target.transform.position);
        Vector3 localPlayer = worldMover.curContinent.transform.InverseTransformPoint(connectionManager.currentPlayer.transform.position);

        //Add local version of the points to a list and a reference on the relevant person
        List <Vector3> localPoints = new List <Vector3>()
        {
            localTar, localPlayer
        };

        worldMover.continentsMain.GetComponent <ContinentManager>().AddLine(localPoints);
        person.AddLine(localPoints);
    }
Exemplo n.º 13
0
    void Update()
    {
        inputState = (UIManager.Instance.InMenu() || ChatManager.IsChatActive()) ? 0 : (BuildManager.placing) ? 1 : 2;
        bool inputEnabled = inputState > 0;

        dx = 0;
        dy = 0;

        PersonScript sp = PersonScript.FirstSelectedPerson();

        if (cameraMode == 1 && sp == null)
        {
            cameraModeChanging = true;
            cameraMode         = 0;
        }

        if (inputEnabled)
        {
            float deltaAngle = 0f;
            if (Input.GetKey(KeyCode.E))
            {
                deltaAngle = -1;
            }
            else if (Input.GetKey(KeyCode.Q))
            {
                deltaAngle = 1;
            }
            lerpLookAtRotation += deltaAngle * rotateSpeed * Time.deltaTime;

            float scrollAmount = Input.GetAxis("Mouse ScrollWheel") * scrollSensitivity;
            if (invertedMousehweel)
            {
                scrollAmount *= -1f;
            }
            if (EventSystem.current.IsPointerOverGameObject())
            {
                scrollAmount = 0f;
            }

            if (Input.GetKey(KeyCode.A))
            {
                dx = -1;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                dx = 1;
            }
            else if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
            {
                dx = 0;
            }

            if (Input.GetKey(KeyCode.W))
            {
                dy = 1;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                dy = -1;
            }
            else if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S))
            {
                dy = 0;
            }

            // additional camera movement when in bird view
            if (cameraMode == 0)
            {
                cameraDistance += scrollAmount * -1f;
                cameraDistance  = Mathf.Clamp(cameraDistance, 0.5f, 12f);

                Vector3 mousePos            = Input.mousePosition;
                float   mouseMoveScreenPerc = 0.01f;
                float   border = Mathf.Max(8f, Screen.width * mouseMoveScreenPerc);
                bool    ed     = Application.isEditor;
                if (mousePos.x < border && (!ed || mousePos.x >= 0))
                {
                    dx = -1;
                }
                if (mousePos.x > Screen.width - border && (!ed || mousePos.x <= Screen.width))
                {
                    dx = 1;
                }
                if (mousePos.y < border && (!ed || mousePos.y >= 0))
                {
                    dy = -1;
                }
                if (mousePos.y > Screen.height - border && (!ed || mousePos.y <= Screen.height))
                {
                    dy = 1;
                }
            }
            else if (cameraMode == 1)
            {
                sp.Move(dx, dy);
                sp.Rotate(deltaAngle);
            }
        }

        // scale movement relatively to camera distance
        Vector3 delta = new Vector3(dx, 0, dy) * keyMoveSpeed * Mathf.Pow(cameraDistance, 0.3f) * Time.deltaTime;

        if (inputEnabled)
        {
            // center camera around average position of selected people to make them all visible
            if (PersonScript.selectedPeople.Count > 0)
            {
                if (Input.GetKey(KeyCode.Space))
                {
                    ZoomSelectedPeople();
                }

                /*else if(Input.GetKeyDown(KeyCode.Z))
                 * {
                 *  cameraMode = 1 - cameraMode;
                 *  cameraModeChanging = true;
                 *  ZoomSelectedPeople();
                 * }*/
            }
            else if (Input.GetKey(KeyCode.Space))
            {
                Instance.lerplookAtPosition = Grid.SpawnpointNode.Position;
                cameraDistance = 3f;
                cameraDistance = Mathf.Clamp(cameraDistance, 2f, 12f);
            }

            if (Input.GetMouseButtonDown(2))
            {
                bDragging = true;
                panOrigin = Camera.main.ScreenToViewportPoint(Input.mousePosition); //Get the ScreenVector the mouse clicked
            }

            if (Input.GetMouseButton(2))
            {
                // Get the difference between where the mouse clicked and where it moved
                Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition) - panOrigin;
                // Move the position of the camera to simulate a drag, speed * 10 for screen to worldspace conversion
                Vector3 newPos = -pos * panSpeed;
                //delta -=  new Vector3(newPos.x, 0, newPos.y);
                lerpLookAtRotation += Mathf.Clamp(newPos.x * 20f, -15f, 15f);
            }

            if (Input.GetMouseButtonUp(2))
            {
                bDragging = false;
            }
        }
        else
        {
            bDragging = false;
        }

        // birds eye view
        if (cameraMode == 0)
        {
            delta = Quaternion.AngleAxis(transform.rotation.eulerAngles.y, Vector3.up) * delta;

            lookAtRotation      = Mathf.Lerp(lookAtRotation, lerpLookAtRotation, Time.deltaTime * 5f);
            lerplookAtPosition += delta;
            lerplookAtPosition  = Vector3.ClampMagnitude(lerplookAtPosition, Grid.WIDTH / 2);
            lookAt.position     = Vector3.Lerp(lookAt.position, lerplookAtPosition, Time.deltaTime * 10f);

            Vector3 lookAtOffset = new Vector3(2 + 0.5f * cameraDistance, 0.5f + 1f * cameraDistance, 0);
            currentLookAtOffset = Vector3.Lerp(currentLookAtOffset, lookAtOffset, Time.deltaTime * 5f);
            Vector3 targetPos = lookAt.position + Quaternion.AngleAxis(lookAtRotation, Vector3.up) * currentLookAtOffset;
            if (cameraModeChanging)
            {
                transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * 5f);
                Quaternion targetRot = Quaternion.LookRotation(lookAt.position - transform.position);
                transform.rotation     = Quaternion.Lerp(oldRot, targetRot, camerModeChangingTime);
                camerModeChangingTime += Time.deltaTime * 3f;
                if (Vector3.Distance(transform.position, targetPos) <= 0.01f && Quaternion.Angle(transform.rotation, targetRot) <= 2f)
                {
                    cameraModeChanging = false;
                }
            }
            else
            {
                transform.position = targetPos;
                transform.LookAt(lookAt);
            }
        }
        else if (cameraMode == 1)
        {
            if (cameraModeChanging)
            {
                Transform target = sp.GetShoulderCamPos();
                transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * 5f);
                Quaternion targetRot = Quaternion.Euler(target.rotation.eulerAngles.x + 5, target.rotation.eulerAngles.y, target.rotation.eulerAngles.z);
                transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, Time.deltaTime * 5f);

                oldRot = transform.rotation;
                camerModeChangingTime = 0;

                // zoom out on this person
                lookAt.position    = target.position;
                lerpLookAtRotation = target.rotation.eulerAngles.y + 90;
                lookAtRotation     = lerpLookAtRotation;
            }
        }
    }
Exemplo n.º 14
0
    public static void CommitMsg()
    {
        if (!IsChatActive())
        {
            return;
        }

        string msgText = Instance.chatInput.text;

        if (msgText.Length == 0)
        {
            return;
        }
        MessageType type = MessageType.PlayerChat;

        if (msgText.StartsWith("/") && GameManager.IsDebugging())
        {
            // command
            type    = MessageType.Debug;
            msgText = msgText.Substring(1);
            string[] arguments = new string[0];
            if (msgText.Contains(" "))
            {
                arguments = msgText.Substring(msgText.IndexOf(' ') + 1).Split(' ');
                msgText   = msgText.Substring(0, msgText.IndexOf(' '));
            }
            switch (msgText.ToLower())
            {
            case "help":
                string resText = "";
                for (int i = 0; i < ResourceData.allResources.Count; i++)
                {
                    resText += i + "=" + ResourceData.allResources[i].name + " ,";
                }
                resText = resText.Substring(0, resText.Length - 2);
                msgText =
                    "Spielgeschwindigkeit verändern = /speed [faktor]" +
                    "\nJahre vergehen lassen = /years [jahre]" +
                    "\nRessourcen an ausgewählte Person = /give [resNr] [anzahl]\n" + resText +
                    "\nMännlichen Bewohner spawnen = /bornman [alter]" +
                    "\nWeiblichen Bewohner spawnen = /bornwoman [alter]" +
                    "\nGebäudekosten (de)aktivieren = /tcost";
                break;

            case "speed":
                try
                {
                    float fact = float.Parse(arguments[0]);
                    fact = Mathf.Clamp(fact, 0.1f, 5000);
                    GameManager.speedFactor = fact;
                    msgText = "Spielgeschwindigkeit auf " + fact + " gesetzt";
                }
                catch
                {
                    msgText = "Falsche Argumente!";
                    type    = MessageType.Error;
                }
                break;

            case "years":
                try
                {
                    int yrs = int.Parse(arguments[0]);
                    yrs = Mathf.Clamp(yrs, 1, 100);
                    GameManager.PassYears(yrs);
                    msgText = yrs + " Jahre sind vergangen";
                }
                catch
                {
                    msgText = "Falsche Argumente!";
                    type    = MessageType.Error;
                }
                break;

            case "give":
                try
                {
                    int id = int.Parse(arguments[0]);
                    int am = int.Parse(arguments[1]);
                    am = Mathf.Clamp(am, 0, 1000);
                    PersonScript ps = PersonScript.FirstSelectedPerson();
                    if (ps)
                    {
                        ps.SetInventory(new GameResources(id, am));
                        msgText = am + "x " + ps.InventoryMaterial.Name + " wurden " + ps.FirstName + "s Inventar hinzugefügt";
                    }
                    else
                    {
                        msgText = "Keine Person ausgewählt";
                        type    = MessageType.Error;
                    }
                }
                catch
                {
                    msgText = "Falsche Argumente!";
                    type    = MessageType.Error;
                }
                break;

            case "bornman":
            case "bornwoman":
                try
                {
                    Gender Gender = (msgText.ToLower() == "bornman") ? Gender.Male : Gender.Female;
                    int    age    = int.Parse(arguments[0]);
                    age = Mathf.Clamp(age, 0, 80);
                    GamePerson p = GameManager.village.PersonBirth(-1, Gender, age);
                    msgText = "Bewohner gespawnt: Name=" + p.firstName + ",Alter=" + p.age;
                }
                catch
                {
                    msgText = "Falsche Argumente!";
                    type    = MessageType.Error;
                }
                break;

            case "tcost":
                GameManager.noCost = !GameManager.noCost;
                msgText            = "Gebäudekosten " + (GameManager.noCost ? "de" : "") + "aktiviert";
                break;

            default:
                msgText = "Falscher Befehl!";
                type    = MessageType.Error;
                break;
            }
        }
        else
        {
            msgText = GameManager.Username + ": " + msgText;
        }

        Msg(msgText, type);
        Instance.chatInput.text = "";
        Instance.chatShowTime   = 0;
    }
Exemplo n.º 15
0
 protected void ShowPhoto(PersonScript person)
 {
     rawImage.texture = person.PhotoGO;
     rawImage.enabled = true;
 }
Exemplo n.º 16
0
    void LateUpdate()
    {
        // exit ui and building mode
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (BuildManager.placing)
            {
                BuildManager.EndPlacing();
            }
            else if (ChatManager.IsChatActive())
            {
                ChatManager.ToggleChat();
            }
            else
            {
                if (uiManager.InMenu())
                {
                    uiManager.ExitMenu();
                }
                else if (uiManager.HideObjectInfo())
                {
                }
                else if (uiManager.HidePersonInfo())
                {
                }
                else
                {
                    uiManager.ShowMenu(6);
                }
            }
        }

        if (!ChatManager.IsChatActive())
        {
            // open build menu if exactly one person is selected
            if (Input.GetKeyDown(KeyCode.B))
            {
                if (PersonScript.selectedPeople.Count == 1)
                {
                    uiManager.ShowMenu(7);
                }
            }

            // open job overview if no person selected
            if (Input.GetKeyDown(KeyCode.J))
            {
                if (PersonScript.selectedPeople.Count == 0)
                {
                    uiManager.ShowMenu(1);
                    uiManager.OnPopulationTab(1);
                }
            }

            // open minimap overview
            if (Input.GetKeyDown(KeyCode.M))
            {
                uiManager.ToggleMiniMap();
            }

            BuildingScript selb = uiManager.GetSelectedBuilding();
            // destroy building if selected
            if (Input.GetKeyDown(KeyCode.Period))
            {
                if (selb && !BuildManager.placing)
                {
                    /* TODO: show warning when destroying buildings */
                    //selb.DestroyBuilding();
                }
            }
            // move building if selected
            if (Input.GetKeyDown(KeyCode.Comma))
            {
                if (selb && !BuildManager.placing)
                {
                    BuildManager.StartMoving(selb);
                }
            }

            // Toggle Cheats
            if (Input.GetKeyDown(KeyCode.O))
            {
                GameManager.ToggleDebugging();
                ChatManager.Msg("Cheats " + (GameManager.IsDebugging() ? "aktiviert" : "deaktiviert"), MessageType.Debug);
            }

            // Toggle Deubg window
            if (Input.GetKeyDown(KeyCode.P))
            {
                UIManager.Instance.ShowMenu(10);
            }

            // Person Groups
            int numberInput = -1;
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                numberInput = 0;
            }
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                numberInput = 1;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                numberInput = 2;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                numberInput = 3;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                numberInput = 4;
            }
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                numberInput = 5;
            }
            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                numberInput = 6;
            }
            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                numberInput = 7;
            }
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                numberInput = 8;
            }
            if (Input.GetKeyDown(KeyCode.Alpha9))
            {
                numberInput = 9;
            }

            if (numberInput >= 0)
            {
                List <int> group = GameManager.GetPeopleGroup(numberInput);
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    group = new List <int>();
                    foreach (PersonScript ps in PersonScript.selectedPeople)
                    {
                        group.Add(ps.Nr);
                    }
                    GameManager.SetPeopleGroup(numberInput, group);
                    ChatManager.Msg("Personengruppe " + numberInput + " erstellt!");
                }
                else
                {
                    PersonScript.DeselectAll();
                    if (group != null)
                    {
                        foreach (PersonScript ps in PersonScript.allPeople)
                        {
                            if (group.Contains(ps.Nr))
                            {
                                ps.OnSelect();
                            }
                        }
                    }
                }
            }
        }
        // enter chat
        if (!IsInputFieldFocused() && Input.GetKeyDown(KeyCode.Return))
        {
            ChatManager.CommitMsg();
            ChatManager.ToggleChat();
        }

        // if click is not already handled, select units
        SelectUnits();

        LeftClickHandled  = false;
        RightClickHandled = false;
    }
Exemplo n.º 17
0
 void HandleMouseInput()
 {
     // deal with selecting characters, etc.
     if (Input.GetMouseButtonDown(0))
     {
         // left click down, see if they selected a character
         Vector3 mousePos = CameraScript.controlledCam.ScreenToWorldPoint(Input.mousePosition);
         mousePos.z = 0;
         PersonScript selected    = null;
         float        minDistance = maxSelectDistance;
         for (int i = 0; i < crew.Length; i++)
         {
             if (((crew[i].transform.position - mousePos).sqrMagnitude < minDistance))
             {
                 minDistance = (crew[i].transform.position - mousePos).sqrMagnitude;
                 selected    = crew[i];
             }
         }
         if (selected != null)
         {
             if (MouseInShip())
             {
                 // then do shit with them
                 selectedCrewMember      = selected;
                 currentPath             = new List <Vector2>();
                 currentPathLineRenderer = new List <Vector3>();
                 prevPoint = MousePoint();
                 currentPath.Add(prevPoint);
                 Vector3 pos = prevPoint; // to get the lines to draw at the correct depth
                 pos.z = zPositionOfLines;
                 currentPathLineRenderer.Add(pos);
                 lineRenderer.positionCount = 0;
                 selectedCrewMember.path.Clear();
                 selectedCrewMember.walkingToGoal = false;
             }
         }
         else
         {
             selectedCrewMember = null;
         }
     }
     else if (Input.GetMouseButton(0))
     {
         // then draw a path I guess?
         if (selectedCrewMember != null && MouseInShip() && (prevPoint - MousePoint()).magnitude > .2)
         {
             Vector2      dpos = MousePoint() - prevPoint;
             RaycastHit2D hit  = Physics2D.Raycast(prevPoint, dpos, dpos.magnitude);
             if (!hit)
             {
                 prevPoint = MousePoint();
                 currentPath.Add(MousePoint());
                 Vector3 pos = prevPoint; // to get the lines to draw at the correct depth
                 pos.z = zPositionOfLines;
                 currentPathLineRenderer.Add(pos);
                 lineRenderer.positionCount = currentPath.Count;
                 lineRenderer.SetPositions(currentPathLineRenderer.ToArray());
             }
         }
     }
     else if (Input.GetMouseButtonUp(0))
     {
         if (selectedCrewMember != null)
         {
             // set the current path
             selectedCrewMember.path          = currentPath;
             selectedCrewMember.walkingToGoal = false;
         }
     }
     else if (Input.GetMouseButtonDown(1))
     {
         // cancel the current path and deselect the crew member
         selectedCrewMember = null;
     }
 }
Exemplo n.º 18
0
    private List <string> linkedPeople = new List <string>(); //A list of all the names of the people we've linked to

    public void PersonClicked(PersonType person, GameObject clicked)
    {
        if (person == PersonType.Player)
        {
            Debug.Log("Player Selected!");
            playerSelected = true;
        }
        else
        {
            //If the player was selected first, make the connection and deselect the player
            if (playerSelected)
            {
                //Check that this person hasn't been linked to already
                PersonScript thisPerson = worldMover.continentsMain.transform.Find(clicked.name).GetComponent <PersonScript>();
                if (!PersonIsSelected(clicked.name))
                {
                    //Add the person to the list
                    linkedPeople.Add(clicked.name);

                    //Make or refresh the connection for this person by telling the Main version of it
                    thisPerson.MakeRefreshConnection();

                    //Increase the number of our links. If they are more than the required to run the Peak event, run it.
                    totalLinks++;
                    if (totalLinks >= gameEvents.peakReq)
                    {
                        gameEvents.CheckRunEvent(GameEvent.Peak);
                    }
                    else if (totalLinks == 1) //If there's only 1 link, see if it's our first and add to the music
                    {
                        gameEvents.CheckRunEvent(GameEvent.Connection);
                    }

                    //The music queue If statements
                    if (totalLinks <= 4)
                    {
                        gameEvents.RampAudio(MusicEvent.Connection1);
                    }
                    else if (totalLinks <= 9)
                    {
                        gameEvents.RampAudio(MusicEvent.Connection5);
                    }
                    else if (totalLinks >= 10)
                    {
                        gameEvents.RampAudio(MusicEvent.Connection10);
                    }

                    //Specific events for lover connections
                    if (thisPerson.thisPersonType == PersonType.Lover)
                    {
                        totalLovers++;
                        gameEvents.CheckRunEvent(GameEvent.Love);
                        gameEvents.RampAudio(MusicEvent.LoveConnection);
                    }

                    //Disable the line renderer going to the mouse pointer
                    currentPlayer.GetComponent <LineRenderer>().enabled = false; //Disable the line renderer
                    playerSelected = false;

                    //Render the line between the two clicked objects
                    lineDraw.GenerateLine(clicked);
                    //Since we just drew a new line, update the maps!
                    worldMover.UpdateContinents();
                }
                else //This character has already been linked to, and should at least get the benefits
                {
                    Debug.Log("This character is already linked!");

                    //Refresh the connection for this person
                    thisPerson.MakeRefreshConnection();

                    //Disable the line renderer going to the mouse pointer
                    currentPlayer.GetComponent <LineRenderer>().enabled = false; //Disable the line renderer
                    playerSelected = false;
                }
            }
        }
    }
Exemplo n.º 19
0
    // PRE: Building and game building have to be set before strat is called
    private void Start()
    {
        // set nr of building if not already given by game building
        if (gameBuilding.nr == -1)
        {
            gameBuilding.nr = allBuildingScripts.Count;
            BuildingScript par = Identify(ParentBuildingNr);
            if (par)
            {
                par.AddChildBuilding(this);
            }
        }

        // Update allBuildings collection
        allBuildingScripts.Add(this);
        tag = Building.Tag;

        // make building a clickable object
        //co = gameObject.AddComponent<ClickableObject>();
        // co.clickable = false;

        if (currentModel == null)
        {
            for (int i = 0; i < MaxStages; i++)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }
            SetCurrentModel();
        }

        audioSource = Instantiate(AudioManager.Instance.buildingAudioPrefab, transform).GetComponent <AudioSource>();

        // Add and disable Campfire script
        if (HasFire)
        {
            campfire            = gameObject.AddComponent <Campfire>();
            campfire.woodAmount = gameBuilding.campFireWoodAmount;
            campfire.enabled    = !Blueprint;
            if (Name == "Lagerfeuer")
            {
                campfire.SetIsBigCampfire(false);
            }
            else if (Name == "Grosse Feuerstelle")
            {
                campfire.SetIsBigCampfire(true);
            }

            audioSource.clip = AudioManager.Instance.campfire;
            audioSource.loop = true;
            //cf.maxIntensity = Mathf.Clamp(GridWidth, 1, 1.8f);
        }

        fieldPlant = NatureObject.Get("Korn");

        // init blueprint UI
        blueprintCanvas = transform.Find("CanvasBlueprint");
        panelMaterial   = new List <Transform>();
        textMaterial    = new List <Text>();
        for (int i = 0; i < blueprintCanvas.Find("Cost").childCount; i++)
        {
            Transform pm = blueprintCanvas.Find("Cost").GetChild(i);
            panelMaterial.Add(pm);
            textMaterial.Add(pm.Find("TextMat").GetComponent <Text>());
        }
        LayoutRebuilder.ForceRebuildLayoutImmediate(blueprintCanvas.GetComponent <RectTransform>());
        buildingMaterial  = meshRenderer.materials;
        blueprintMaterial = new Material[buildingMaterial.Length];
        for (int i = 0; i < buildingMaterial.Length; i++)
        {
            blueprintMaterial[i] = BuildManager.Instance.blueprintMaterial;
        }

        // Finish building if no costs
        if (BlueprintBuildCost.Count == 0)
        {
            FinishBuilding();
        }
        else
        {
            ChangeTerrainGround();
        }

        //blueprintCanvas.gameObject.SetActive(false);

        blueprintCanvas.gameObject.SetActive(false);

        // init range canvas
        rangeCanvas = transform.Find("CanvasRange").transform;
        rangeImage  = rangeCanvas.Find("Image").GetComponent <Image>();

        // Make selected person go build this building
        PersonScript ps = PersonScript.FirstSelectedPerson();

        if (ps)
        {
            ps.AddTargetTransform(transform, true);
        }

        // if building has a custom collision radius, disable default collider and add a capsule collider

        /*if (CollisionRadius > float.Epsilon)
         * {
         *  gameObject.AddComponent<CapsuleCollider>();
         *  myCollider.enabled = false;
         * }*/


        if (ViewRange > 0)
        {
            /* TODO: optimize code! */

            /*
             * foreach (NatureObjectScript p in Nature.nature)
             * {
             *  p.UpdateBuildingViewRange();
             * }
             * foreach (ItemScript p in ItemScript.allItemScripts)
             * {
             *  p.UpdateBuildingViewRange();
             * }
             * foreach (PersonScript p in PersonScript.wildPeople)
             * {
             *  p.UpdateBuildingViewRange();
             * }
             * foreach (AnimalScript a in AnimalScript.allAnimals)
             * {
             *  a.UpdateBuildingViewRange();
             * }*/

            gameObject.AddComponent <SimpleFogOfWar.FogOfWarInfluence>().ViewDistance = ViewRange;
        }

        // start coroutine
        StartCoroutine(GameBuildingTransform());

        //recruitingTroop = new List<Troop>();
    }
Exemplo n.º 20
0
    // update selection
    private void SelectUnits()
    {
        // only update if not building and pointer is not over a UI Element
        if (EventSystem.current.IsPointerOverGameObject() ||
            BuildManager.placing)
        {
            LeftClickHandled = true;
        }

        if (Input.GetMouseButtonDown(0) && !LeftClickHandled)
        {
            // mouse click is handled
            LeftClickHandled = true;

            dragging = true;

            // set start position of drag
            startPos = Input.mousePosition;
        }
        if (Input.GetMouseButtonUp(0) && dragging)
        {
            dragging = false;
            // if selection box is too small, just select highlighted person
            if (selection.width * selection.height >= 100)
            {
                SelectPeople(selection);
            }
            else
            {
                // only deselect units if shift-key is not hold
                if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
                {
                    PersonScript.DeselectAll();
                }
                foreach (PersonScript ps in PersonScript.allPeople)
                {
                    if (ps.highlighted)
                    {
                        ps.OnClick();
                    }
                }
            }

            // make the selectio nsquare invisible
            selectionBoxImage.gameObject.SetActive(false);
        }
        if (Input.GetMouseButton(0) && dragging)
        {
            // make the selection square visible
            if (!selectionBoxImage.gameObject.activeInHierarchy)
            {
                selectionBoxImage.gameObject.SetActive(true);
            }
            endPos = Input.mousePosition;

            // make sure the rect has non-negative size
            selection.xMin = startPos.x < endPos.x ? startPos.x : endPos.x;
            selection.xMax = startPos.x < endPos.x ? endPos.x : startPos.x;
            selection.yMin = startPos.y < endPos.y ? startPos.y : endPos.y;
            selection.yMax = startPos.y < endPos.y ? endPos.y : startPos.y;

            // set the selection square rectTransform
            selectionBoxImage.offsetMin = selection.min;
            selectionBoxImage.offsetMax = selection.max;
        }
    }