Friday, December 31, 2021

Check animator is playing or finshed


https://answers.unity.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html?page=1&pageSize=5&sort=votes


 just send your animation name in CurrentAnimation you want to check.

  1. public IEnumerator CheckAnimationCompleted(string CurrentAnim, Action Oncomplete)
  2. {
  3. while (!Animator.GetCurrentAnimatorStateInfo(0).IsName(CurrentAnim))
  4. yield return null;
  5. if (Oncomplete != null)
  6. Oncomplete();
  7. }

calling coroutine

  1. StartCoroutine(CheckAnimationCompleted("Shoot", () =>
  2. {
  3. Animator.SetBool("Shoot", false);
  4. // Your any code
  5. }
  6. ));

Wednesday, December 1, 2021

Check gameobject is visible on screen

 


Answer by Taylor-Libonati 

Here's the method I used with success:

Convert the position of the object into viewport space. If the viewport space is within 0-1 you are in the cameras frustum. This method also allows you to add a margin amount if you want, so that objects turn on when they are almost in view.

  1. Vector3 screenPoint = playerHead.leftCamera.WorldToViewportPoint(targetPoint.position);
  2. bool onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;

Instantiate Photon object without using Resources folder

 https://forum.unity.com/threads/solved-photon-instantiating-prefabs-without-putting-them-in-a-resources-folder.293853/


PUN 2 is using a PrefabPool to get a GameObject instance. You can write your own but you can also very easily fill the existing pool of type DefaultPool.

The attached MonoBehaviour has a list of "prefabs", which can be edited in the Inspector. This reference means that the assets don't have to be in the Resources folder. In Start(), the list is used to "fill" the DefaultPool. That's enough.

Code (CSharp):
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using Photon.Pun;
  4.  
  5.  
  6. public class PreparePool : MonoBehaviour
  7. {
  8.     public List<GameObject> Prefabs;
  9.  
  10.     void Start ()
  11.     {
  12.         DefaultPool pool = PhotonNetwork.PrefabPool as DefaultPool;
  13.         if (pool != null && this.Prefabs != null)
  14.         {
  15.             foreach (GameObject prefab in this.Prefabs)
  16.             {
  17.                 pool.ResourceCache.Add(prefab.name, prefab);
  18.             }
  19.         }
  20.     }
  21. }

Map circle coord to rectanglar coord

 https://stackoverflow.com/questions/13211595/how-can-i-convert-coordinates-on-a-circle-to-coordinates-on-a-square


See Mapping a Square to a Circle. There's also a nice visualization for the mapping. You get:

xCircle = xSquare * sqrt(1 - 0.5*ySquare^2)
yCircle = ySquare * sqrt(1 - 0.5*xSquare^2)

Thursday, November 18, 2021

prevent hacking unity

 https://www.alanzucconi.com/2015/09/02/a-practical-tutorial-to-hack-and-protect-unity-games/

Monday, October 25, 2021

Grass simulator by shader graph




 Grass simulator by shader graph


https://www.gameslave.me/p/pasto-interactivo.html

Sunday, October 24, 2021

https://github.com/PhotonEngine

 https://github.com/PhotonEngine

Standard numeric format strings

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers


https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0#the-format-item

A format item has this syntax:

{index[,alignment][:formatString]}

Brackets denote optional elements. The opening and closing braces are required. (To include a literal opening or closing brace in the format string, see the Escaping Braces section in the Composite Formatting article.)

For example, a format item to format a currency value might appear like this:

C#
var value = String.Format("{0,-10:C}", 126347.89m);         
Console.WriteLine(value);

A format item has the following elements:

index
The zero-based index of the argument whose string representation is to be included at this position in the string. If this argument is null, an empty string will be included at this position in the string.

alignment
Optional. A signed integer that indicates the total length of the field into which the argument is inserted and whether it is right-aligned (a positive integer) or left-aligned (a negative integer). If you omit alignment, the string representation of the corresponding argument is inserted in a field with no leading or trailing spaces.

If the value of alignment is less than the length of the argument to be inserted, alignment is ignored and the length of the string representation of the argument is used as the field width.

formatString
Optional. A string that specifies the format of the corresponding argument's result string. If you omit formatString, the corresponding argument's parameterless ToString method is called to produce its string representation. If you specify formatString, the argument referenced by the format item must implement the IFormattable interface. Types that support format strings include:

However, note that any custom type can implement IFormattable or extend an existing type's IFormattable implementation.

The following example uses the alignment and formatString arguments to produce formatted output.

