Esempio n. 1
0
        public bool CreateGhostCollection(params GameObject[] ghostTypes)
        {
            if (m_GhostCollection != null)
            {
                return(false);
            }
            var collectionGameObject = new GameObject();
            var collection           = collectionGameObject.AddComponent <GhostCollectionAuthoringComponent>();

            var oldGhostDefaults = GhostAuthoringComponentEditor.GhostDefaultOverrides;

            GhostAuthoringComponentEditor.InitDefaultOverrides();
            foreach (var ghostObject in ghostTypes)
            {
                var ghost = ghostObject.GetComponent <GhostAuthoringComponent>();
                if (ghost == null)
                {
                    ghost = ghostObject.AddComponent <GhostAuthoringComponent>();
                }

                ghost.Name     = ghostObject.name;
                ghost.prefabId = Guid.NewGuid().ToString().Replace("-", "");

                collection.Ghosts.Add(new GhostCollectionAuthoringComponent.Ghost {
                    prefab = ghost, enabled = true
                });
            }
            GhostAuthoringComponentEditor.GhostDefaultOverrides = oldGhostDefaults;
            m_GhostCollection = collectionGameObject;
            m_BlobAssetStore  = new BlobAssetStore();
            return(true);
        }
Esempio n. 2
0
        public bool CreateGhostCollection(string rootPath, string name, params GameObject[] ghostTypes)
        {
            bool validateOnly = !k_ForceRegenerateAllCode;

            if (m_GhostCollection != null)
            {
                return(false);
            }
            var collectionGameObject = new GameObject();
            var collection           = collectionGameObject.AddComponent <GhostCollectionAuthoringComponent>();

            collection.NamePrefix = name;
            collection.SerializerCollectionPath   = rootPath + name + "GhostSerializerCollection.cs";
            collection.DeserializerCollectionPath = rootPath + name + "GhostDeserializerCollection.cs";

            bool success = true;

            foreach (var ghostObject in ghostTypes)
            {
                var ghost = ghostObject.GetComponent <GhostAuthoringComponent>();
                if (ghost == null)
                {
                    ghost = ghostObject.AddComponent <GhostAuthoringComponent>();
                }

                ghost.RootPath         = rootPath;
                ghost.SnapshotDataPath = ghostObject.name + "SnapshotData.cs";
                ghost.UpdateSystemPath = ghostObject.name + "UpdateSystem.cs";
                ghost.SerializerPath   = ghostObject.name + "Serializer.cs";

                ghost.prefabId = Guid.NewGuid().ToString().Replace("-", "");

                GhostAuthoringComponentEditor.SyncComponentList(ghost);
                if (GhostAuthoringComponentEditor.GenerateGhost(ghost, validateOnly) != GhostCodeGen.Status.NotModified)
                {
                    success = false;
                }

                collection.Ghosts.Add(new GhostCollectionAuthoringComponent.Ghost {
                    prefab = ghost, enabled = true
                });
            }
            // Trigger code-gen for collection and ghosts, if anything changes that is an error
            if (GhostCollectionAuthoringComponentEditor.GenerateCollection(collection, validateOnly) != GhostCodeGen.Status.NotModified)
            {
                success = false;
            }
            if (!success)
            {
                return(false);
            }
            m_GhostCollection = collectionGameObject;
            m_BlobAssetStore  = new BlobAssetStore();
            return(true);
        }