public static Texture2D LoadEditorTexture(string relativePath, StringBuilder log = null) { #if UNITY_EDITOR var path = _scriptFolder + ImagesPath + relativePath; Texture2D tex; if (_cachedTextures.TryGetValue(path, out tex)) { return(tex); } tex = AssetDatabase.LoadAssetAtPath <Texture2D>(path); _cachedTextures[path] = tex; #if VERBOSE string logText = string.Format(" > {0} -> {1}", ImagesPath + relativePath, tex != null ? loadedStr : notFoundStr); if (log != null) { log.AppendLine(logText); } else { PrettyLog.Log(logText); } #endif return(tex); #else return(null); #endif }
Color32[] ExtractColorsFromTex(Sprite sprite) { var spriteRect = sprite.rect; var spriteId = sprite.GetInstanceID(); var tex = sprite.texture; Color32[] ret; if (!SpritePixelColors.TryGetValue(spriteId, out ret)) { if (_showDebugInfo) { PrettyLog.Log("making tex... id: {0} name: {1}", spriteId, tex.name); } var w = (int)spriteRect.width; var h = (int)spriteRect.height; var colors = new List <Color32>(); for (int xOffset = 0; xOffset < w; xOffset++) { var x = xOffset + (int)spriteRect.x; for (int yOffset = 0; yOffset < h; yOffset++) { var y = yOffset + (int)spriteRect.y; var pixelColor = tintByPixels ? tex.GetPixel(x, y) : Color.white; if (Mathf.Approximately(pixelColor.a, 0)) { continue; } colors.Add(pixelColor); } } ret = colors.ToArray(); SpritePixelColors[spriteId] = ret; } return(ret); }
public void Toss() { var dir = Quaternion.Euler(0, 0, tossAngle) * Vector2.right; GetComponent <Rigidbody2D>().AddForce(dir * speed, ForceMode2D.Impulse); PrettyLog.Log("toss"); }
protected override void Start(PlayerBlackboard snapshot) { PrettyLog.Log("take action: {0}", snapshot.action == null ? "(no action)" : snapshot.action.type.ToString()); if (snapshot.HasOrder) { snapshot.order.actionCallback = snapshot.action.startAction; } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); Type refType = null; Obj[] targets = null; if (!serializedObject.isEditingMultipleObjects && serializedObject.targetObject != null) { refType = serializedObject.targetObject.GetType(); targets = new[] { serializedObject.targetObject }; } else if (serializedObject.targetObjects != null) { refType = TypeUtility.FindCommonTypeWithin(serializedObject.targetObjects .Select(obj => obj != null ? obj.GetType() : null) .Where(t => t != null).ToArray()); targets = serializedObject.targetObjects; } if (refType == null) { return; } var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; var members = refType.GetMembers(flags).Where(m => GetCheersAttribute(m) != null) .Union( refType.GetInterfaceHierarchy().SelectMany(i => i.GetMembers(flags)) ); foreach (var member in members.Where(m => GetCheersAttribute(m) != null)) { var attr = GetCheersAttribute(member); if (attr == null) { continue; } switch (member.MemberType) { case MemberTypes.Method: DrawMethod((MethodInfo)member, attr, targets); break; case MemberTypes.Property: DrawProperty((PropertyInfo)member, attr, targets); break; default: PrettyLog.Log("TODO...Or never to be done. >_< Just use SerializedField instead"); break; } } }
public void GameOver(GameEndType end) { if (isOver) { return; } if (end > GameEndType.None) { isOver = true; } PrettyLog.Log("Game Over: {0}", end); ending.Show(end); }
static void InitializeAssets() { #pragma warning disable 0219 var assetPathRet = GetEditorAssetPath(); #pragma warning restore 0219 #if VERBOSE StringBuilder log = new StringBuilder("<color=maroon>[ Initializing Editor Assets... ]</color>\n"); log.AppendLine(assetPathRet); PrettyLog.Log(log.ToString()); #endif //VERBOSE }
void DrawToolbar() { // toolbar EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginDisabledGroup(!_hasTarget); if (GUILayout.Button("Save", EditorStyles.toolbarButton)) { _treeData.SaveAsset(); } if (GUILayout.Button("Load", EditorStyles.toolbarButton)) { _treeData.LoadAsset(); } if (GUILayout.Button("Clear", EditorStyles.toolbarButton)) { _treeData.rootNode.Clear(); } if (GUILayout.Button("Load Clipboard", EditorStyles.toolbarButton)) { _treeData.DeserializeFromClipboard(); } if (GUILayout.Button("Print Last Log", EditorStyles.toolbarButton)) { PrettyLog.Log(BTLogger.PrintLastLog(_treeData.rootNode)); } GUILayout.Space(10f); if (GUILayout.Button("Pan To (0,0)", EditorStyles.toolbarButton)) { _pan = Vector2.zero + CanvasRect.size * .5f; } if (GUILayout.Button("Scale -0.1", EditorStyles.toolbarButton)) { _scale -= .1f; } if (GUILayout.Button("Scale +0.1", EditorStyles.toolbarButton)) { _scale += .1f; } if (GUILayout.Button("Reset scale", EditorStyles.toolbarButton)) { _scale = 1f; } GUILayout.FlexibleSpace(); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); }
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); } }
Color32[] MakePieceColors(SpriteRenderer rdr) { var colors = ExtractColorsFromTex(rdr.sprite); var pieceCount = Mathf.RoundToInt(colors.Length / (chunkSize * chunkSize)); if (_showDebugInfo) { PrettyLog.Log("pixels: {0}, chunk size: {1}, piece count: {2}", colors.Length, chunkSize, pieceCount); } var ret = new Color32[pieceCount]; for (int colorIndex = 0, pieceIndex = 0; pieceIndex < pieceCount; colorIndex += chunkSize, pieceIndex++) { ret[pieceIndex] = colors[colorIndex]; } return(ret); }
void DrawMethod(MethodInfo method, See attr, Obj[] targets) { var @params = method.GetParameters(); var btnText = new GUIContent(GetCheersTitle(attr, method)); var canPress = true; if (@params.Length > 0) { btnText.text += "\n(Parameters are not supported yet)"; btnText.image = EditorHelper.icons.warning; canPress = false; } EditorGUI.BeginDisabledGroup(!canPress); var bgColor = attr.BackgroundColor == Color.clear ? GUI.backgroundColor : attr.BackgroundColor; var oldBgColor = GUI.backgroundColor; GUI.backgroundColor = bgColor; var btnStyle = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).button); if (attr.TextColor != Color.clear) { btnStyle.normal.textColor = attr.TextColor; btnStyle.hover.textColor = attr.TextColor; btnStyle.focused.textColor = attr.TextColor; btnStyle.active.textColor = attr.TextColor; } if (GUILayout.Button(btnText, btnStyle)) { StringBuilder retSb = new StringBuilder("=== Call Returns ===\n"); foreach (var t in targets) { var ret = method.Invoke(t, null); retSb.AppendLine(string.Format(" - {0} >> {1}", t.name, ret ?? "(null)")); } PrettyLog.Log(retSb.ToString()); } GUI.backgroundColor = oldBgColor; EditorGUI.EndDisabledGroup(); }
//No parameters static public void Broadcast(string eventType) { PrettyLog.Log("<color=maroon>Broadcasting»</color> {0}", eventType); #if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\""); #endif OnBroadcasting(eventType); Delegate d; if (eventTable.TryGetValue(eventType, out d)) { Callback callback = d as Callback; if (callback != null) { callback(); } else { throw CreateBroadcastSignatureException(eventType); } } }
public void Explode(SpriteRenderer rdr, Vector2?explodePos) { if (!_fakeExplodeForTest) { rdr.gameObject.SetActive(false); } if (rdr == null) { Debug.LogError("Sprite renderer is null", this); return; } var fx = MakeFx(rdr.transform); var colors = MakePieceColors(rdr); var particleCount = Mathf.Min(colors.Length, fx.main.maxParticles); fx.Emit(particleCount); var particles = new ParticleSystem.Particle[particleCount]; int num = fx.GetParticles(particles); // 用于计算粒子飞行向量 System.Func <ParticleSystem.Particle, Vector2, Vector2> ComputeFlyVec = (particle, blowPos) => { var dir = Quaternion.AngleAxis(Random.Range(-1f, 1f) * 30 + blowAngleVariant, Vector3.forward) * (particle.position.ToVector2() - blowPos).normalized; var force = fx.main.startSpeedMultiplier * (1f / (particle.startSize * chunkMass)) * .7f; return(dir * force); }; for (int i = 0; i < num; i++) { MakeParticle(ref particles[i], explodePos, colors[i], rdr, fx, ComputeFlyVec); } fx.SetParticles(particles, num); if (_showDebugInfo) { PrettyLog.Log("{1} explodes into {0} particles", fx.particleCount, rdr.name); } }
public void PrintFrameResult() { PrettyLog.Log("Frame result: \n{0}", _frameResult); }
public virtual void ByBaseVirtual() { PrettyLog.Log("virtual in BASE"); }
public void LoadAsset() { Deserialize(); PrettyLog.Log("<color=maroon>{0} is loaded. Data size: {1}</color>", name, _serializedData.Length); }
public void SaveAsset() { Serialize(); SaveTree(); PrettyLog.Log("<color=green>{0} is saved. Data size: {1}</color>", name, _serializedData.Length); }
void TestParamter(int a) { PrettyLog.Log("A={0}", a); }
public override void ByBaseVirtual() { base.ByBaseVirtual(); PrettyLog.Log("Virtual in butter"); }
protected override void ByBaseAbstract() { PrettyLog.Log("Abstract in butter"); }
public int ByInterface() { PrettyLog.Log("implements interface"); return(80016); }