Ejemplo n.º 1
0
        internal static void Open(uLink.RegisterPrefabs target)
        {
            var window = GetWindow <RegisterPrefabsBrowser>(true, "Select uLink prefabs to be registered");

            window.Init(target);
            window.Repaint();
        }
Ejemplo n.º 2
0
        private void Init(uLink.RegisterPrefabs target)
        {
            _target = target;

            var files = Utility.GetAllAssetFiles("*.prefab");

            if (files == null)
            {
                return;
            }

            var items = new List <Item>(files.Length);

            foreach (var file in files)
            {
                var gameObject = AssetDatabase.LoadAssetAtPath(file, typeof(GameObject)) as GameObject;

                if (gameObject != null &&
                    PrefabUtility.GetPrefabType(gameObject) == PrefabType.Prefab &&
                    Utility.HasComponentInChildren <uLink.NetworkView>(gameObject.transform))
                {
                    var item = new Item(file, gameObject, _target);
                    items.Add(item);
                }
            }

            _items = items.ToArray();
        }
Ejemplo n.º 3
0
            public Item(string path, GameObject gameObject, uLink.RegisterPrefabs target)
            {
                _path = path;

                _indent = Utility.CountOccurencesOfChar(path, Path.DirectorySeparatorChar);

                _name = path + (gameObject != null ? " (" + gameObject.name + ")" : "");

                _gameObject = gameObject;
                selected    = target.prefabs.Contains(gameObject);
            }
Ejemplo n.º 4
0
 public void UpdateSelection(uLink.RegisterPrefabs target)
 {
     if (!selected)
     {
         target.prefabs.RemoveAll(_gameObject);
         EditorUtility.SetDirty(target);
     }
     else if (_gameObject != null && !target.prefabs.Contains(_gameObject))
     {
         target.prefabs.Add(_gameObject);
         EditorUtility.SetDirty(target);
     }
 }
Ejemplo n.º 5
0
    public void Reimport()
    {
        string filePath = Path.Combine(Application.dataPath, "PrefabsPath.txt");

        using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read))
        {
            if (null != fs)
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    Paths.Clear();
                    while (!sr.EndOfStream)
                    {
                        Paths.Add(sr.ReadLine());
                    }
                }
            }
        }

        Register = gameObject.GetComponent <uLink.RegisterPrefabs>();
        if (null == Register)
        {
            Debug.LogError("No script uLink.RegisterPrefabs.");
            return;
        }

        Register.prefabs.Clear();
        Register.replaceIfExists = true;

        foreach (string path in Paths)
        {
            string newPath = Path.Combine(Application.dataPath, path);
            if (Directory.Exists(newPath))
            {
                string[] files = Directory.GetFiles(newPath, "*.prefab");
                foreach (string file in files)
                {
                    string fileName = @"Assets/" + path + "/" + Path.GetFileName(file);

                    GameObject obj = UnityEditor.AssetDatabase.LoadAssetAtPath(fileName, typeof(GameObject)) as GameObject;

                    if (null != obj)
                    {
                        uLink.NetworkView view = obj.GetComponent <uLink.NetworkView>();
                        if (null == view)
                        {
                            view = obj.AddComponent <uLink.NetworkView>();
                        }

                        Register.prefabs.Add(obj);
                    }
                    else
                    {
                        Debug.LogError(fileName + " load failed.");
                    }
                }
            }
            else
            {
                Debug.LogError(newPath + " does not exists.");
            }
        }
    }