Exemplo n.º 1
0
        private static void ReadAllPrefabsInCategory(PrefabCategory prefabCategory, XmlNodeList prefabNodes)
        {
            if (prefabNodes.Count == 0)
            {
                return;
            }

            for (int prefabNodeIndex = 0; prefabNodeIndex < prefabNodes.Count; ++prefabNodeIndex)
            {
                XmlNode prefabNode     = prefabNodes[prefabNodeIndex];
                XmlNode prefabNameNode = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabNameNode);
                XmlNode prefabPathNode = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabPathNode);
                if (prefabPathNode == null)
                {
                    continue;
                }
                XmlNode offsetFromGridNode   = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabOffsetFromGridSurfaceNode);
                XmlNode offsetFromObjectNode = prefabNode.SelectSingleNode(PrefabConfigXMLInfo.PrefabOffsetFromObjectSurfaceNode);

                GameObject unityPrefab = AssetDatabase.LoadAssetAtPath(prefabPathNode.InnerText, typeof(GameObject)) as GameObject;
                if (unityPrefab == null)
                {
                    continue;
                }

                Prefab prefab = PrefabFactory.Create(unityPrefab);
                if (prefabNameNode != null && !string.IsNullOrEmpty(prefabNameNode.InnerText))
                {
                    prefab.Name = prefabNameNode.InnerText;
                }

                float offsetFromGrid = 0.0f;
                if (offsetFromGridNode != null)
                {
                    try { offsetFromGrid = float.Parse(offsetFromGridNode.InnerText); }
                    catch (Exception) { }
                }
                prefab.OffsetFromGridSurface = offsetFromGrid;

                float offsetFromObject = 0.0f;
                if (offsetFromObjectNode != null)
                {
                    try { offsetFromObject = float.Parse(offsetFromObjectNode.InnerText); }
                    catch (Exception) { }
                }
                prefab.OffsetFromObjectSurface = offsetFromObject;

                ReadPrefabTagAssociations(prefab, prefabNode.SelectNodes(PrefabConfigXMLInfo.PrefabAssociatedTagNode));
                prefabCategory.AddPrefab(prefab);
            }
        }
Exemplo n.º 2
0
        public void TransferPrefabToCategory(Prefab prefabToTransfer, PrefabCategory destinationCategory)
        {
            if (destinationCategory == this)
            {
                return;
            }

            if (ContainsPrefab(prefabToTransfer))
            {
                _prefabs.RemoveEntity(prefabToTransfer);
                destinationCategory.AddPrefab(prefabToTransfer);

                PrefabWasTransferredToCategoryMessage.SendToInterestedListeners(prefabToTransfer, this, destinationCategory);
            }
        }
 public void Perform()
 {
     UndoEx.RecordForToolAction(_prefabCategory);
     _prefabCategory.AddPrefab(_prefab);
 }