示例#1
0
 public static singleton getInstance()
 {
     if (instance == null)
     {
         instance = new singleton();
     }
     return(instance);
 }
 private static void Main(string[] args)
  {
      Mysingleton Object = Mysingleton.sravs;
      Object.check();
      singleton obj1 = singleton.sravs;
      obj1.worked();
      Console.ReadKey();
  }
示例#3
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject g = GameObject.FindGameObjectWithTag("MainCamera");

        infoWorld     = g.GetComponent <singleton>();
        audio         = GetComponent <AudioSource>();
        pop_transform = infoWorld.canvas.GetComponent <AudioSource>();
    }
示例#4
0
文件: singleton.cs 项目: oxrock/BOIDS
 // Use this for initialization
 void Awake()
 {
     if (singleton.instance != null)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
     }
 }
示例#5
0
 private void Awake()
 {
     if (instance == null)
     {
         DontDestroyOnLoad(this.gameObject);
         instance = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
示例#6
0
 public static void Main()
 {
     for (int i = 0; i < 7; i++)
     {
         singleton a = singleton.Create();
         a.VAL = i;
     }
     for (int i = 0; i < 7; i++)
     {
         singleton a = singleton.Create();
         Console.WriteLine(a.VAL);
     }
 }
示例#7
0
    void Awake()
    {
        singleton data = singleton.getInstance();

        int     cellCount = data.cellCount;
        float   size      = prefub.GetComponent <MeshFilter>().sharedMesh.bounds.size.x *prefub.transform.localScale.x;
        Vector3 start     = new Vector3(cellCount * size / 2.0f - size / 2, 0.1f, cellCount * size / 2.0f - size / 2);

        arr = new CellBehaviour[cellCount, cellCount];

        for (int i = 0; i < cellCount; i++)
        {
            for (int j = 0; j < cellCount; j++)
            {
                GameObject obj = Instantiate(prefub.gameObject);
                arr[i, j] = obj.GetComponent <CellBehaviour>();
                obj.transform.SetParent(world.transform);
                obj.transform.localPosition = start;

                data.navigate.SetPoint(i, j, obj.transform);
                start.x -= size;
            }
            start.z -= size;
            start.x  = cellCount * size / 2 - size / 2;
        }

        data.navigate.CreateNavMesh();

        for (int i = 0; i < cellCount; i++)
        {
            for (int j = 0; j < cellCount; j++)
            {
                arr[i, j].SetNode(data.navigate.GetNode(i, j));
            }
        }

        for (int i = 0; i < data.enemyCount; i++)
        {
            Vector3        position = data.navigate.GetNode(Random.Range(0, cellCount - 1), Random.Range(0, cellCount - 1)).position;
            EnemyBehaviour agent    = Instantiate(walker.gameObject, position, Quaternion.identity).GetComponent <EnemyBehaviour>();
            data.enemys.Add(agent);
        }

        info.text = string.Format("world side {0}\nenemy count {1}", data.cellCount, data.enemyCount);
    }
示例#8
0
 public static singleton Create()
 {
     if (!full)
         {
             singleton nowy = new singleton();
             Tab[cur] = nowy;
             if (cur>=MAX-1)
                 full=true;
             return nowy;
         }
         else
         {
             cur++;
             if(cur>=MAX)
                 cur=0;
             return Tab[cur];
         }
 }
    // Create as a static method so this can be called using
    // just the class name (no object instance is required).
    // It simplifies other code because it will always return
    // the single instance of this class, either newly created
    // or from the session
    public static singleton GetCurrentSingleton()
    {
        singleton oSingleton;

        if (null == System.Web.HttpContext.Current.Session[SESSION_SINGLETON])
        {
            //No current session object exists, use private constructor to
            // create an instance, place it into the session
            oSingleton = new singleton();
            System.Web.HttpContext.Current.Session[SESSION_SINGLETON] = oSingleton;
        }
        else
        {
            //Retrieve the already instance that was already created
            oSingleton = (singleton)System.Web.HttpContext.Current.Session[SESSION_SINGLETON];
        }
        //Return the single instance of this class that was stored in the session
        return(oSingleton);
    }
示例#10
0
 static public singleton Create()
 {
     if (!full)
     {
         singleton nowy = new singleton();
         Tab[cur] = nowy;
         if (cur >= MAX - 1)
         {
             full = true;
         }
         return(nowy);
     }
     else
     {
         cur++;
         if (cur >= MAX)
         {
             cur = 0;
         }
         return(Tab[cur]);
     }
 }
示例#11
0
 private void Awake()
 {
     sg = this;
 }