示例#1
0
 private void OnDrawGizmos()
 {
     if (showDebugInformation)
     {
         PatternView pv = GetComponent <PatternView>();
         if (matches != null)
         {
             foreach (Match m in matches)
             {
                 Gizmos.color = Color.yellow;
                 Vector3 p1 = pv.GetPositionInWorldSpace(m.position, pv.displayDelta);
                 Vector3 p2 = pv.GetPositionInWorldSpace(m.position + m.rule.leftSide.Size - Vector3Int.one, pv.displayDelta);
                 Gizmos.DrawWireCube((p1 + p2) / 2, (p2 - p1) + pv.displayDelta);
                 Gizmos.color = Preferences.RoomLabelColor;
                 GUI.color    = Preferences.RoomLabelColor;
                 Utils.DrawLabel(m.rule.name, p1);
             }
         }
     }
 }
        // method called from PatternView
        public void OnPatternChange()
        {
            PatternView patternView = GetComponent <PatternView>();
            Pattern     pattern     = patternView.pattern;
            GameObject  container   = Utils.CreateChildWithName(transform, "[GeneratedRooms]");

#if !UNITY_EDITOR
            if (executeInEditorOnly)
            {
                return;
            }
#endif
            foreach (Vector3Int position in Utils.IterateGrid3D(pattern.Size))
            {
                string[] tags = pattern.GetTile(position).Label.Split('_');
                if (tags.Length < 2)
                {
                    if (logWarnings)
                    {
                        Debug.LogWarning("Could not parse tile label: Label has to consist of at least two tags separated by an underscore.", gameObject);
                    }
                    continue;
                }
                string lastTag = tags[tags.Length - 1];

                if (lastTag == "")
                {
                    continue;
                }
                int rotation;
                try
                {
                    rotation = int.Parse(lastTag);
                }
                catch (System.FormatException)
                {
                    if (logWarnings)
                    {
                        Debug.LogWarning("Could not parse tile label: Last tag in label is not an integer.", gameObject);
                    }
                    continue;
                }
                catch (System.OverflowException)
                {
                    if (logWarnings)
                    {
                        Debug.LogWarning("Could not parse tile label: The rotation is fractional or out of the integer number range.", gameObject);
                    }
                    continue;
                }

                GameObject[] prefabs = prefabDictionary.ToPrefabs(tags);
                for (int i = 0; i < prefabs.Length - 1; i++)
                {
                    GameObject prefab = prefabs[i];

                    if (prefab == null)
                    {
                        if (logWarnings)
                        {
                            Debug.LogWarning("Could not parse tile label: Specified tag \"" + tags[0] + "\"does not exist.");
                        }
                        continue;
                    }

                    GameObject instance = Instantiate(
                        prefab,
                        patternView.GetPositionInWorldSpace(position, patternView.displayDelta),
                        Quaternion.Euler(0, rotation * 90, 0)
                        );
                    instance.transform.SetParent(container.transform, true);
                }
            }
        }