예제 #1
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);
                }
            }
        }
예제 #2
0
        public static void CopyAllRules(MenuCommand item)
        {
            RuleTilePlus tile = item.context as RuleTilePlus;

            if (tile == null)
            {
                return;
            }

            RuleTileRuleWrapper rulesWrapper = new RuleTileRuleWrapper();

            rulesWrapper.rules = tile.m_TilingRules;
            var rulesJson = EditorJsonUtility.ToJson(rulesWrapper);

            EditorGUIUtility.systemCopyBuffer = rulesJson;
        }
예제 #3
0
        public static void PasteRules(MenuCommand item)
        {
            RuleTilePlus tile = item.context as RuleTilePlus;

            if (tile == null)
            {
                return;
            }

            try {
                RuleTileRuleWrapper rulesWrapper = new RuleTileRuleWrapper();
                EditorJsonUtility.FromJsonOverwrite(EditorGUIUtility.systemCopyBuffer, rulesWrapper);
                tile.m_TilingRules.AddRange(rulesWrapper.rules);
            } catch (Exception) {
                Debug.LogError("Unable to paste rules from system copy buffer");
            }
        }
예제 #4
0
        public static List <RuleOverrideTile> FindAffectedOverrideTiles(RuleTilePlus target)
        {
            List <RuleOverrideTile> overrideTiles = new List <RuleOverrideTile>();

            string[] overrideTileGuids = AssetDatabase.FindAssets("t:" + typeof(RuleOverrideTile).Name);
            foreach (string overrideTileGuid in overrideTileGuids)
            {
                string           overrideTilePath = AssetDatabase.GUIDToAssetPath(overrideTileGuid);
                RuleOverrideTile overrideTile     = AssetDatabase.LoadAssetAtPath <RuleOverrideTile>(overrideTilePath);
                if (overrideTile.m_Tile == target)
                {
                    overrideTiles.Add(overrideTile);
                }
            }

            return(overrideTiles);
        }