Пример #1
0
    private void GenerateRandomLocations(int count, bool refresh)
    {
        if (!refresh && count <= _randomLocations.Length)
        {
            //Debug.Log($"Skip resize random points [{_randomPoints.Length} / {count}].");
            return;
        }

        //Debug.Log($"Create new set [{refresh}].");
        PlacementLocation[] newSet = new PlacementLocation[count];

        for (int idx = 0; idx < count; idx++)
        {
            if (refresh || idx >= _randomLocations.Length)
            {
                //Debug.Log($"Add new index: {idx}.");
                newSet[idx] = new PlacementLocation
                {
                    UnitLocation = Random.insideUnitCircle,
                    PrefabIndex  = GetRandomPrefabIndex(),
                    Orientation  = Quaternion.Euler(0, Random.value * 360, 0)
                };
            }
            else
            {
                //Debug.Log($"Copy old index: {idx}.");
                newSet[idx] = _randomLocations[idx];
            }
        }

        //Debug.Log("Apply new set.");
        _randomLocations = newSet;
    }
Пример #2
0
    void SetPlayerStartPlaceInMaze(short[,] maze)
    {
        int width   = maze.GetLength(0);
        int height  = maze.GetLength(1);
        int xCenter = width / 2;
        int yCenter = height / 2;

        maze[xCenter, yCenter]         = 0;
        maze[xCenter, yCenter + 1]     = 0;
        maze[xCenter, yCenter - 1]     = 0;
        maze[xCenter + 1, yCenter]     = 0;
        maze[xCenter + 1, yCenter + 1] = 0;
        maze[xCenter + 1, yCenter - 1] = 0;
        maze[xCenter - 1, yCenter]     = 0;
        maze[xCenter - 1, yCenter + 1] = 0;
        maze[xCenter - 1, yCenter - 1] = 0;

        if (level > 0)
        {
            maze[xCenter, yCenter] = 3;

            Transform         prevLevel = transform.parent.Find((level - 1).ToString());
            PlacementLocation prevExit  = prevLevel.gameObject.GetComponent <MazeGenerator>().exitPlacement;
            if (!prevExit.reversedHorizontally)
            {
                maze[xCenter + 1, yCenter] = 3;
            }
            else
            {
                maze[xCenter - 1, yCenter] = 3;
            }
        }
    }
Пример #3
0
 public virtual void ShowUpgrade(PlacementLocation placementLocation, UpgradableData upgradable)
 {
     PlacementManager.Instance.SetArea(AreaType.Build);
     PlacementManager.Instance.GetBuildArea().SetPlacementLocation(placementLocation);
     PlacementManager.Instance.GetBuildArea().SetUpgrading(upgradable);
     //UIManager.Instance.ShowUI(gameObject);
 }
Пример #4
0
    // Note: Should this be in a different script????
    public void PlaceObject()
    {
        int x = Screen.width / 2;
        int y = Screen.height / 2;

        Ray        ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(new Vector3(x, y));
        RaycastHit hit = new RaycastHit();

        Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);

        if (Physics.Raycast(ray, out hit))
        {
            //Debug.Log(hit.collider);
            Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue); // Drawing ray

            PlacementLocation pLoc = hit.collider.GetComponent <PlacementLocation>();
            // If the Object the ray hits is in the list of the Props valid locations
            // This should usually return false
            if (carriedObject != null && carriedObject.CheckLocation(pLoc, carriedObject.validLocations))
            {
                //change reticle
                Debug.Log("this is valid location");
                Debug.Log(carriedObject.CheckLocation(pLoc, carriedObject.validLocations));

                if (Input.GetMouseButtonDown(0))
                {
                    carriedObject.transform.position    = hit.transform.position;
                    carriedObject.transform.eulerAngles = hit.transform.eulerAngles;
                    carriedObject.objPlaced             = true;

                    DropObject();
                }
            }
        }
    }
