示例#1
0
    public float GetAngle(ScoringComponent Other)
    {
        float angle = Vector3.Angle(transform.forward, Other.transform.forward);

        if (Symmetry == SymmetryType.OneAxis)
        {
            angle = Mathf.Min(angle, 180f - angle);
        }
        else if (Symmetry == SymmetryType.TwoAxis)
        {
            angle = Mathf.Min(angle, 180f - angle, Mathf.Abs(90f - angle));
        }
        else if (Symmetry == SymmetryType.IgnoreRotation)
        {
            angle = 0f;
        }

        return(angle);
    }
示例#2
0
    private ScoringComponent[] DuplicateRoom(GameObject room)
    {
        var children = room.GetComponentsInChildren <ScoringComponent>();

        ScoringComponent[] scorings = new ScoringComponent[children.Length];
        for (int s = 0; s < children.Length; s++)
        {
            var child = children[s];
            RoomsProcessed++;

            if (MaterialsInitialized)
            {
                var mr   = child.GetComponent <MeshRenderer>();
                var mats = mr.materials;
                for (int m = 0; m < mats.Length; m++)
                {
                    mats[m] = FurnitureTextures[MaterialIndexes[child.ID]];
                }
                mr.materials = mats;
            }

            var Duplicate = Instantiate(child.gameObject, Vector3.zero, Quaternion.identity);
            Duplicate.transform.localScale = Vector3.one;
            scorings[s] = Duplicate.GetComponent <ScoringComponent>();

            float roomsRatio   = RoomsStayed / (float)RoomsProcessed;
            bool  keepNextRoom = true;

            if (roomsRatio / RoomStayChance > 1.1f)    // too many stayed
            {
                keepNextRoom = false;
            }
            else if (roomsRatio / RoomStayChance < 0.9f)    // too little stayed
            {
                keepNextRoom = true;
            }
            else if (Random.value < RoomStayChance)    // about right, so random
            {
                keepNextRoom = false;
            }

            if (keepNextRoom)
            {
                Duplicate.transform.position = child.transform.position;
                Duplicate.transform.rotation = child.transform.rotation;
                RoomsStayed++;
            }
            else
            {
                bool found = false;

                for (int i = 0; i < SizeX; i++)
                {
                    for (int j = 0; j < SizeZ; j++)
                    {
                        if (CanPlaceDuplicate(i, j,
                                              Mathf.RoundToInt(child.GridSize.x),
                                              Mathf.RoundToInt(child.GridSize.y)))
                        {
                            Vector2 offset = (child.GridSize + Vector2.one) * 0.5f;

                            Duplicate.transform.position = new Vector3(i + offset.x, 0f, j + offset.y);
                            i     = SizeX;
                            j     = SizeZ;
                            found = true;
                        }
                    }
                }

                if (!found)
                {
                    Duplicate.transform.position = child.transform.position;
                    Duplicate.transform.rotation = child.transform.rotation;
                    RoomsStayed++;
                }
            }
        }

        return(scorings);
    }
示例#3
0
 public float GetDistance(ScoringComponent Other)
 {
     return(Vector3.Distance(transform.position, Other.transform.position));
 }