示例#1
0
    public PositionOrientation getSlotLocation(int slotNumber)
    {
        float angleAroundCircle = (slotNumber / (float)numberOfSlots) * 2f * Mathf.PI;
        float radius            = characterRadius / Mathf.Sin(Mathf.PI / numberOfSlots);

        PositionOrientation location = new PositionOrientation();

        location.position    = new Vector3(radius * -Mathf.Sin(angleAroundCircle), radius * Mathf.Cos(angleAroundCircle), 0);
        location.orientation = new Vector3(0, 0, angleAroundCircle * Mathf.Rad2Deg);

        return(location);
    }
示例#2
0
        // If position is not valid, look around until a valid position is found
        // Examine surrounding cells in a "snail pattern"
        private void AdjustToSuitableLocationInLayout(WordPositionLayout layout, IList <WordAndCanvas> wordAndCanvasList, IList <PositionOrientation> topLeftList, bool onlyValidPlacement)
        {
            // Internal helper to check all words
            bool CanPlaceAllWords(bool isOnlyValidPlacement)
            {
                for (int il = 0; il < wordAndCanvasList.Count; il++)
                {
                    var placmentStatus = EditorViewModel.CanPlaceWordAtPositionInLayout(layout, wordAndCanvasList[il].WordPosition, topLeftList[il]);
                    if (placmentStatus == PlaceWordStatus.Invalid || placmentStatus == PlaceWordStatus.TooClose && !isOnlyValidPlacement)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            if (!CanPlaceAllWords(onlyValidPlacement))
            {
                int st   = 1;
                int sign = 1;

                for (; ;)
                {
                    for (int i = 0; i < st; i++)
                    {
                        for (int il = 0; il < wordAndCanvasList.Count; il++)
                        {
                            topLeftList[il] = new PositionOrientation(topLeftList[il].StartRow, topLeftList[il].StartColumn + sign, m_Sel.WordAndCanvasList[il].WordPosition.IsVertical);
                        }
                        if (CanPlaceAllWords(true))
                        {
                            return;
                        }
                    }
                    for (int i = 0; i < st; i++)
                    {
                        for (int il = 0; il < wordAndCanvasList.Count; il++)
                        {
                            topLeftList[il] = new PositionOrientation(topLeftList[il].StartRow + sign, topLeftList[il].StartColumn, m_Sel.WordAndCanvasList[il].WordPosition.IsVertical);
                        }
                        if (CanPlaceAllWords(true))
                        {
                            return;
                        }
                    }
                    sign = -sign;
                    st++;
                }
            }
        }
示例#3
0
    public PositionOrientation getDriftOffset(List <SlotAssignment> slots)
    {
        PositionOrientation center = new PositionOrientation();


        foreach (SlotAssignment slot in slots)
        {
            PositionOrientation location = getSlotLocation(slot.slotNumber);
            center.position    += location.position;
            center.orientation += location.orientation;
        }

        center.position    *= 1f / (float)slots.Count;
        center.orientation *= 1f / (float)slots.Count;

        return(center);
    }
示例#4
0
 // Use this for initialization
 void Start()
 {
     pattern         = new FormationPattern(characterRadius, numberOfSlots);
     slotAssignments = new List <SlotAssignment> ();
     completedTunnel = new List <bool> ();
     for (int i = 0; i < numberOfSlots; i++)
     {
         SlotAssignment slot = new SlotAssignment();
         slot.slotNumber = i;
         slot.character  = Instantiate(unitPrefab);
         slotAssignments.Add(slot);
         completedTunnel.Add(false);
     }
     anchorPoint  = pattern.getDriftOffset(slotAssignments);
     currentIndex = 0;
     rbody        = GetComponent <Rigidbody2D> ();
     completed    = false;
     walls        = GameObject.FindGameObjectsWithTag("Wall");
 }
示例#5
0
 // Not immutable because of this
 public void SetNewPositionOrientation(PositionOrientation positionOrientation)
 {
     m_PositionOrientation = positionOrientation;
 }
示例#6
0
 public WordPosition(string word, string originalWord, PositionOrientation positionOrientation)
 {
     Word                  = word;
     OriginalWord          = originalWord;
     m_PositionOrientation = positionOrientation;
 }
示例#7
0
 internal static PlaceWordStatus CanPlaceWordAtPositionInLayout(WordPositionLayout layout, WordPosition wordPosition, PositionOrientation positionOrientation)
 {
     return(EditorModel.CanPlaceWordAtPositionInLayout(layout, wordPosition, positionOrientation));
 }
示例#8
0
        // Check if a WordPosition can be placed at specific location in given layout
        internal static PlaceWordStatus CanPlaceWordAtPositionInLayout(WordPositionLayout layout, WordPosition wordPosition, PositionOrientation position)
        {
            WordPosition testWordPosition = new WordPosition(wordPosition.Word, wordPosition.OriginalWord, position);

            return(layout.CanPlaceWord(testWordPosition, true));
        }