UnityEditor.Search.Providers 中的类
/
继承自:Search.QueryEngineParameterTransformerAttribute
属性类,用于定义应用于在场景提供者中运行的查询的自定义参数转换器函数,该场景提供者由使用 SceneQueryEngineFilterAttribute 的场景自定义过滤器定义。
[SceneQueryEngineParameterTransformer] static Vector3 DistanceParamHandler(string param) { if (param == "selection") { var centerPoint = Selection.gameObjects.Select(go => go.transform.position).Aggregate((v1, v2) => v1 + v2); centerPoint /= Selection.gameObjects.Length; return centerPoint; } if (param.StartsWith("[") && param.EndsWith("]")) { param = param.Trim('[', ']'); var vectorTokens = param.Split(','); var vectorValues = vectorTokens.Select(token => float.Parse(token, CultureInfo.InvariantCulture.NumberFormat)).ToList(); while (vectorValues.Count < 3) vectorValues.Add(0f); return new Vector3(vectorValues[0], vectorValues[1], vectorValues[2]); } var obj = GameObject.Find(param); if (!obj) return Vector3.zero; return obj.transform.position; }
与之一起使用
[SceneQueryEngineFilter("dist", "DistanceParamHandler", new[] {"=", "!=", "<", ">", "<=", ">="})] static float DistanceHandler(GameObject go, Vector3 p) { return (go.transform.position - p).magnitude; }