Exemple #1
0
 void OnApplicationPause(bool pauseStatus)
 {
     Debug.unityLogger.Log("EditorFile", "OnApplicationPause(" + pauseStatus + ")");
     if (pauseStatus)
     {
         Save();
     }
     else if (ShareMap.FileWaitingToImport())
     {
         if (importWorldHandler == null)
         {
             Save();
             SceneManager.LoadScene(Scenes.FILE_RECEIVE);
         }
         else
         {
             try
             {
                 importWorldHandler(ShareMap.GetImportStream());
             }
             catch (System.Exception e)
             {
                 DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "An error occurred while reading the file.");
                 Debug.LogError(e);
             }
         }
     }
 }
Exemple #2
0
    private void ImportMap(string name)
    {
        if (name.Length == 0)
        {
            Close();
            return;
        }
        string newPath = WorldFiles.GetFilePath(name);

        if (File.Exists(newPath))
        {
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            dialog.yesButtonHandler = Close;
            return;
        }

        try
        {
            using (FileStream fileStream = File.Create(newPath))
            {
                ShareMap.ReadSharedURLAndroid(fileStream);
            }
            Close();
        }
        catch (System.Exception e)
        {
            Debug.Log(e);
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "Error importing world");
            dialog.yesButtonHandler = Close;
        }
    }
Exemple #3
0
    // callback MUST dispose the stream when done!
    public static void ImportAudioStream(System.Action <Stream> callback)
    {
// TODO: get this to work with Android eventually
// right now it can't open files unless they are in a .nomedia folder (doesn't have read permission)
// and the files it can open have names obscured.
//#if UNITY_ANDROID && !UNITY_EDITOR
#if false
        CheckPermission(NativeGallery.GetAudioFromGallery((path) => {
            if (path == null)
            {
                callback(null);
                return;
            }
            try
            {
                callback(File.Open(path, FileMode.Open));
            }
            catch (System.Exception e)
            {
                DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "Error importing audio file");
                Debug.LogError(e);
            }
        }));
#else
        ShareMap.OpenFileManager();
#endif
    }
Exemple #4
0
    private void ImportWorld(string name)
    {
        if (name.Length == 0)
        {
            Destroy(this);
            return;
        }
        string newPath = WorldFiles.GetNewWorldPath(name);

        if (File.Exists(newPath))
        {
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            dialog.yesButtonHandler = DestroyThis;
            return;
        }

        try
        {
            ShareMap.ImportSharedFile(newPath);
            MenuGUI.OpenWorld(newPath, Scenes.EDITOR);
            openingWorld = true;
            Destroy(this);
        }
        catch (System.Exception e)
        {
            Debug.Log(e);
            var dialog = DialogGUI.ShowMessageDialog(gameObject, "Error importing world");
            dialog.yesButtonHandler = DestroyThis;
        }
    }
Exemple #5
0
    public static DialogGUI ShowMessageDialog(GameObject gameObject, string message)
    {
        DialogGUI dialog = gameObject.AddComponent <DialogGUI>();

        dialog.message       = message;
        dialog.yesButtonText = "OK";
        return(dialog);
    }
Exemple #6
0
 private static void CheckPermission(NativeGallery.Permission permission)
 {
     if (permission != NativeGallery.Permission.Granted)
     {
         DialogGUI.ShowMessageDialog(GUIManager.guiGameObject,
                                     "Please grant N-Space permission to access your photo gallery.");
     }
 }
