Example #1
0
        public void RuleNeighborUpdate(Rect rect, RuleTilePlus.TilingRule tilingRule, Dictionary <Vector3Int, int> neighbors, Vector3Int position)
        {
            if (Event.current.type == EventType.MouseDown && ContainsMousePosition(rect))
            {
                var allConsts      = tile.m_NeighborType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                var neighborConsts = allConsts.Select(c => (int)c.GetValue(null)).ToList();
                neighborConsts.Sort();

                if (neighbors.ContainsKey(position))
                {
                    int oldIndex = neighborConsts.IndexOf(neighbors[position]);
                    int newIndex = oldIndex + GetMouseChange();
                    if (newIndex >= 0 && newIndex < neighborConsts.Count)
                    {
                        newIndex            = (int)Mathf.Repeat(newIndex, neighborConsts.Count);
                        neighbors[position] = neighborConsts[newIndex];
                    }
                    else
                    {
                        neighbors.Remove(position);
                    }
                }
                else
                {
                    neighbors.Add(position, neighborConsts[GetMouseChange() == 1 ? 0 : (neighborConsts.Count - 1)]);
                }
                tilingRule.ApplyNeighbors(neighbors);

                GUI.changed = true;
                Event.current.Use();
            }
        }
Example #2
0
 public void RuleTransformUpdate(Rect rect, RuleTilePlus.TilingRule tilingRule)
 {
     if (Event.current.type == EventType.MouseDown && ContainsMousePosition(rect))
     {
         tilingRule.m_RuleTransform = (RuleTilePlus.TilingRule.Transform)(int) Mathf.Repeat((int)tilingRule.m_RuleTransform + GetMouseChange(), Enum.GetValues(typeof(RuleTilePlus.TilingRule.Transform)).Length);
         GUI.changed = true;
         Event.current.Use();
     }
 }
Example #3
0
 public void OnAddElement(ReorderableList list)
 {
     RuleTilePlus.TilingRule rule = new RuleTilePlus.TilingRule();
     rule.m_Output       = RuleTilePlus.TilingRule.OutputSprite.Single;
     rule.m_Sprites[0]   = tile.m_DefaultSprite;
     rule.m_GameObject   = tile.m_DefaultGameObject;
     rule.m_ColliderType = tile.m_DefaultColliderType;
     tile.m_TilingRules.Add(rule);
 }
Example #4
0
        public float GetElementHeight(RuleTilePlus.TilingRule rule)
        {
            BoundsInt bounds = GetRuleGUIBounds(rule.GetBounds(), rule);

            float inspectorHeight = GetElementHeight(rule as RuleTilePlus.TilingRuleOutput);
            float matrixHeight    = GetMatrixSize(bounds).y + 10f;

            return(Mathf.Max(inspectorHeight, matrixHeight));
        }
Example #5
0
 public virtual BoundsInt GetRuleGUIBounds(BoundsInt bounds, RuleTilePlus.TilingRule rule)
 {
     if (extendNeighbor)
     {
         bounds.xMin--;
         bounds.yMin--;
         bounds.xMax++;
         bounds.yMax++;
     }
     bounds.xMin = Mathf.Min(bounds.xMin, -1);
     bounds.yMin = Mathf.Min(bounds.yMin, -1);
     bounds.xMax = Mathf.Max(bounds.xMax, 2);
     bounds.yMax = Mathf.Max(bounds.yMax, 2);
     return(bounds);
 }
Example #6
0
        public virtual void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
        {
            RuleTilePlus.TilingRule rule = tile.m_TilingRules[index];
            BoundsInt bounds             = GetRuleGUIBounds(rule.GetBounds(), rule);

            float   yPos       = rect.yMin + 2f;
            float   height     = rect.height - k_PaddingBetweenRules;
            Vector2 matrixSize = GetMatrixSize(bounds);

            Rect spriteRect    = new Rect(rect.xMax - k_DefaultElementHeight - 5f, yPos, k_DefaultElementHeight, k_DefaultElementHeight);
            Rect matrixRect    = new Rect(rect.xMax - matrixSize.x - spriteRect.width - 10f, yPos, matrixSize.x, matrixSize.y);
            Rect inspectorRect = new Rect(rect.xMin, yPos, rect.width - matrixSize.x - spriteRect.width - 20f, height);

            RuleInspectorOnGUI(inspectorRect, rule);
            RuleMatrixOnGUI(tile, matrixRect, bounds, rule);
            SpriteOnGUI(spriteRect, rule);
        }
Example #7
0
 public void RuleMatrixIconOnGUI(RuleTilePlus.TilingRule tilingRule, Dictionary <Vector3Int, int> neighbors, Vector3Int pos, Rect rect)
 {
     using (var check = new EditorGUI.ChangeCheckScope()) {
         if (pos.x != 0 || pos.y != 0)
         {
             if (neighbors.ContainsKey(pos))
             {
                 RuleOnGUI(rect, pos, neighbors[pos]);
                 RuleTooltipOnGUI(rect, neighbors[pos]);
             }
             RuleNeighborUpdate(rect, tilingRule, neighbors, pos);
         }
         else
         {
             RuleTransformOnGUI(rect, tilingRule.m_RuleTransform);
             RuleTransformUpdate(rect, tilingRule);
         }
         if (check.changed)
         {
             tile.UpdateNeighborPositions();
         }
     }
 }
Example #8
0
        public virtual void RuleMatrixOnGUI(RuleTilePlus tile, Rect rect, BoundsInt bounds, RuleTilePlus.TilingRule tilingRule)
        {
            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);
            float w = rect.width / bounds.size.x;
            float h = rect.height / bounds.size.y;

            for (int y = 0; y <= bounds.size.y; y++)
            {
                float top = rect.yMin + y * h;
                Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top));
            }
            for (int x = 0; x <= bounds.size.x; x++)
            {
                float left = rect.xMin + x * w;
                Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax));
            }
            Handles.color = Color.white;

            var neighbors = tilingRule.GetNeighbors();

            for (int y = bounds.yMin; y < bounds.yMax; y++)
            {
                for (int x = bounds.xMin; x < bounds.xMax; x++)
                {
                    Vector3Int pos = new Vector3Int(x, y, 0);
                    Rect       r   = new Rect(rect.xMin + (x - bounds.xMin) * w, rect.yMin + (-y + bounds.yMax - 1) * h, w - 1, h - 1);
                    RuleMatrixIconOnGUI(tilingRule, neighbors, pos, r);
                }
            }
        }
Example #9
0
 public float GetElementHeight(int index)
 {
     RuleTilePlus.TilingRule rule = tile.m_TilingRules[index];
     return(GetElementHeight(rule));
 }