/// <summary> /// 获取字段信息,支持使用“.”分隔的多级路径 /// </summary> /// <returns>The object field info.</returns> /// <param name="objType">Object type.</param> /// <param name="fieldPath">Field path.</param> public static FieldInfo GetObjectFieldInfo(System.Type objType, string fieldPath) { var hierarchy = fieldPath.Split(new[] { '.' }, 2); var field = GetFieldInfoByType(objType, hierarchy[0]); if (field == null) { return(null); } if (hierarchy.Length > 1) { var nextPath = hierarchy[1]; if (!nextPath.StartsWith(ArrayDataPrefix)) { return(GetObjectFieldInfo(field.FieldType, nextPath)); } else if (field.FieldType.IsArray || typeof(IList).IsAssignableFrom(field.FieldType)) { ParseArrayPath(nextPath, out nextPath); if (string.IsNullOrEmpty(nextPath)) { return(field); } else { var fieldType = field.FieldType; Type elementType = null; if (fieldType.IsArray) { elementType = fieldType.GetElementType(); } else if (fieldType.IsGenericType) { var gTypes = fieldType.GetGenericArguments(); if (gTypes.Length != 1) { PrettyLog.Error("Unknown array or list type: {0}", fieldType); return(null); } elementType = gTypes[0]; } else { PrettyLog.Error("Only array and List<T> can retrieve FieldInfo by propertyPath (not {0})", fieldType); return(null); } return(GetObjectFieldInfo(elementType, nextPath)); } } else { return(null); } } else { return(field); } }
//[See] //void TestFallingAliveAndDie() //{ // var request = new PlayerBlackboard() // { // action = new PlayerAction(PlayerActionType.Die, null, null, null), // posture = PlayerPosture.Idle, // isOnGround = false, // isGravityEnabled = true, // playingAction = null, // }; // ExecuteTest(request); //} //[See] //void TestFallingDead() //{ // var request = new PlayerBlackboard() // { // action = new PlayerAction(PlayerActionType.Die, null, null, null), // posture = PlayerPosture.Dead, // isOnGround = false, // isGravityEnabled = true, // }; // ExecuteTest(request); //} void ExecuteTest(PlayerBlackboard request) { if (!Application.isPlaying) { PrettyLog.Error("Run only when playing"); return; } StartCoroutine(ExecuteTestCo(request)); }
public void SetNodeWeight(Node child, float weight) { var childIndex = children.IndexOf(child); if (childIndex < 0) { PrettyLog.Error("Set weight error: '{0}' is not a child of '{1}'", child, this); return; } SetNodeWeight(childIndex, weight); }
void Say(TalkType type, System.Action onComplete) { PlayAnim(type); var content = FindTalk(type); if (bubble == null) { PrettyLog.Error("{0} has no bubble!", name); return; } bubble.Say(type, content, onComplete); }
bool ValidateSnapshot(Blackboard snapshot, out T typedSnapshot) { var actualType = snapshot.GetType(); if (actualType != typeof(T) && actualType.IsSubclassOf(typeof(T)) && typeof(T).IsAssignableFrom(actualType)) { PrettyLog.Error("{0} can not be converted to {1}", actualType, typeof(T)); typedSnapshot = null; return(false); } typedSnapshot = (T)snapshot; return(true); }
public void DeserializeFromClipboard() { var data = GUIUtility.systemCopyBuffer; try { _serializedData = data; Deserialize(); PrettyLog.Log("<color=maroon>{0} is loaded. Data size: {1}</color>", name, _serializedData.Length); } catch (JsonReaderException ex) { PrettyLog.Error("<color=red>Load failed: Invalid behaviour tree data</color>\n<color=blue>Exception:</color>\n{0}\n\n<color=blue>Data</color>\n{1}", ex, data); } }
public static Color ByWeb(string htmlString) { Color ret; if (string.IsNullOrEmpty(htmlString)) { ret = Color.clear; } else if (!ColorUtility.TryParseHtmlString(htmlString, out ret)) { PrettyLog.Error( "Invalid HTML color string: {0}. It needs to be a web color name, or a hex color with a leading '#'", htmlString); ret = Color.clear; } return(ret); }
bool ValidateType(Node node) { var nodeType = node.GetType(); var selfType = GetType(); var attr = selfType.GetAttribute <CustomNodeEditorAttribute>(false); if (attr == null) { PrettyLog.Error("{0} has no CustomNodeEditor attribute", selfType); return(false); } if (nodeType != attr.nodeType) { PrettyLog.Error("{0} can only be used as {1}'s editor ({2} given)", selfType, attr.nodeType, nodeType); return(false); } return(true); }
protected override Node Select(Blackboard snapshot) { if (children.Count == 0) { return(null); } // initialize the weights with same values if not correctly set if (weights == null || weights.Length == 0 || Array.TrueForAll(weights, w => w == 0)) { if (weights == null || weights.Length == 0) { weights = new float[children.Count]; } for (int i = 0; i < weights.Length; i++) { weights[i] = 1; } } var arrCdf = new float[weights.Length]; for (int i = 0; i < arrCdf.Length; i++) { if (i == 0) { arrCdf[i] = weights[i]; } else { arrCdf[i] = arrCdf[i - 1] + weights[i]; } } var rnd = UnityEngine.Random.Range(0, arrCdf[arrCdf.Length - 1]); int min = 0, max = arrCdf.Length - 1; var index = BinarySearchInRanges(arrCdf, rnd, min, max); if (index < 0 || index >= children.Count) { PrettyLog.Error("Random weighted sampling error: result index is {0}", index); } return(children[index]); }
public Node AddNodes(params Node[] newChildren) { if (IsLeaf) { PrettyLog.Error("{0} is a leaf node that can't hold any child", DisplayName); } if (newChildren == null || newChildren.Length == 0) { return(this); } for (int i = 0; i < newChildren.Length; i++) { var newChild = newChildren[i]; newChild.UpdateParent(this); children.Add(newChild); } return(this); }