Exemple #7
0
    void Start()
    {
        if (Gui != null)
        {
            return;
        }

        Gui = GameObject.Find("DialogGUI").GetComponent <DialogGUI>();
    }
    public void Tick()
    {
        Dialog dialog = node.Content as Dialog;

        if (!launched)
        {
            wasLooking = CameraManager.Target;
            fragments  = new Queue <Dialog.Fragment>(dialog.getFragments());
            launched   = true;
            next       = true;
            chosen     = -1;
        }

        if (next)
        {
            if (fragments.Count > 0)
            {
                if (fragments.Peek().Entity != null)
                {
                    CameraManager.smoothLookTo(fragments.Peek().Entity.gameObject);
                }
                DialogGUI gui = ScriptableObject.CreateInstance <DialogGUI>();
                gui.init(this, fragments.Dequeue());
                GUIManager.addGUI(gui);
            }
            else
            {
                if (dialog.getOptions() != null && dialog.getOptions().Length > 1)
                {
                    DialogGUI gui = ScriptableObject.CreateInstance <DialogGUI>();
                    gui.init(this, dialog.getOptions());
                    GUIManager.addGUI(gui);
                }
                else
                {
                    chosen = 0;
                }
            }
            next = false;
        }

        if (chosen != -1)
        {
            finished = true;
            CameraManager.lookTo(wasLooking);
            if (node.Childs.Length > chosen)
            {
                nextNode = node.Childs[chosen];
            }
            chosen = -1;
        }
    }
Exemple #9
0
    private void CopyWorld(string newName)
    {
        if (newName.Length == 0)
        {
            return;
        }
        string newPath = WorldFiles.GetNewWorldPath(newName);

        if (File.Exists(newPath))
        {
            DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            return;
        }
        File.Copy(selectedWorldPath, newPath);
        UpdateWorldList();
    }
Exemple #10
0
    private void RenameMap(string newName)
    {
        if (newName.Length == 0)
        {
            return;
        }
        string newPath = WorldFiles.GetFilePath(newName);

        if (File.Exists(newPath))
        {
            DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            return;
        }
        File.Move(WorldFiles.GetFilePath(selectedWorld), newPath);
        UpdateMapList();
    }
Exemple #11
0
 public static void ImportTexture(System.Action <Texture2D> callback)
 {
     CheckPermission(NativeGallery.GetImageFromGallery((path) => {
         if (path == null)
         {
             callback(null);
             return;
         }
         Texture2D texture = NativeGallery.LoadImageAtPath(path,
                                                           maxSize: 1024, markTextureNonReadable: false);
         if (texture == null)
         {
             DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "Error importing image");
         }
         else
         {
             Debug.Log("Dimensions: " + texture.width + ", " + texture.height);
         }
         callback(texture);
     }, "Select a texture image"));
 }
Exemple #12
0
    private void NewWorld(string name, TextAsset template)
    {
        if (name.Length == 0)
        {
            return;
        }
        string path = WorldFiles.GetNewWorldPath(name);

        if (File.Exists(path))
        {
            DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            return;
        }
        using (FileStream fileStream = File.Create(path))
        {
            fileStream.Write(template.bytes, 0, template.bytes.Length);
        }
        UpdateWorldList();

        OpenWorld(path, Scenes.EDITOR);
    }
Exemple #13
0
    private void CreateWorldOverflowMenu(string path)
    {
        string name = Path.GetFileNameWithoutExtension(path);

        worldOverflowMenu       = gameObject.AddComponent <OverflowMenuGUI>();
        selectedWorldPath       = path;
        worldOverflowMenu.items = new OverflowMenuGUI.MenuItem[]
        {
            new OverflowMenuGUI.MenuItem("Play", GUIIconSet.instance.play, () => {
                MenuGUI.OpenWorld(path, Scenes.GAME);
            }),
            new OverflowMenuGUI.MenuItem("Rename", GUIIconSet.instance.rename, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new name for " + name;
                inputDialog.handler            = RenameWorld;
            }),
            new OverflowMenuGUI.MenuItem("Copy", GUIIconSet.instance.copy, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new world name...";
                inputDialog.handler            = CopyWorld;
            }),
            new OverflowMenuGUI.MenuItem("Delete", GUIIconSet.instance.delete, () => {
                DialogGUI dialog        = gameObject.AddComponent <DialogGUI>();
                dialog.message          = "Are you sure you want to delete " + name + "?";
                dialog.yesButtonText    = "Yes";
                dialog.noButtonText     = "No";
                dialog.yesButtonHandler = () =>
                {
                    File.Delete(path);
                    UpdateWorldList();
                };
            }),
