Ejemplo n.º 1
0
 public void DrawFound(ReplaceSelector selector, string name)
 {
     selector.found.Clear();
     selector.targetPath = "";
     if (selector.type == ReplaceOption.GameObject)
     {
         GameObject[] all = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));
         foreach (GameObject current in all)
         {
             bool allowed = current != null && (current.transform.parent == null || current.transform.parent.name != name);
             if (allowed && current.name == name)
             {
                 selector.found.Add(current);
             }
         }
         EditorGUILayout.LabelField(selector.found.Count + " objects found.");
     }
     else if (selector.type == ReplaceOption.Prefab)
     {
         bool       exists = false;
         FileData   file   = File.Find(name + ".prefab");
         GameObject target = (GameObject)selector.targetObject;
         if (file != null)
         {
             selector.targetPath = file.GetAssetPath();
             target = file.GetAsset <GameObject>();
         }
         if (target != null)
         {
             selector.found.Add(target);
             exists = true;
         }
         string result = exists ? "Found." : "Not Found.";
         string note   = exists ? "Valid .prefab source." : "";
         GUI.skin.label.normal.textColor = Colors.names["gray"];
         if (exists && selector.targetPath == "")
         {
             GUI.skin.label.normal.textColor = Colors.names["orange"];
             note = "Not a .prefab source.";
         }
         EditorGUILayout.LabelField(result, GUILayout.Width(65));
         EditorGUILayout.LabelField(note, GUI.skin.label);
         GUI.skin.label.normal.textColor = Color.white;
     }
 }
Ejemplo n.º 2
0
        public void DrawSelectorRow(ReplaceSelector selector, string label)
        {
            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField(label, GUILayout.Width(60));
            selector.type = (ReplaceOption)EditorGUILayout.EnumPopup(selector.type, GUILayout.Width(100));
            bool isGameObject = selector.type == ReplaceOption.GameObject;

            selector.manual = EditorGUILayout.Toggle(selector.manual, GUILayout.Width(15));
            if (selector.manual)
            {
                if (selector.targetObject != null)
                {
                    selector.targetObject = null;
                    selector.found.Clear();
                }
                selector.targetName = EditorGUILayout.TextField(selector.targetName, GUILayout.Width(150));
                if (selector.targetName != "")
                {
                    this.DrawFound(selector, selector.targetName);
                }
            }
            else
            {
                if (selector.targetName != "")
                {
                    selector.targetName = "";
                    selector.found.Clear();
                }
                selector.targetObject = EditorGUILayout.ObjectField(selector.targetObject, typeof(GameObject), isGameObject, GUILayout.Width(168));
                if (selector.targetObject != null)
                {
                    this.DrawFound(selector, selector.targetObject.name);
                }
            }
            GUILayout.EndHorizontal();
        }