예제 #1
0
    private void OnValidate()
    {
        CheckTileType(ref Structure, LayerType.Walls, LayerType.Windows);
        CheckTileType(ref Object, LayerType.Objects);
        CheckTileType(ref Floor, LayerType.Floors);
        CheckTileType(ref Base, LayerType.Base);

        if (Structure != _structureCurrent || Object != _objectCurrent || Floor != _floorCurrent ||
            Base != _baseCurrent)
        {
            if (_structureCurrent == null && _objectCurrent == null && _floorCurrent == null &&
                _baseCurrent == null)
            {
                // if everything is null, it could be that it's loading on startup, so there already should be an preview sprite to load
                EditorApplication.delayCall += () =>
                {
                    PreviewSprite = PreviewSpriteBuilder.LoadSprite(this) ?? PreviewSpriteBuilder.Create(this);
                    ;
                };
            }
            else
            {
                // something changed, so create a new preview sprite
                EditorApplication.delayCall += () => { PreviewSprite = PreviewSpriteBuilder.Create(this); };
            }
        }

        _structureCurrent = Structure;
        _objectCurrent    = Object;
        _floorCurrent     = Floor;
        _baseCurrent      = Base;
    }
예제 #2
0
        private void OnValidate()
        {
            if (Object != null)
            {
                if (_objectCurrent == null)
                {
                    // if sprite already exists (e.g. at startup), then load it, otherwise create a new one
                    EditorApplication.delayCall += () => { PreviewSprite = PreviewSpriteBuilder.LoadSprite(Object) ?? PreviewSpriteBuilder.Create(Object); };
                }
                else if (Object != _objectCurrent)
                {
                    // from one object -> other (overwrite current sprite)
                    EditorApplication.delayCall += () => { PreviewSprite = PreviewSpriteBuilder.Create(Object); };
                }
            }
            else if (_objectCurrent != null)
            {
                // setting to None object (delete current sprite)
                var obj = _objectCurrent;
                EditorApplication.delayCall += () => { PreviewSpriteBuilder.DeleteSprite(obj); };
            }

            _objectCurrent = Object;

            if (_objectCurrent != null)
            {
                IsItem = _objectCurrent.GetComponentInChildren <RegisterItem>() != null;
            }
        }
예제 #3
0
    public static void GenerateTiles(string subject)
    {
        //Moving old tiles
        string basePath  = Application.dataPath + "/Resources/Prefabs/";
        string basePath2 = basePath + subject + "/";
        //			Debug.Log (basePath2);
        int counter = 0;
        int created = 0;

        string[] scan = Directory.GetFiles(basePath2, "*.prefab", SearchOption.AllDirectories);
        foreach (string file in scan)
        {
            counter++;
            int t = scan.Length;
            EditorUtility.DisplayProgressBar(counter + "/" + scan.Length + " Generating Tiles for " + subject, "Tile: " + counter,
                                             counter / (float)scan.Length);
            //			Debug.Log ("Longpath data: " + file);

            //Get the filename without extention and path
            string name = Path.GetFileNameWithoutExtension(file);
            //			Debug.Log ("Creating tile for prefab: " + name);

            //Generating the path needed to hook onto for selecting the game object
            string smallPath = file.Substring(file.IndexOf("Assets") + 0);
            //			Debug.Log ("smallpath data: " + smallPath);


            //Generating the path needed to chose the right tile output sub-folder
            string subPath = smallPath.Substring(smallPath.IndexOf(subject) + 7);
            //			Debug.Log ("subPath data: " + subPath);
            string barePath = subPath.Substring(0, subPath.LastIndexOf(Path.DirectorySeparatorChar));
            //			Debug.Log ("barePath data: " + barePath);

            //Check if tile already exists
            if (File.Exists(Application.dataPath + "/Tilemaps/Tiles/" + subject + "/" + barePath + "/" + name + ".asset"))
            {
                //		Debug.Log ("A tile for " + name + " already exists... Skipping...");
            }
            else
            {
                //setup building the tile//
                ObjectTile tile = TileBuilder.CreateTile <ObjectTile>(LayerType.Objects);

                //Cast the gameobject
                GameObject cast = AssetDatabase.LoadAssetAtPath(smallPath, typeof(GameObject)) as GameObject;
                if (barePath == "/WallMounts")
                {
                    tile.Rotatable = true;
                    tile.Offset    = true;
                }
                else
                {
                    tile.Rotatable = false;
                    tile.Offset    = false;
                }
                tile.Object = cast;
                //Create the tile
                TileBuilder.CreateAsset(tile, name, "Assets/Tilemaps/Tiles/" + subject + "/" + barePath);
                PreviewSpriteBuilder.Create(cast);
                created++;
            }
        }
        EditorUtility.ClearProgressBar();
        Debug.Log(created + " / " + counter + " Tiles created for prefabs");
    }