#if (UNITY_ANDROID || UNITY_IOS)
            new OverflowMenuGUI.MenuItem("Share", GUIIconSet.instance.share,
                                         () => ShareMap.Share(path))
#endif
        };
    }
Exemple #14
0
    private void CreateWorldOverflowMenu(string fileName)
    {
        worldOverflowMenu       = gameObject.AddComponent <OverflowMenuGUI>();
        selectedWorld           = fileName;
        worldOverflowMenu.items = new OverflowMenuGUI.MenuItem[]
        {
            new OverflowMenuGUI.MenuItem("Play", GUIIconSet.instance.play, () => {
                MenuGUI.OpenMap(fileName, "playScene");
            }),
            new OverflowMenuGUI.MenuItem("Rename", GUIIconSet.instance.rename, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new name for " + fileName;
                inputDialog.handler            = RenameMap;
            }),
            new OverflowMenuGUI.MenuItem("Copy", GUIIconSet.instance.copy, () => {
                TextInputDialogGUI inputDialog = gameObject.AddComponent <TextInputDialogGUI>();
                inputDialog.prompt             = "Enter new world name...";
                inputDialog.handler            = CopyMap;
            }),
            new OverflowMenuGUI.MenuItem("Delete", GUIIconSet.instance.delete, () => {
                DialogGUI dialog        = gameObject.AddComponent <DialogGUI>();
                dialog.message          = "Are you sure you want to delete " + fileName + "?";
                dialog.yesButtonText    = "Yes";
                dialog.noButtonText     = "No";
                dialog.yesButtonHandler = () =>
                {
                    File.Delete(WorldFiles.GetFilePath(fileName));
                    UpdateMapList();
                };
            }),
#if UNITY_ANDROID
            new OverflowMenuGUI.MenuItem("Share", GUIIconSet.instance.share, () => {
                string path = WorldFiles.GetFilePath(fileName);
                ShareMap.ShareAndroid(path);
            })
#endif
        };
    }
Exemple #15
0
    private void NewMap(string name)
    {
        if (name.Length == 0)
        {
            return;
        }
        string filePath = WorldFiles.GetFilePath(name);

        if (File.Exists(filePath))
        {
            DialogGUI.ShowMessageDialog(gameObject, "A world with that name already exists.");
            return;
        }
        using (FileStream fileStream = File.Create(filePath))
        {
            using (var sw = new StreamWriter(fileStream))
            {
                sw.Write(defaultMap.text);
                sw.Flush();
            }
        }
        UpdateMapList();
    }
Exemple #16
0
 void Awake()
 {
     cur = this;
 }
