LoadAdditive() public static method

Additively loads a TextScene. All objects from the TextScene will be children of the passed parent, if any. The TextScene will be added with a link to its original source asset, so it can easily be treated as a prefab, or scene-in-scene link.
public static LoadAdditive ( TextAsset asset, GameObject parent ) : void
asset UnityEngine.TextAsset
parent GameObject
return void
Ejemplo n.º 1
0
        public bool HandleDrag()
        {
            if (Event.current.type == EventType.DragUpdated ||
                Event.current.type == EventType.DragPerform)
            {
                Entry e = DragAndDrop.GetGenericData("entry") as Entry;

                //Do not allow dragging stuff onto prefabs or textscene links.
                if (this.type != EntryType.Normal)
                {
                    selected = null;
                    DragAndDrop.visualMode = DragAndDropVisualMode.None;
                    return(false);
                }
                //Do not allow dragging prefab or textscene children around.
                else if (e != null &&
                         (e.type == EntryType.PrefabChild ||
                          e.type == EntryType.TextSceneChild))
                {
                    selected = null;
                    DragAndDrop.visualMode = DragAndDropVisualMode.None;
                    return(false);
                }
                else
                {
                    selected = this;

                    if (expanded == false &&
                        EditorApplication.timeSinceStartup > this.expandedTimer)
                    {
                        this.expanded = true;
                    }

                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;

                    if (Event.current.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();

                        if (e != null && e.go != null)
                        {
                            GameObject dragged = e.go;

                            if (dragged != null)
                            {
                                if (dragged != go)
                                {
                                    Undo.RegisterSceneUndo("Move " + dragged.name);

                                    //If the target is null (the root), we might want to orphan the object.
                                    if (go == null)
                                    {
                                        if (dragged.transform.parent != null)
                                        {
                                            if (EditorUtility.DisplayDialog("Orphan", "Do you want to make " + dragged.name + " an orphan?", "Yes", "No"))
                                            {
                                                dragged.transform.parent   = null;
                                                Selection.activeGameObject = dragged;
                                                TextSceneHierarchy.Refresh();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //Change parent to whatever we're hovering above at the time of drag end.
                                        if (EditorUtility.DisplayDialog("Change parent", "Do you want to make " + go.name + " the parent of " + dragged.name + "?", "Yes", "No"))
                                        {
                                            dragged.transform.parent   = go.transform;
                                            Selection.activeGameObject = dragged;
                                            TextSceneHierarchy.Refresh();
                                        }
                                    }
                                }
                            }
                        }
                        else if (DragAndDrop.objectReferences.Length > 0)
                        {
                            UnityEngine.Object dragged = DragAndDrop.objectReferences[0];

                            MonoScript comp             = dragged as MonoScript;
                            GameObject draggedGO        = dragged as GameObject;
                            TextAsset  draggedTextScene = dragged as TextAsset;

                            if (comp != null)
                            {
                                if (this.go != null)
                                {
                                    this.go.AddComponent(comp.GetClass());
                                    Selection.activeGameObject = this.go;
                                }
                            }
                            else if (draggedTextScene != null)
                            {
                                Undo.RegisterSceneUndo("Add scene " + draggedTextScene.name);

                                TextSceneDeserializer.LoadAdditive(draggedTextScene, this.go);
                            }
                            else if (draggedGO != null)
                            {
                                PrefabType pt = EditorUtility.GetPrefabType(dragged);

                                if (pt == PrefabType.ModelPrefab || pt == PrefabType.Prefab)
                                {
                                    Undo.RegisterSceneUndo("Create " + draggedGO.name);

                                    GameObject instance = EditorUtility.InstantiatePrefab(dragged) as GameObject;

                                    if (this.go != null)
                                    {
                                        instance.transform.parent = this.go.transform;
                                    }

                                    instance.transform.localPosition = Vector3.zero;
                                    instance.transform.localRotation = Quaternion.identity;
                                    instance.name = instance.name + "_instance";

                                    Selection.activeGameObject = instance;
                                }
                            }
                        }
                    }
                }

                Event.current.Use();
                return(true);
            }

            return(false);
        }