Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[Challenge]The ECS API is a work in progress could a 4k source code challenge be a good test?

Discussion in 'Entity Component System and C# Job system' started by Arowx, Jan 11, 2019.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    6,683


    The idea is that often amazing demos can be made with very small code bases, e.g. 4k demo scene.

    ECS is very powerful but also quite verbose, so could a 4k source code programming challenge allow people to show of tricks and techniques that we could use to minimize and simplify our ECS code and have fun showing off our skills and the power of Unity ECS.

    • The challenge would be to make a demo that is based on one < 4k source code file that will run in a default Unity scene.
    • The program could be a game or demo...

    So do you think you can write something in Pure ECS that fits in under 4k and blows people away?

    What style of ECS would you use and how could you refactor your code and ECS to minimise it's footprint?

    Who knows maybe Unity could convinve the demo scene to add it as a category?

    Also are there any hurdles in the current ECS coverage that would limit what can be made?
     
    Last edited: Jan 12, 2019
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    3,185
    What the video has to do with rest of topic?
    Should you rather ask this questions in Tiny Project sub forum?
     
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    6,683
    It's an example of a demo scene project that shows some of the amazing things that can be done from small code bases without Unity and ECS.

    It's a tiny ECS source code challenge and not a tiny build file size challenge

    Here's an example (none ECS) based on the idea of a source code business card (the code needs to fit onto a buisness card) using Unity...

    Code (CSharp):
    1. using UnityEngine;using UnityEngine.Rendering;
    2. public class UBC:MonoBehaviour{private int[] txt={524288,1432917,1906002,1383925};private Material m;
    3. void Start(){m=new Material(Shader.Find("Standard"));m.SetFloat("_Metallic", 1f);m.SetFloat("_Glossiness",1f);int y=txt.Length;for(int i=0;i<txt.Length;i++){int x=10;for(int b=1;b<=1048576;b=b<<1){if((txt[i]&b)>0)B(x,y);x--;}y--;}G(10,10);GameObject p=new GameObject("ReflectionProbe");ReflectionProbe pc=p.AddComponent<ReflectionProbe>()as ReflectionProbe;pc.resolution=256;pc.size=new Vector3(20,20,20);p.transform.position=new Vector3(0,5,0);pc.mode=ReflectionProbeMode.Realtime;pc.refreshMode=ReflectionProbeRefreshMode.EveryFrame; }
    4. void B(int x,int y){GameObject b=GameObject.CreatePrimitive(PrimitiveType.Sphere);b.transform.position=new Vector3(x,y,0f);b.GetComponent<Renderer>().material=m;}
    5. void C(int x,int z,bool red){float t=2f;GameObject c=GameObject.CreatePrimitive(PrimitiveType.Cube);Vector3 s=c.transform.localScale;s*=t;c.transform.localScale=s;c.transform.position=new Vector3(x*t,-3,z*t);c.GetComponent<Renderer>().material.color=red?Color.red:Color.white;}
    6. void G(int x,int z){bool c=false;for(int a=-x;a<x;a++){for(int b=-z;b<z;b++){C(a,b,c);c=!c;}c=!c;}}}
    If you run it you get this, note some developers have written ray tracing routines that generate this kind of image using C and a couple of libraries, what can we do with Unity?


    Here is the long form version if anyone wants to make their own Unity business card...
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5.  
    6. public class UBC1 : MonoBehaviour {
    7.  
    8.     // Name In Spheres
    9.     // Arowx
    10.     //  |   |   |   |   |   <
    11.     // -x-------------------
    12.     // x-x-xxx-xxx-x-x-x-x-x
    13.     // xxx-x---x-x-x-x-x--x-
    14.     // x-x-x---xxx-xxxxx-x-x
    15.  
    16.     private int[] txt = { 524288, 1432917, 1906002, 1383925};
    17.  
    18.     private Material mat;
    19.  
    20.     void Start () {
    21.         mat = new Material(Shader.Find("Standard"));
    22.         mat.SetFloat("_Metallic", 1f);
    23.         mat.SetFloat("_Glossiness", 1f);
    24.  
    25.         int y = txt.Length;
    26.         for (int i = 0; i < txt.Length; i++)
    27.         {
    28.             int x = 10;
    29.             for (int b = 1; b <= 1048576; b = b << 1)
    30.             {
    31.                 if ((txt[i] & b) > 0) Ball(x, y);
    32.                 x--;
    33.             }
    34.             y--;
    35.         }
    36.  
    37.         Grid(10, 10);
    38.  
    39.         GameObject probeGameObject = new GameObject("ReflectionProbe");
    40.         ReflectionProbe probeComponent = probeGameObject.AddComponent<ReflectionProbe>() as ReflectionProbe;
    41.         probeComponent.resolution = 256;
    42.         probeComponent.size = new Vector3(20, 20, 20);
    43.         probeGameObject.transform.position = new Vector3(0, 5, 0);
    44.  
    45.         probeComponent.mode = ReflectionProbeMode.Realtime;
    46.         probeComponent.refreshMode = ReflectionProbeRefreshMode.EveryFrame;
    47.  
    48.     }
    49.  
    50.     void Ball(int x, int y)
    51.     {
    52.         GameObject ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    53.         ball.transform.position = new Vector3(x, y, 0f);
    54.         ball.GetComponent<Renderer>().material = mat;
    55.     }
    56.  
    57.     void Cube(int x, int z, bool red)
    58.     {
    59.         float scale = 2f;
    60.  
    61.         GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    62.  
    63.         Vector3 s = cube.transform.localScale;
    64.         s *= scale;
    65.         cube.transform.localScale = s;
    66.  
    67.         cube.transform.position = new Vector3(x * scale, -3, z * scale);
    68.         cube.GetComponent<Renderer>().material.color = red ? Color.red : Color.white;
    69.     }
    70.  
    71.     void Grid(int x, int z)
    72.     {
    73.         bool c = false;
    74.         for (int px = -x; px < x; px++)
    75.         {
    76.             for (int pz = -z; pz < z; pz++)
    77.             {
    78.                 Cube(px, pz, c);
    79.                 c = !c;
    80.             }
    81.             c = !c;
    82.         }
    83.     }
    84. }
    85.  
     
    Last edited: Jan 12, 2019