Exemple #17
0
    private void EntityPropertiesGUI()
    {
        Entity singleSelectedEntity = null;

        if (selectedEntities.Count == 1)
        {
            singleSelectedEntity = selectedEntities[0];
        }

        EntityReferencePropertyManager.Reset(singleSelectedEntity); // could be null and that's fine (?)

        GUILayout.BeginVertical(GUI.skin.box);
        PropertiesObjectGUI(editEntity);
        GUILayout.EndVertical();

        if (singleSelectedEntity != null && !(singleSelectedEntity is PlayerObject))
        {
            GUILayout.BeginHorizontal();
            if (GUIUtils.HighlightedButton("Clone"))
            {
                if (singleSelectedEntity is ObjectEntity)
                {
                    ObjectEntity clone     = (ObjectEntity)(singleSelectedEntity.Clone());
                    var          pickerGUI = gameObject.AddComponent <FacePickerGUI>();
                    pickerGUI.voxelArray = voxelArray;
                    pickerGUI.message    = "Tap to place clone";
                    pickerGUI.pickAction = () =>
                    {
                        if (!voxelArray.PlaceObject(clone))
                        {
                            DialogGUI.ShowMessageDialog(gameObject, ActionBarGUI.OBJECT_NO_ROOM_ERROR);
                        }
                    };
                }
                else if (singleSelectedEntity is Substance)
                {
                    Substance clone = (Substance)(singleSelectedEntity.Clone());
                    clone.defaultPaint                = voxelArray.GetSelectedPaint();
                    clone.defaultPaint.addSelected    = false;
                    clone.defaultPaint.storedSelected = false;
                    voxelArray.substanceToCreate      = clone;
                    var createGUI = gameObject.AddComponent <CreateSubstanceGUI>();
                    createGUI.voxelArray = voxelArray;
                }
            }
            if (GUIUtils.HighlightedButton("Delete"))
            {
                DeleteButton();
            }
            GUILayout.EndHorizontal();
        }
        if (selectedEntities.Count > 1)
        {
            if (GUIUtils.HighlightedButton("Delete"))
            {
                DeleteButton();
            }
        }

        TutorialGUI.TutorialHighlight("change sensor");
        if (GUILayout.Button("Change Sensor"))
        {
            TypePickerGUI sensorMenu = gameObject.AddComponent <TypePickerGUI>();
            sensorMenu.title      = "Change Sensor";
            sensorMenu.categories = new PropertiesObjectType[][] { GameScripts.sensors };
            sensorMenu.handler    = (PropertiesObjectType type) =>
            {
                foreach (Entity entity in selectedEntities)
                {
                    entity.sensor = (Sensor)type.Create();
                }
                voxelArray.unsavedChanges = true;
                UpdateEditEntity();
            };
        }
        TutorialGUI.ClearHighlight();
        GUILayout.BeginVertical(GUI.skin.box);
        PropertiesObjectGUI(editSensor, " Sensor");
        GUILayout.EndVertical();

        TutorialGUI.TutorialHighlight("add behavior");
        if (GUILayout.Button("Add Behavior"))
        {
            NewBehaviorGUI behaviorMenu = gameObject.AddComponent <NewBehaviorGUI>();
            behaviorMenu.title      = "Add Behavior";
            behaviorMenu.self       = singleSelectedEntity;
            behaviorMenu.voxelArray = voxelArray;
            behaviorMenu.handler    = (PropertiesObjectType behaviorType) =>
            {
                foreach (Entity entity in selectedEntities)
                {
                    EntityBehavior newBehavior = (EntityBehavior)behaviorType.Create();
                    // with multiple selected entities, NewBehaviorGUI doesn't check if behaviors
                    // are valid for the selected entities
                    if (newBehavior.targetEntity.entity == null && !newBehavior.targetEntityIsActivator &&
                        !newBehavior.BehaviorObjectType().rule(entity))
                    {
                        continue;
                    }
                    entity.behaviors.Add(newBehavior);
                    EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, newBehavior);
                }
                voxelArray.unsavedChanges = true;
                UpdateEditEntity();
                scrollVelocity = new Vector2(0, 2000 * editBehaviors.Count); // scroll to bottom
            };
        }
        TutorialGUI.ClearHighlight();

        Color guiBaseColor = GUI.backgroundColor;
        StoredEntityBehavior behaviorToRemove = null;

        foreach (StoredEntityBehavior storedBehavior in editBehaviors)
        {
            TutorialGUI.TutorialHighlight("behaviors");
            Entity behaviorTarget = null;
            if (storedBehavior.sharedTarget)
            {
                behaviorTarget = storedBehavior.allBehaviors[0].targetEntity.entity;
            }
            if (behaviorTarget != null)
            {
                EntityReferencePropertyManager.Next(behaviorTarget);
                GUI.backgroundColor = guiBaseColor * EntityReferencePropertyManager.GetColor();
            }
            EntityReferencePropertyManager.SetBehaviorTarget(behaviorTarget);
            GUILayout.BeginVertical(GUI.skin.box);
            GUI.backgroundColor = guiBaseColor;
            PropertiesObjectGUI(storedBehavior, " Behavior",
                                () => EntityPreviewManager.BehaviorUpdated(singleSelectedEntity,
                                                                           storedBehavior.allBehaviors[0]));
            if (GUILayout.Button("Remove"))
            {
                behaviorToRemove = storedBehavior;
            }
            GUILayout.EndVertical();
            // clear this every time, in case the next target is the same
            EntityReferencePropertyManager.SetBehaviorTarget(null);
        }

        if (behaviorToRemove != null)
        {
            foreach (Entity entity in selectedEntities)
            {
                foreach (EntityBehavior remove in behaviorToRemove.allBehaviors)
                {
                    if (entity.behaviors.Remove(remove))
                    {
                        break;
                    }
                }
            }
            voxelArray.unsavedChanges = true;
            UpdateEditEntity();
            EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, behaviorToRemove.allBehaviors[0]);
        }

        if (mismatchedSelectedBehaviorCounts)
        {
            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("(other behaviors...)", GUIStyleSet.instance.labelTitle);
            GUILayout.EndVertical();
        }
    }