Пример #5
0
    private void RenderModelAtLocation(GameObject activePrefab, PlacementLocation location)
    {
        Matrix4x4 rootOrientationMatrix = Matrix4x4.TRS(location.WorldPosition, location.Rotation, Vector3.one);         //, activePrefab.transform.localScale);

        MeshFilter[] filters = activePrefab.GetComponentsInChildren <MeshFilter>();

        foreach (MeshFilter filter in filters)
        {
            Matrix4x4 localOrientation = filter.transform.localToWorldMatrix;
            Matrix4x4 worldOrientation = rootOrientationMatrix * localOrientation;

            MeshRenderer renderer = filter.GetComponent <MeshRenderer>();
            Material     material = renderer.sharedMaterial;
            material.SetPass(0);

            Mesh mesh = filter.sharedMesh;
            Graphics.DrawMeshNow(mesh, worldOrientation);
        }


        //Material material = activePrefab.GetComponent<MeshRenderer>().sharedMaterial;
        //material.SetPass(0);
        //
        //Mesh mesh = activePrefab.GetComponent<MeshFilter>().sharedMesh;
        //Graphics.DrawMeshNow(mesh, rootOrientationMatrix);
    }
Пример #6
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(PlacementLocation != null ? PlacementLocation.ToStepValue() : "$");
            parameters.Add(PlacementRefDirection != null ? PlacementRefDirection.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
Пример #7
0
    void PlaceExit(short[,] maze)
    {
        short[,] exitPattern = new short[, ] {
            { 1, 1, 1 },
            { 1, 0, 0 },
            { 1, 1, 1 }
        };

        List <PlacementLocation> placements = GetPlacementLocations(exitPattern);
        PlacementLocation        selectedLocation;

        if (placements.Count != 0)
        {
            selectedLocation = placements[placements.Count > 1 ? rand.Next(0, placements.Count - 1) : 0];
        }
        else
        {
            if (level == 0)
            {
                selectedLocation = new PlacementLocation((int)Math.Floor(maze.GetLength(0) / 2.0), (int)Math.Floor(maze.GetLength(1) / 2.0), false, false);
            }
            else
            {
                Transform         prevLevel = transform.parent.Find((level - 1).ToString());
                PlacementLocation prevExit  = prevLevel.gameObject.GetComponent <MazeGenerator>().exitPlacement;
                selectedLocation = new PlacementLocation((int)Math.Floor(maze.GetLength(0) / 2.0), (int)Math.Floor(maze.GetLength(1) / 2.0), !prevExit.reversedHorizontally, false);
            }
        }
        this.exitPlacement = selectedLocation;
        Debug.Log("Exit is at: " + selectedLocation.ToString());

        maze[selectedLocation.x + 1, selectedLocation.y + 1] = 2;
        exit = GetLocation(selectedLocation.x + 1, selectedLocation.y + 1);
        if (!selectedLocation.reversedHorizontally)
        {
            maze[selectedLocation.x + 2, selectedLocation.y + 1] = 2;
        }
        else
        {
            maze[selectedLocation.x, selectedLocation.y + 1] = 2;
        }
        if (level > 0)
        {
            Transform prevLevel       = transform.parent.Find((level - 1).ToString());
            Vector3   prevExit        = prevLevel.gameObject.GetComponent <MazeGenerator>().exit;
            Vector3   currentPosition = prevLevel.localPosition;
            transform.localPosition = new Vector3(prevExit.x + currentPosition.x, transform.localPosition.y, prevExit.z + currentPosition.z);
        }

        Stairs.transform.localPosition = new Vector3(exit.x + (selectedLocation.reversedHorizontally ? -1f : 1f), -0.5f, exit.z);
        Stairs.transform.Rotate(0, selectedLocation.reversedHorizontally ? 180f: 0f, 0);
    }
Пример #8
0
    private void Xzabb_OnXZABBEnter(GameObject go1, GameObject other)
    {
        //Checks if the other XZABB has any placement locations
        PlacementLocation pl = other.GetComponentInParent <PlacementLocation>();

        if (pl == null)
        {
            return;
        }

        if (pl.GetIsValid(this))
        {
            //Sets the currentPlacementLocation to pl. This means that, if it's dropped, it will go there
            prospectivePL = pl;
        }
    }
Пример #9
0
    //When the object is let go, stop dragging it
    private void OnMouseUp()
    {
        OnDropped?.Invoke(this);
        xzabb.ClearCheckAgainst();

        isPickedUp = false;

        if (prospectivePL != currentPL)
        {
            prospectivePL.PlacePickUpable(this);
            currentPL.RemovePickUpable(this);
            currentPL = prospectivePL;
        }
        else
        {
            transform.localPosition = Vector3.zero;
        }
    }
Пример #10
0
    void PlaceBatteries()
    {
        short[,] cornerPattern = new short[, ]
        {
            { 1, 1, 1 },
            { 0, 0, 1 },
            { 1, 0, 1 }
        };

        List <PlacementLocation> placements = GetPlacementLocations(cornerPattern);

        bool alternativeLocation = false;

        if (placements.Count == 0)
        {
            cornerPattern = new short[, ]
            {
                { 0, 0 }
            };

            placements          = GetPlacementLocations(cornerPattern);
            alternativeLocation = true;
        }
        if (placements.Count > 0)
        {
            PlacementLocation selectedLocation = placements.Count > 1
                ? placements[rand.Next(0, placements.Count - 1)]
                : placements[0];

            int x = alternativeLocation
                ? selectedLocation.x
                : selectedLocation.x + 1;
            int y = alternativeLocation
                ? selectedLocation.y
                : selectedLocation.y + 1;

            maze[x, y] = 4;

            Transform  batteries = this.gameObject.transform.Find("Batteries");
            GameObject battery   = Instantiate(BatteryPrefab, batteries);
            battery.transform.localPosition = GetLocation(x, y);
        }
    }
Пример #11
0
    public bool CheckLocation(PlacementLocation loc, List <PlacementLocation> list)
    {
        // Iterate through list
        // Check if that transform is not in the list
        // If so, return true
        if (loc == null || list.Count.Equals(0))
        {
            return(false);
        }

        foreach (var t in list)
        {
            if (!list.Contains(loc))
            {
                return(false);
            }
        }

        return(true);
    }
Пример #12
0
    void PlaceScaryText()
    {
        short[,] corridorPattern = new short[, ]
        {
            { 1, 1, 1 },
            { 0, 0, 0 }
        };

        List <PlacementLocation> placements = GetPlacementLocations(corridorPattern);

        Transform texts = this.gameObject.transform.Find("Texts");

        if (placements.Count == 0)
        {
            return;
        }

        PlacementLocation selectedPlacement = placements.Count > 1
            ? placements[rand.Next(0, placements.Count - 1)]
            : placements[0];


        GameObject text = Instantiate(ScaryTextPrefab, texts);
        Vector3    position;

        text.GetComponent <TextMeshPro>().text = ScaryTexts[rand.Next(0, ScaryTexts.Length - 1)];
        if (selectedPlacement.reversedVertically)
        {
            position    = GetLocation(selectedPlacement.x + 1, selectedPlacement.y);
            position.z += 0.4999f;
        }
        else
        {
            position    = GetLocation(selectedPlacement.x + 1, selectedPlacement.y + 1);
            position.z -= 0.4999f;
            text.transform.Rotate(0, 180, 0);
        }
        position.y += .2f;
        text.transform.localPosition = position;
    }
Пример #13
0
 private void Xzabb_OnXZABBLeave(GameObject go1, GameObject go2)
 {
     prospectivePL = currentPL;
 }
Пример #14
0
 private void Awake()
 {
     dragPlane     = new Plane(Vector3.down, dragPlaneHeight);
     xzabb         = GetComponent <XZABB>();
     prospectivePL = currentPL;
 }
 public override Transform Transform()
 {
     return(Rhino.Geometry.Transform.ChangeBasis(PlacementLocation.LocationPlane(mDatabase.Tolerance), Plane.WorldXY));
 }
Пример #16
0
 public override void Show(PlacementLocation placementLocation)
 {
     PlacementManager.Instance.SetArea(AreaType.Cook);
     PlacementManager.Instance.GetCookArea().SetPlacementLocation(placementLocation);
     //UIManager.Instance.ShowUI(gameObject);
 }
Пример #17
0
 public void SetPlacementLocation(PlacementLocation placementLocation)
 {
     this.placementLocation = placementLocation;
 }
 void Awake()
 {
     location = GetComponent <PlacementLocation>();
 }