Exemplo n.º 1
0
        protected override ObjectInitData AttemptRecreateInitData()
        {
            string         guessedPrefabPath = PrefabPath + gameObject.name.Split(new char[' '])[0];
            ObjectInitData newinitData       = new ObjectInitData(guessedPrefabPath);

            return(newinitData);
        }
Exemplo n.º 2
0
        GameObject SpawnInstance(GameObject prototype, ObjectInitData initData = null, string savedUniqueID = null)
        {
            // Instantiate prototype
            GameObject instance = Instantiate(prototype);
            // Get SaveLoadable component of instance
            SaveLoadableGameObject spawnedObject = instance.GetComponent <SaveLoadableGameObject>();

            if (initData == null)
            {
                Debug.LogFormat("GameObject {0} spawning without any initialization data", prototype.name);
            }
            else
            {
                spawnedObject.Initialize(initData);
            }
            // If we are spawning an object with a saved UniqueID, set it here
            if (savedUniqueID != null)
            {
                instance.GetComponent <UniqueID>().SetUniqueIDFromSaveFile(savedUniqueID);
            }


            // WorldController should listen for this and add it to its dictionary
            cbPrefabSpawned(instance);

            return(instance);
        }
Exemplo n.º 3
0
        // TODO: Would be nice to track which prefabs have already been loaded
        // to avoid loading Poster / Postit prefabs more than once
        public void OnSpawnMenuButtonClicked(MenuButton menuButton, ObjectInitData objectInitdata)
        {
            GameObject prototype = CreatePrototype(objectInitdata.PrefabPath);
            // TODO: Add prototype to dictionary here

            GameObject instance = SpawnInstance(prototype, objectInitdata);

            // TODO: Call ManipulateController or otherwise handle the grab when spawning from menu
        }
Exemplo n.º 4
0
        public virtual void Save(WorldSaveData worldSaveData)
        {
            // This would occur if we place objects in the Editor manually.
            if (initData == null)
            {
                initData = AttemptRecreateInitData();
            }

            // Record current transform in serializable format
            transformData = new SerializableTransform(this.transform);
        }
Exemplo n.º 5
0
        // TODO: Is it safe to keep this public? Maybe should be called by Start / OnEnable and protected?
        public override void Initialize(ObjectInitData initData)
        {
            // Confirm that ObjectInitData is valid PosterData
            if (initData == null)
            {
                Debug.LogError("Attempting to initialize Poster with null objectInitData");
                return;
            }
            else if (initData.GetType() != typeof(PosterInitData))
            {
                Debug.LogErrorFormat("Attempting to initialize a Poster with ObjectInitData of type {0}. Valid PosterInitData required.");
                return;
            }
            // Cast initData to PosterInitData
            posterInitData = (PosterInitData)initData;

            // Set label to PosterData.Label

            // Set texture to PosterData.Texture
            posterTexture = posterInitData.Texture;

            base.Initialize(initData);
        }
Exemplo n.º 6
0
 // All SaveLoadableGameObjects must be initialized from prefabs.
 // ObjectInitData contains everything this prefab need to build a specific instance.
 // ObjectInitData contains a prefab path as a string at the minimum.
 // Derived classes may use more specific InitData
 // For example, PosterInitData (with texture and label information)
 // TODO: Is it safe to keep this public?
 public virtual void Initialize(ObjectInitData initData)
 {
     this.initData = initData;
 }
Exemplo n.º 7
0
 public GameObjectSaveData(ObjectInitData initData, SerializableTransform transformData)
 {
     this.initData      = initData;
     this.transformData = transformData;
 }
Exemplo n.º 8
0
 public SpawnMenuItem(string label, Sprite icon, ObjectInitData objectInitData = null)
 {
     this.Label          = label;
     this.Icon           = icon;
     this.ObjectInitData = objectInitData;
 }