Exemple #18
0
 public void InitButton(DialogGUI parent, NPCDialogNode node)
 {
     Text.text = node.PlayerText;
     Parent    = parent;
     Node      = node;
 }
Exemple #19
0
    protected void EditGUI()
    {
        if (!voxelArray.FacesAreSelected())
        {
            return;
        }

        TutorialGUI.TutorialHighlight("paint");
        if (ActionBarButton(GUIIconSet.instance.paint))
        {
            PaintGUI paintGUI = gameObject.AddComponent <PaintGUI>();
            paintGUI.title   = "Paint Faces";
            paintGUI.handler = (VoxelFace paint) =>
            {
                voxelArray.PaintSelectedFaces(paint);
            };
            paintGUI.paint = voxelArray.GetSelectedPaint();
        }
        TutorialGUI.ClearHighlight();

        TutorialGUI.TutorialHighlight("create object");
        if (ActionBarButton(GUIIconSet.instance.create))
        {
            TypePickerGUI picker = gameObject.AddComponent <TypePickerGUI>();
            picker.title      = "Create";
            picker.categories = new PropertiesObjectType[][] {
                GameScripts.entityTemplates, GameScripts.objectTemplates
            };
            picker.categoryNames = new string[] { "Substance", "Object" };
            picker.handler       = (PropertiesObjectType type) =>
            {
                if (typeof(Substance).IsAssignableFrom(type.type))
                {
                    Substance substance = (Substance)type.Create();
                    voxelArray.substanceToCreate = substance;
                    var createGUI = gameObject.AddComponent <CreateSubstanceGUI>();
                    createGUI.voxelArray = voxelArray;
                }
                else if (typeof(ObjectEntity).IsAssignableFrom(type.type))
                {
                    ObjectEntity obj = (ObjectEntity)type.Create();
                    if (!voxelArray.PlaceObject(obj))
                    {
                        DialogGUI.ShowMessageDialog(gameObject, OBJECT_NO_ROOM_ERROR);
                    }
                }
            };
        }
        TutorialGUI.ClearHighlight();

        GUILayout.FlexibleSpace();
        int moveCount = 0;

        if (touchListener.currentTouchOperation == TouchListener.TouchOperation.MOVE &&
            touchListener.movingAxis is MoveAxis)
        {
            moveCount = Mathf.Abs(((MoveAxis)touchListener.movingAxis).moveCount);
        }
        if (moveCount != 0)
        {
            ActionBarLabel(moveCount.ToString());
        }
        else
        {
            ActionBarLabel(SelectionString(voxelArray.selectionBounds.size));
        }
    }