Esempio n. 1
0
    private void InputReaction()
    {
        Event current = Event.current;

        if (current.type == EventType.DragPerform && DragAndDrop.objectReferences.Length != 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType().BaseType == typeof(EditorEntity))
        {
            if (SceneEditorWindow.targetGameObject == null)
            {
                SceneEditorWindow.targetGameObject = SceneCache.CreateEntity(DragAndDrop.objectReferences[0]);
            }
            SceneEditorWindow.targetGameObject.transform.position = this.CalEntityPosition(current.mousePosition);
            Selection.activeObject = SceneEditorWindow.targetGameObject;
            DragAndDrop.AcceptDrag();
            HandleUtility.Repaint();
            current.Use();
        }
        if (current.type == EventType.DragUpdated && DragAndDrop.objectReferences.Length != 0 && DragAndDrop.objectReferences[0] != null && DragAndDrop.objectReferences[0].GetType().BaseType == typeof(EditorEntity))
        {
            if (SceneEditorWindow.targetGameObject == null)
            {
                SceneEditorWindow.targetGameObject = SceneCache.CreateEntity(DragAndDrop.objectReferences[0]);
            }
            if (SceneEditorWindow.targetGameObject != null)
            {
                SceneEditorWindow.targetGameObject.transform.position = this.CalEntityPosition(current.mousePosition);
            }
            DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            current.Use();
        }
    }
Esempio n. 2
0
 public static void LoadAsset(string assetPath)
 {
     SceneCache._cache = (AssetDatabase.LoadAllAssetsAtPath(assetPath).Cast <ScriptableObject>().ToArray <ScriptableObject>().Single((ScriptableObject obj) => obj as SceneCache != null) as SceneCache);
     if (SceneCache.cache == null)
     {
         Debug.Log("Dungeon: Cannot find serialized dungeon cache, creating new instance");
         SceneCache.CreatAsset(assetPath);
     }
 }
Esempio n. 3
0
 private static void OnCacheChange()
 {
     if (SceneCache.cache)
     {
         SceneCache.SaveDungeonCache();
         EditorUtility.SetDirty(SceneCache.cache);
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
     }
 }
Esempio n. 4
0
 public static void CreateDungeonEditor()
 {
     if (SceneEditorWindow.instance)
     {
         DestroyImmediate(SceneEditorWindow.instance);
     }
     SceneEditorWindow.instance      = ScriptableObject.CreateInstance <SceneEditorWindow>();
     SceneEditorWindow.instance.name = "Dungeon Editor";
     SceneCache.Init();
     SceneView.FrameLastActiveSceneView();
 }
Esempio n. 5
0
 private static bool OpenAsset(int instanceid, int line)
 {
     UnityEngine.Object @object = EditorUtility.InstanceIDToObject(instanceid);
     if (@object is SceneCache && EditorUtility.DisplayDialog("", string.Format("用副本编辑器打开 {0}?", @object.name), "Hm", "Cancle"))
     {
         SceneCache.LoadAsset(AssetDatabase.GetAssetPath(@object));
         SceneUtils.OpenScene();
         SceneEditorWindow.CreateDungeonEditor();
         return true;
     }
     return false;
 }
Esempio n. 6
0
    public static GameObject CreateEntity(UnityEngine.Object entity, string selectStateID = "")
    {
        GameObject gameObject = null;

        if (entity is EditorMonster)
        {
            EditorMonster editorMonster = entity as EditorMonster;
            Debug.Log(editorMonster.name);
            gameObject = SceneUtils.CreateEntityInScene(string.Format("Assets/Resources/{0}.prefab", editorMonster.path), editorMonster.name);
            //SceneCache.AddToList<ScriptableObjectMonster>(ScriptableObjectMonster.Create(gameObject.transform, editorMonster.path, selectStateID, editorMonster.monsterId, editorMonster.name), DungeonCache.MonsterList);
        }
        gameObject.transform.SetParent(SceneCache.dungeonRoot);
        SceneCache.OnCacheChange();
        gameObject.layer = 9;
        return(gameObject);
    }
Esempio n. 7
0
    private void OnGUI()
    {
        GUILayout.BeginArea(new Rect(0f, base.position.height / 3f, base.position.width, base.position.height / 3f));
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayout.FlexibleSpace();




        if (GUILayout.Button(new GUIContent("New Dungeon"), new GUILayoutOption[]
        {
            GUILayout.Width(100f),
            GUILayout.Height(60f)
        }))
        {
            string text = EditorUtility.OpenFilePanel("New Dungeon", "Assets/Scene/Test", "unity");
            if (!string.IsNullOrEmpty(text) && SceneUtils.CheckScene(text))
            {
                text = text.Replace(Application.dataPath, "Assets");
                string text2 = EditorUtility.SaveFilePanel("Save New Dungeon", "Assets", "NewDungeon", "asset");
                if (!string.IsNullOrEmpty(text2) && !text2.Contains(Application.dataPath))
                {
                    string contents = File.ReadAllText(text2);
                    string arg = text2.Split(new char[]
                    {
                        '/'
                    }).Last<string>();
                    text2 = string.Format("{0}/DungeonTmp/{1}", Application.dataPath, arg);
                    Debug.Log(text2);    
                    File.WriteAllText(text2, contents);    
                }
                text2 = text2.Replace(Application.dataPath, "Assets");
                SceneCache.LoadDungeon(text2, text);
                SceneUtils.OpenScene();
                SceneEditorWindow.CreateDungeonEditor();
                this.Destroy();                                                  
            }
            else
            {
                base.ShowNotification(new GUIContent("Choose .unity"));
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
Esempio n. 8
0
        private void Start()
        {
            gameContext = GameObject.FindGameObjectWithTag(GlobalConsts.CONTEXT_TAG);
            sceneCache  = gameContext.GetComponent <SceneCache>();

            /* We don't use the inventory because of the player uses the item
             * and it gets destroyed, there's no longer a point of reference.
             * We also don't call this when the item is added via the inventory
             * because that means we're dealing with get and set in two places
             * when we only need them here in one place. */
            if (!string.IsNullOrEmpty(itemSessionId))
            {
                bool alreadyOwned = sceneCache.ItemExists(itemSessionId);

                if (alreadyOwned)
                {
                    Destroy(gameObject);
                }
            }
            else
            {
                throw new UnityException(GlobalConsts.ERROR_STRING_EMPTY);
            }
        }
Esempio n. 9
0
    private IEnumerator LoadRequestedScene()
    {
        yield return(null);

        UnityEngine.SceneManagement.SceneManager.LoadScene(SceneCache.ReadCache(), LoadSceneMode.Single);
    }
Esempio n. 10
0
 public void LoadHome()
 {
     SceneCache.WriteCache(0);
     UnityEngine.SceneManagement.SceneManager.LoadScene(3, LoadSceneMode.Single);
 }
Esempio n. 11
0
 public static void CreatAsset(string path)
 {
     SceneCache._cache = ScriptableObject.CreateInstance <SceneCache>();
     AssetDatabase.CreateAsset(SceneCache.cache, path);
     AssetDatabase.SaveAssets();
 }
Esempio n. 12
0
 public static void LoadDungeon(string assetPath, string scenePath)
 {
     SceneCache.CreatAsset(assetPath);
     SceneCache.cache.scenePath = scenePath;
     SceneCache.OnCacheChange();
 }