Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

geckoo

Moderators
  • Content Count

    2,816
  • Joined

  • Last visited

  • Days Won

    156

geckoo last won the day on June 21

geckoo had the most liked content!

Community Reputation

812 Excellent

About geckoo

  • Rank
    Суета сует и погоня за ветром

Profile Information

  • Gender
    Male
  • Location:
    - между раем и адом

Recent Profile Visitors

5,049 profile views
  1. geckoo

    STR!PES

    Harder faster and optimized using Unity 2019 - available on itch.io ++ https://geckoo1337.itch.io/strpes
  2. geckoo

    Long time

    Hi Reaperkan. I hope that all is fine for you We live another era on forum - just a few people share their scripts, an opinion or something else. You can find always some questions or request so as to "add multiplayer to FPSkit", but nothing more. In other words, we die - slowly but surely. It's a pity ++
  3. geckoo

    Unity 2019.1

    Hello friends. Just a few words so as to share with you a recent experience. Working on my project STR!PES, I updated my Unity version to 2019.1 expecting some minor changes - as usual, it's always a little bit disturbing to update Unity for a newer version because sometimes old projects are broken or don't work correctly anymore. A little bit anxious I launched STR!PES on my new Unity version (I used Unity 2018.2 before) - and I noticed more or less 70 errors. I erased all previous log files, keeping only Assets folder with scripts, sounds, shaders, etc. After a project reconfiguration, all works fine as expected, but... Previously my project was good - oscillating between 25/45 batches. Now it stays constant - exactly 17 batches during all process and main execution is really really more smooth. With naked eye I notice a real improvement. I tried searching some explaination, willing to understand what it means, but I don't understand all features which have been added in newer Unity version. Now I am checking my previous projects (abaddon, theorem and more) so as to evaluate them under Unity 2019. I am very surprised by the result - better than I expected. Have you noticed too some improvement with your own projects? Have a nice day (like me today) ++
  4. geckoo

    Pool System

    A simple script so as to test the previous : SimplePoolSystem.PreLoadInstances to fill pool, SimplePoolSystem.GetInstance to activate an object, SimplePoolSystem.StoreInstance to store it for a next use ++ using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public int width = 10; public int height = 10; public GameObject obj; public int preloadedObjects = 10; IEnumerator Start() { SimplePoolSystem.PreLoadInstances(obj, preloadedObjects, null); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { var lol = SimplePoolSystem.GetInstance(obj, null); lol.transform.position = new Vector3(x, y, 0); yield return new WaitForSeconds(0.1f); StartCoroutine(dd(lol)); } } } IEnumerator dd(GameObject go) { yield return new WaitForSeconds(1f); SimplePoolSystem.StoreInstance(go); } }
  5. geckoo

    Pool System

    Creating objects, usually we instantiate them. Then we can destroy them after use. However it requires some resource and when many instantiated objects must be created, there is an acceptable limit before lag. To avoid wasted resource, it is recommended to use a pooling sustem which preloads those objects, setting them active and storing them for a new use. This way, we limit objects in scene, using always the same (but you have to reset them) ++ using System.Collections.Generic; using UnityEngine; public static class SimplePoolSystem { private static Dictionary<string, List<GameObject>> pool = new Dictionary<string, List<GameObject>>(); private const string nameEnding = "(Clone)"; public static void PreLoadInstances(GameObject prefab, int number, Transform parent = null) { GameObject prefabInstance; bool setParent = parent != null; for (int i = 0; i < number; i++) { prefabInstance = Instantiate(prefab); if (setParent) prefabInstance.transform.SetParent(parent); StoreInstance(prefabInstance); } } private static GameObject GetInstanceFromPool(GameObject prefab) { GameObject prefabInstance = null; List<GameObject> instancesList; if (pool.TryGetValue(GeneratePrefabInstancesName(prefab), out instancesList)) if (instancesList.Count != 0) { prefabInstance = instancesList[0]; instancesList.RemoveAt(0); } else { Debug.Log("Not enough objects have been preloaded - create a new one"); prefabInstance = Instantiate(prefab); } return prefabInstance; } public static GameObject GetInstance(GameObject prefab, Transform parent = null) { GameObject prefabInstance = GetInstanceFromPool(prefab); prefabInstance.SetActive(true); if (parent != null) prefabInstance.transform.SetParent(parent); return prefabInstance; } public static void StoreInstance(GameObject gameObjectInstance) { gameObjectInstance.gameObject.SetActive(false); List<GameObject> instancesList; if (pool.TryGetValue(gameObjectInstance.name, out instancesList)) instancesList.Add(gameObjectInstance); else { instancesList = new List<GameObject>(); instancesList.Add(gameObjectInstance); pool.Add(gameObjectInstance.name, instancesList); } } public static void Clear() { pool.Clear(); } private static GameObject Instantiate(GameObject prefab) { GameObject prefabInstance = Object.Instantiate(prefab); prefabInstance.name = GeneratePrefabInstancesName(prefab); return prefabInstance; } private static string GeneratePrefabInstancesName(GameObject prefab) { return prefab.name + nameEnding; } }
  6. geckoo

    Time To Sprite

    The same script but with another font - 7*5 pixels ++ using System.Collections; using UnityEngine; // convert time to sprite [RequireComponent(typeof(SpriteRenderer))] public class TimeToSprite : MonoBehaviour { Texture2D mTex; private Sprite mySprite; // sprite size which can be using like a fontSize [Range(1, 10)] public int fontSize = 5; // font color public Color _color = Color.black; // each number use 7x5 pixels + 1 as space between them int marging = 6; // size int width; int height = 7; // seven pixel float time; // for deltaTime string str; // time as string string[] sChars = new string[] { "x", "x", "x", "x" }; // saved chars // each column will be displayed according a bit code int[] num0 = new int[] { 127, 65, 73, 65, 127 }; int[] num1 = new int[] { 65, 65, 127, 64, 64 }; int[] num2 = new int[] { 121, 73, 73, 73, 79 }; int[] num3 = new int[] { 73, 73, 73, 73, 127 }; int[] num4 = new int[] { 15, 8, 8, 8, 127 }; int[] num5 = new int[] { 79, 73, 73, 73, 121 }; int[] num6 = new int[] { 127, 73, 73, 73, 121 }; int[] num7 = new int[] { 1, 1, 1, 1, 127 }; int[] num8 = new int[] { 127, 73, 73, 73, 127 }; int[] num9 = new int[] { 79, 73, 73, 73, 127 }; int[] _dot = new int[] { 0, 0, 64, 0, 0 }; void Awake() { this.transform.localScale = new Vector3(fontSize, fontSize, 0); width = ((4 * marging) - 1); // because we use only 4 chars - 00.0 if (mTex == null) mTex = new Texture2D(width, height, TextureFormat.ARGB32, true); mTex.wrapMode = TextureWrapMode.Clamp; mTex.filterMode = FilterMode.Point; // pixel it mTex.Apply(); this.GetComponent<SpriteRenderer>().flipX = false; this.GetComponent<SpriteRenderer>().flipY = true; } // clear some part of the sprite according a new pattern void refresh(int shift) { for (int i = 0; i < height; i++) for (int j = 0; j < marging; j++) mTex.SetPixel(j + shift, i, Color.clear); } void UpdateTexture() { mTex.Apply(); // apply new texture as sprite after modification var mySprite = Sprite.Create(mTex, new Rect(0.0f, 0.0f, mTex.width, mTex.height), new Vector2(0.5f, 0.5f), 100.0f, (uint)0); this.transform.GetComponent<SpriteRenderer>().sprite = mySprite; } void timer() { // we use only one digit str = time.ToString("00.0"); for (int i = 0; i < str.Length; i++) { // check if the new number is the same (or not) than the previous if (str.Substring(i, 1) != sChars[i]) { // erase the previous pixel zone for this index refresh(i * marging); if (str.Substring(i, 1) == "0") pencil(i * marging, num0, _color); else if (str.Substring(i, 1) == "1") pencil(i * marging, num1, _color); else if (str.Substring(i, 1) == "2") pencil(i * marging, num2, _color); else if (str.Substring(i, 1) == "3") pencil(i * marging, num3, _color); else if (str.Substring(i, 1) == "4") pencil(i * marging, num4, _color); else if (str.Substring(i, 1) == "5") pencil(i * marging, num5, _color); else if (str.Substring(i, 1) == "6") pencil(i * marging, num6, _color); else if (str.Substring(i, 1) == "7") pencil(i * marging, num7, _color); else if (str.Substring(i, 1) == "8") pencil(i * marging, num8, _color); else if (str.Substring(i, 1) == "9") pencil(i * marging, num9, _color); else if (str.Substring(i, 1) == ".") pencil(i * marging, _dot, _color); } // save the char at its index so as to compare it with the next sequence sChars[i] = str.Substring(i, 1); } // update our texture UpdateTexture(); } // convert a number as a bool array private bool[] ConvertByteToBoolArray(byte b) { bool[] r = null; r = new bool[height]; for (int i = 0; i < r.Length; i++) r[i] = (b & (1 << i)) == 0 ? false : true; return r; } void pencil(int shift, int[] seq, Color color) { // read each integer as pixels column for (int i = 0; i < seq.Length; i++) { var lol = (byte)seq[i]; var ss = ConvertByteToBoolArray(lol); // read bool array to know where a black pixel must be displayed for (int j = 0; j < height; j++) if (ss[j] == true) mTex.SetPixel(shift + i, j, color); } } ////////////////////////////////////////////////////////// // as an example, we show deltaTime IEnumerator Start() { timer(); while (true) { yield return new WaitForSeconds(0.09f); timer(); } } private void Update() { time += Time.deltaTime; // set max if (time >= 99.9f) time = 99.9f; } }
  7. geckoo

    Time To Sprite

    Displaying a text on screen, usually we create a canvas as UI and it works very well on Unity. However I wanted to code a script which could apply a text or a value as a sprite - in other words, I tried to create an alternative UI, setting some features, creating my own font, etc. As an example, the basical code below allows to display time.deltaTime, checking values, applying modification, reading an array of booleans (according an integer) so as to paint some pixels on sprite (5*3). Also it could be used on a weapon so as to show how many bullets are available in the cartridge or maybe for health, and more. Simply put it on a game object. I hope that it will be useful someone ++ using System.Collections; using UnityEngine; // convert time to sprite [RequireComponent(typeof(SpriteRenderer))] public class TimeToSprite : MonoBehaviour { Texture2D mTex; private Sprite mySprite; // sprite size which can be using like a fontSize [Range(1, 10)] public int fontSize = 5; // font color public Color _color = Color.black; // each number use 5x3 pixels + 1 as space between them int marging = 4; // size int width; int height = 5; // five pixel float time; // for deltaTime string str; // time as string string[] sChars = new string[] { "x", "x", "x", "x" }; // saved chars // each column will be displayed according a bit code int[] num0 = new int[] { 31, 17, 31 }; int[] num1 = new int[] { 17, 31, 16 }; int[] num2 = new int[] { 29, 21, 23 }; int[] num3 = new int[] { 21, 21, 31 }; int[] num4 = new int[] { 07, 04, 31 }; int[] num5 = new int[] { 23, 21, 29 }; int[] num6 = new int[] { 31, 21, 29 }; int[] num7 = new int[] { 01, 01, 31 }; int[] num8 = new int[] { 31, 21, 31 }; int[] num9 = new int[] { 23, 21, 31 }; int[] _dot = new int[] { 00, 16, 00 }; void Awake() { this.transform.localScale = new Vector3(fontSize, fontSize, 0); width = ((4 * marging) - 1); // because we use only 4 chars - 00.0 if (mTex == null) mTex = new Texture2D(width, height, TextureFormat.ARGB32, true); mTex.wrapMode = TextureWrapMode.Clamp; mTex.filterMode = FilterMode.Point; // pixel it mTex.Apply(); this.GetComponent<SpriteRenderer>().flipX = false; this.GetComponent<SpriteRenderer>().flipY = true; } // clear some part of the sprite according a new pattern void refresh(int shift) { for (int i = 0; i < height; i++) for (int j = 0; j < marging; j++) mTex.SetPixel(j + shift, i, Color.clear); } void UpdateTexture() { mTex.Apply(); // apply new texture as sprite after modification var mySprite = Sprite.Create(mTex, new Rect(0.0f, 0.0f, mTex.width, mTex.height), new Vector2(0.5f, 0.5f), 100.0f, (uint)0); this.transform.GetComponent<SpriteRenderer>().sprite = mySprite; } void timer() { // we use only one digit str = time.ToString("00.0"); for (int i = 0; i < str.Length; i++) { // check if the new number is the same (or not) than the previous if (str.Substring(i, 1) != sChars[i]) { // erase the previous pixel zone for this index refresh(i * marging); if (str.Substring(i, 1) == "0") pencil(i * marging, num0, _color); else if (str.Substring(i, 1) == "1") pencil(i * marging, num1, _color); else if (str.Substring(i, 1) == "2") pencil(i * marging, num2, _color); else if (str.Substring(i, 1) == "3") pencil(i * marging, num3, _color); else if (str.Substring(i, 1) == "4") pencil(i * marging, num4, _color); else if (str.Substring(i, 1) == "5") pencil(i * marging, num5, _color); else if (str.Substring(i, 1) == "6") pencil(i * marging, num6, _color); else if (str.Substring(i, 1) == "7") pencil(i * marging, num7, _color); else if (str.Substring(i, 1) == "8") pencil(i * marging, num8, _color); else if (str.Substring(i, 1) == "9") pencil(i * marging, num9, _color); else if (str.Substring(i, 1) == ".") pencil(i * marging, _dot, _color); } // save the char at its index so as to compare it with the next sequence sChars[i] = str.Substring(i, 1); } // update our texture UpdateTexture(); } // convert a number as a bool array private bool[] ConvertByteToBoolArray(byte b) { bool[] r = null; r = new bool[height]; // don't read all bit for (int i = 0; i < r.Length; i++) r[i] = (b & (1 << i)) == 0 ? false : true; return r; } void pencil(int shift, int[] seq, Color color) { // read each integer as pixels column for (int i = 0; i < seq.Length; i++) { var lol = (byte)seq[i]; var ss = ConvertByteToBoolArray(lol); // read bool array to know where a black pixel must be displayed for (int j = 0; j < height; j++) if (ss[j] == true) mTex.SetPixel(shift + i, j, color); } } ////////////////////////////////////////////////////////// // as an example, we show deltaTime IEnumerator Start() { timer(); while (true) { yield return new WaitForSeconds(0.09f); timer(); } } private void Update() { time += Time.deltaTime; // set max if (time >= 99.9f) time = 99.9f; } }
  8. geckoo

    Mathf.PI

    Thank you Isaak for your interesting answer. I was a little bit disappointed by the first answer which didn't give any solid explanation - excepted a single line. Yours is more detailled and convinced me. I am trying to reach the best optimization coding my project STR!PES on which I am working. Actually it runs using a few batches (between 35/45 maximum) but I continue to find a way to go down. Finally I can reach a really low execution - enough to be playable on a old mobile device. Procedural generation and geometry in games are just fascinating. When the game is really speed with many stripes rushing on the center, I have those values in inspector ++ CPU : main 13.0 ms (at start 11.9) render thread 1.7 ms (at start 1.1) batches : 43 (at start 25 with an easy level) I noticed that I totally forgot to talk about game itself - just expanding some explanation about code. At the link below you can find my game STR!PES https://geckoo1337.itch.io/strpes
  9. Великая проблема заключается в следующем - ничего не понятно. Мне кажется, что тебе нужен новый микрофон
  10. geckoo

    Theorem

    All keys have been activated ++
  11. Test it adding this code : private void Update() { if (Input.GetKeyDown(KeyCode.Space)) damage(20); if (Input.GetKeyDown(KeyCode.KeypadEnter)) bonus(15); }
  12. Hello. I did a script so as to manage health bar using the old GUI. Take a look at the link below. I hope that it can help you ++
  13. Often I use this script so as to create a little health code using the old GUI which is not bad. Of course, it's could be better to use Canvas, but it's a good stuff. It displays a thin line with colors according screen resolution - like in my game Abaddon (and others). It creates a few textures at start. Also I implemented a couroutine to decrease progressively health and another one if player recover his health (bonus function). You have to call the damage function setting a value and you will see health line decreasing green to red. Only put this script on an object - no more. You can use this script as a timer too - it's the same logical process. I did that so as to answer to a question on our forum. I hope that it will be useful someone ++ using System.Collections; using UnityEngine; public class healthScript : MonoBehaviour { public float hp = 100; // textures for health bar private Texture2D _red; private Texture2D _green; private Texture2D _black; // color for health bar private Color32 cRed = new Color32(205, 40, 0, 200); private Color32 cGreen = new Color32(40, 205, 0, 200); private Color32 cWhite = new Color32(33, 33, 33, 255); void Awake() { _red = CreateTexture(cRed); _green = CreateTexture(cGreen); _black = CreateTexture(cWhite); } // creates some textures private Texture2D CreateTexture(Color32 cor) { int x = 0; int y = 0; int w = 8; // 8x8 int h = 8; // creates new texture Texture2D tex = new Texture2D(w, h, TextureFormat.ARGB32, false); for (int i = 0; i < w * h; i++) { if (x == w) { x = 0; y++; } tex.SetPixel(x, y, cor); // set each pixel color x++; } tex.Apply(); // applies texture return tex; // return texture } public void damage(int dmg) { StartCoroutine(decreaseHealth(dmg)); } // decrease health IEnumerator decreaseHealth(int damage) { for (int i = 0; i < damage; i++) { hp--; if (hp <= 0) hp = 0; yield return new WaitForSeconds(0.015f); } } public void bonus(int bns) { StartCoroutine(increaseHealth(bns)); } // increase health - bonus IEnumerator increaseHealth(int power) { for (int i = 0; i < power; i++) { hp++; if (hp >= 100) hp = 100; yield return new WaitForSeconds(0.015f); } } // creates health bar void OnGUI() { GUI.DrawTexture(new Rect(Screen.width / 2 - Screen.width / 8 - 1, Screen.height - Screen.height + Screen.height / 80 - 1, Screen.width / 4 + 2, // black thin line 4 * (Screen.height / 200) + 2), _black); GUI.DrawTexture(new Rect(Screen.width / 2 - Screen.width / 8, Screen.height - Screen.height + (Screen.height / 80), Screen.width / 4, // red line 4 * (Screen.height / 200)), _red); // we don't use some arbitrary variables - only screen height and width as value GUI.DrawTexture(new Rect(Screen.width / 2 - Screen.width / 8, Screen.height - Screen.height + (Screen.height / 80), Screen.width / 4 * (float)hp / 100, // green line 4 * (Screen.height / 200)), _green); } }
  14. geckoo

    LAN Option?

    https://docs.unity3d.com/Manual/UNetManagerHUDLanMode.html
  15. Interesting question. At first, I would like to say that you have to inform players that your game collects some info during process. But in the same time, there is nothing inside these user data - it's like a leaderboard but anonymous. By consequence, I don't know... If you take a look at the request from GooglePlay, we read those lines : Google Play requires developers to provide a valid privacy policy when the app requests or handles sensitive user or device information. Your app requests sensitive permissions (e.g. camera, microphone, accounts, contacts, or phone) or user data, but does not include a valid privacy policy (bla bla bla)... According what I read I think that you have not to include a privacy policy because you are not collecting sensitive user information - only a winner/looser state. However, I am not an expert in laws. The best you can do - ask them directly ++
×
×
  • Create New...