C#
// Create array of 5-tuples with population data for three U.S. cities, 1940-1950.
Tuple<string, DateTime, int, DateTime, int>[] cities = 
    { Tuple.Create("Los Angeles", new DateTime(1940, 1, 1), 1504277, 
                   new DateTime(1950, 1, 1), 1970358),
      Tuple.Create("New York", new DateTime(1940, 1, 1), 7454995, 
                   new DateTime(1950, 1, 1), 7891957),  
      Tuple.Create("Chicago", new DateTime(1940, 1, 1), 3396808, 
                   new DateTime(1950, 1, 1), 3620962),  
      Tuple.Create("Detroit", new DateTime(1940, 1, 1), 1623452, 
                   new DateTime(1950, 1, 1), 1849568) };

// Display header
var header = String.Format("{0,-12}{1,8}{2,12}{1,8}{2,12}{3,14}\n",
                              "City", "Year", "Population", "Change (%)");
Console.WriteLine(header);
foreach (var city in cities) {
   var output = String.Format("{0,-12}{1,8:yyyy}{2,12:N0}{3,8:yyyy}{4,12:N0}{5,14:P1}",
                          city.Item1, city.Item2, city.Item3, city.Item4, city.Item5,
                          (city.Item5 - city.Item3)/ (double)city.Item3);
   Console.WriteLine(output);
}
// The example displays the following output:
//    City            Year  Population    Year  Population    Change (%)
//  
//    Los Angeles     1940   1,504,277    1950   1,970,358        31.0 %
//    New York        1940   7,454,995    1950   7,891,957         5.9 %
//    Chicago         1940   3,396,808    1950   3,620,962         6.6 %
//    Detroit         1940   1,623,452    1950   1,849,568        13.9 %

Friday, October 22, 2021

ezyfox-server

 https://github.com/youngmonkeys/ezyfox-server?fbclid=IwAR3DBAFkeu2tow_Tvism2Of0pjSZmAFx7XbmheFot5DCYdh8syN7LMplq1w

Friday, October 8, 2021

Check android installed app

 

https://answers.unity.com/questions/627703/detect-if-app-is-installed-on-android.html

  1. public bool IsAppInstalled(string bundleID){
  2. #if UNITY_ANDROID
  3. AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  4. AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
  5. AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
  6. Debug.Log(" ********LaunchOtherApp ");
  7. AndroidJavaObject launchIntent = null;
  8. //if the app is installed, no errors. Else, doesn't get past next line
  9. try{
  10. launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage",bundleID);
  11. //
  12. // ca.Call("startActivity",launchIntent);
  13. }catch(Exception ex){
  14. Debug.Log("exception"+ex.Message);
  15. }
  16. if(launchIntent == null)
  17. return false;
  18. return true;
  19. #else
  20. return false;
  21. #endif

"market://details?q=pname:com.myCompany.myAppName/"

Application.OpenURL ("market://details?id=com.example.android"); misspellings

Thursday, September 30, 2021

Interesting extend Algorthim A*





 https://www.redblobgames.com/

Circular Obstacle Pathfinding

https://redblobgames.github.io/circular-obstacle-pathfinding/

How to find an end point of an arc given another end point, radius, and arc direction?

https://math.stackexchange.com/questions/275201/how-to-find-an-end-point-of-an-arc-given-another-end-point-radius-and-arc-dire


Calculate the length of the arc

https://www.dummies.com/education/math/geometry/how-to-determine-the-length-of-an-arc-2/



http://paulbourke.net/geometry/pointlineplane/


http://paulbourke.net/geometry/circlesphere/

Wednesday, September 15, 2021

Event Declaration

 https://stackoverflow.com/.../how-to-use-c-sharp-events...

Class containing events:
public class EventContainer : MonoBehaviour
{
public event Action<string> OnShow;
public event Action<string,float> OnHide;
public event Action<float> OnClose;
void Show()
{
Debug.Log("Time to fire OnShow event");
if(OnShow != null)
{
OnShow("This string will be received by listener as arg");
}
}
void Hide()
{
Debug.Log("Time to fire OnHide event");
if(OnHide != null)
{
OnHide ("This string will be received by listener as arg", Time.time);
}
}
void Close()
{
Debug.Log("Time to fire OnClose event");
if(OnClose!= null)
{
OnClose(Time.time); // passing float value.
}
}
}
Class which handles events of EventContainer class:
public class Listener : MonoBehaviour
{
public EventContainer containor; // may assign from inspector
void Awake()
{
containor.OnShow += Containor_OnShow;
containor.OnHide += Containor_OnHide;
containor.OnClose += Containor_OnClose;
}
void Containor_OnShow (string obj)
{
Debug.Log("Args from Show : " + obj);
}
void Containor_OnHide (string arg1, float arg2)
{
Debug.Log("Args from Hide : " + arg1);
Debug.Log("Container's Hide called at " + arg2);
}
void Containor_OnClose (float obj)
{
Debug.Log("Container Closed called at : " + obj);
}
}