protected void Awake()
 {
     if (_myPool == null && !ObjectPoolController._isDuringInstantiate)
     {
         CustomDebug.LogWarning("Poolable object " + name + " was instantiated without ObjectPoolController");
     }
 }
Beispiel #2
0
 void InitHandlerObjects()
 {
     foreach (var obj in layoutHandlerObjects)
     {
         if (obj != null)
         {
             ILayoutCellHandler handler = obj.GetComponent <ILayoutCellHandler>();
             if (handler != null)
             {
                 if (!layoutHandlers.Contains(handler))
                 {
                     layoutHandlers.Add(handler);
                 }
             }
             else
             {
                 gameObject.name = CachedName + "(NOT_FOUND_HANDLERS)";
                 CustomDebug.LogWarning("no handlers found in GUILayoutCell references, gameObject name = " + CachedName, this);
             }
         }
         else
         {
             gameObject.name = CachedName + "(NOT_FOUND_HANDLERS)";
             CustomDebug.LogWarning("no handlers found in GUILayoutCell references, gameObject name = " + CachedName, this);
         }
     }
 }
    /// <summary>
    /// Preloads as many instances to the pool so that there are at least as many as
    /// specified in <see cref="PoolableObject.preloadCount"/>.
    /// </summary>
    /// <param name="prefab">The prefab.</param>
    /// <remarks>
    /// Use ObjectPoolController.isDuringPreload to check if an object is preloaded in the <c>Awake()</c> function.
    /// If the pool already contains at least <see cref="PoolableObject.preloadCount"/> objects, the function does nothing.
    /// </remarks>
    /// <seealso cref="PoolableObject.preloadCount"/>
    static public void Preload(GameObject prefab)   // adds as many instances to the prefab pool as specified in the PoolableObject
    {
        PoolableObject poolObj = prefab.GetComponent <PoolableObject>();

        if (poolObj == null)
        {
            CustomDebug.LogWarning("Can not preload because prefab '" + prefab.name + "' is not poolable");
            return;
        }

        var pool = _GetPool(poolObj);   // _preloadDone is set by _GetPool

        int delta = poolObj.preloadCount - pool.GetObjectCount();

        if (delta <= 0)
        {
            return;
        }

        isDuringPreload = true;

        try
        {
            for (int i = 0; i < delta; i++)
            {
                pool.PreloadInstance();
            }
        }
        finally
        {
            isDuringPreload = false;
        }

        //Debug.Log( "preloaded: " + prefab.name + " " + poolObj.preloadCount + " times" );
    }
Beispiel #4
0
    public override void Parse(IPEndPoint client, byte[] data)
    {
        MemoryStream memoryStream = new MemoryStream(data);

        try{
            object obj = formatter.Deserialize(memoryStream);

            if (obj is ServerData)
            {
                ServerData parsedData = (ServerData)obj;
                CustomDebug.Log("Object received : " + parsedData.GetType(), VerboseLevel.ALL);
                parsedData.ValidateAndExecute(clientInformations, client);
            }
            else
            {
                throw new BadDataException("Not a valid Data " + obj.GetType());
            }
        } catch (BadDataException e) {
            CustomDebug.LogWarning("Bad Message ! " + e.Message, VerboseLevel.INFORMATIONS);
        } catch (Exception e) {
            throw e;
        }

        memoryStream.Close();
    }
Beispiel #5
0
 public void SendData(ClientData message)
 {
     try{
         base.SendData(serverEndPoint, message);
     } catch (ObjectDisposedException) {
         CustomDebug.LogWarning("Object disposed, Close Client", VerboseLevel.IMPORTANT);
         Close();
     }
 }
Beispiel #6
0
 public new void SendData(IPEndPoint client, Data message)
 {
     try{
         base.SendData(client, message);
     } catch (ObjectDisposedException) {
         CustomDebug.LogWarning("Object disposed, Client removed", VerboseLevel.IMPORTANT);
         RemoveClient(client);
     }
 }
Beispiel #7
0
        static public T GetSingleton(bool autoCreate)
        {
            if (!instanceT)   // Unity operator to check if object was destroyed,
            {
                T component = null;

                #if UNITY_EDITOR
                if ((Application.isPlaying) && (!UnityEditor.EditorApplication.isPaused))
                {
                    var components = GameObject.FindObjectsOfType <T>();

                    foreach (var c in components)
                    {
                        var singletonCpt = (ISingletonMonoBehaviour)(c);
                        if (singletonCpt.IsSingletonObject)
                        {
                            component = c;
                            CustomDebug.LogError("Must call base.Awake() singleton : " + typeT.Name);
                            break;
                        }
                    }
                }
                #endif

                if (!component)
                {
                    if (autoCreate
                        #if UNITY_EDITOR
                        && Application.isPlaying &&
                        !UnityEditor.EditorApplication.isPaused
                        #endif
                        && !destroySingletonCalled
                        )
                    {
                        GameObject go = new GameObject(typeT.Name, new Type[] { typeT });
                        go.transform.parent = AutocreateRoot;

                        CustomDebug.LogWarning("Create singleton : " + typeT.Name);

                        component = go.GetComponent <T>();
                        if (component == null)
                        {
                            CustomDebug.LogError("Auto created object does not have component " + typeT.Name);
                            component = null;
                        }
                    }
                    else
                    {
                        component = null;
                    }
                }

                instanceT = component;
            }

            return(instanceT);
        }
Beispiel #8
0
    public void RemoveClient(IPEndPoint client)
    {
        ClientToken token;

        if (clients.TryRemove(client, out token))
        {
            removedClients.Add(token.id);
            CustomDebug.LogWarning("Remove Client " + client.Address.ToString() + ":" + client.Port.ToString(), VerboseLevel.IMPORTANT);
        }
    }
    // redundant code with RegisteredComponentEx !!

    protected virtual void Awake()
    {
        if (!isRegistered)
        {
            RegisteredComponentController._Register(this);
            isRegistered   = true;
            isUnregistered = false;
        }
        else
        {
            CustomDebug.LogWarning("RegisteredComponent: Awake() / OnDestroy() not correctly called. Object: " + name);
        }
    }
 public void SendCallback(IAsyncResult asyncResult)
 {
     try{
         if (socket.EndSend(asyncResult) == 0)
         {
             CustomDebug.LogWarning("Send empty message", VerboseLevel.IMPORTANT);
         }
     }
     catch (Exception e)
     {
         Close();
         Debug.LogException(e);
     }
 }
Beispiel #11
0
 void InitHandlerObjects()
 {
     foreach (var obj in layoutHandlerObjects)
     {
         ILayoutCellHandler handler = obj.GetComponent(typeof(ILayoutCellHandler)) as ILayoutCellHandler;
         if (handler != null)
         {
             layoutHandlers.Add(handler);
         }
         else
         {
             gameObject.name = "NOT_FOUND_HANDLERS";
             CustomDebug.LogWarning("no handlers found in GUILayoutCell references, gameObject name = " + name);
         }
     }
 }
Beispiel #12
0
 static internal void InternalAwake(T instance)
 {
     globalInstanceCount++;
     if (globalInstanceCount > 1)
     {
         #if UNITY_EDITOR
         if ((Application.isPlaying) && (!UnityEditor.EditorApplication.isPaused))
         #endif
         {
             // can happen if an exception occurred that prevented correct instance counting
             CustomDebug.LogWarning("More than one awake of SingletonMonoBehaviour " + typeof(T).Name);
         }
     }
     else
     {
         instanceT = (T)instance;
     }
 }
    protected virtual void OnDestroy()
    {
        if (isRegistered && !isUnregistered)
        {
            RegisteredComponentController._Unregister(this);
            isRegistered   = false;
            isUnregistered = true;
        }
        else
        {
            bool alreadyUnregisteredProperly = !isRegistered && isUnregistered;

            if (!alreadyUnregisteredProperly)   // for poolable objects OnDestroy() can get called multiple times
            {
                CustomDebug.LogWarning("RegisteredComponent: Awake() / OnDestroy() not correctly called. Object: " + name + " isRegistered:" + isRegistered + " isUnregistered:" + isUnregistered);
            }
        }
    }
Beispiel #14
0
        public XElement ParseValueForSave(object node)
        {
            if ((node is string) || (node == null))
            {
                return(new XElement(TYPE_STRING, node as string));
            }
            else if (node is int || node is long)
            {
                return(new XElement(TYPE_INTEGER, ((int)node).ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));
            }
            else if (node is PBXPlistDict)
            {
                return(ParseDictForSave((PBXPlistDict)node));
            }
            else if (node is ArrayList)
            {
                return(ParseArrayForSave(node));
            }
            else if (node is byte[])
            {
                return(new XElement(TYPE_DATA, Convert.ToBase64String((Byte[])node)));
            }
            else if (node is float || node is double)
            {
                return(new XElement(TYPE_REAL, ((double)node).ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));
            }
            else if (node is DateTime)
            {
                DateTime time       = (DateTime)node;
                string   stringTime = XmlConvert.ToString(time, XmlDateTimeSerializationMode.Utc);

                return(new XElement(TYPE_DATE, stringTime));
            }
            else if (node is bool)
            {
                return(new XElement(node.ToString().ToLower()));
            }
            else
            {
                CustomDebug.LogWarning("PBXPlistDict: Format unsupported, Parser update needed");
            }

            return(null);
        }
    static public void DeleteArrayElement <T>(ref T[] array, int index)
    {
        if (index >= array.Length || index < 0)
        {
            CustomDebug.LogWarning("invalid index in DeleteArrayElement: " + index);
            return;
        }
        var newArray = new T[array.Length - 1];
        int i;

        for (i = 0; i < index; i++)
        {
            newArray[i] = array[i];
        }
        for (i = index + 1; i < array.Length; i++)
        {
            newArray[i - 1] = array[i];
        }
        array = newArray;
    }
Beispiel #16
0
        private object ParseValueForLoad(XElement val)
        {
            switch (val.Name.ToString())
            {
            case TYPE_STRING:
                return(val.Value);

            case TYPE_INTEGER:
                return(int.Parse(val.Value));

            case TYPE_REAL:
                return(float.Parse(val.Value));

            case TYPE_TRUE:
                return(true);

            case TYPE_FALSE:
                return(false);

            case TYPE_DICT:
                PBXPlistDict plist = new PBXPlistDict();
                ParseDictForLoad(plist, val.Elements());
                return(plist);

            case TYPE_ARRAY:
                return(ParseArrayForLoad(val.Elements()));

            case TYPE_NULL:
                return(null);

            case TYPE_DATE:
                return(XmlConvert.ToDateTime(val.Value, XmlDateTimeSerializationMode.Utc));

            case TYPE_DATA:
                return(Convert.FromBase64String(val.Value));

            default:
                CustomDebug.LogWarning("PBXPlistDict: Format unsupported, Parser update needed");
                return(null);
            }
        }
Beispiel #17
0
 static internal void InternalDestroy()
 {
     if (globalInstanceCount > 0)
     {
         globalInstanceCount--;
         if (globalInstanceCount == 0)
         {
             destroySingletonCalled = true;
             instanceT = null;
         }
     }
     else
     {
         #if UNITY_EDITOR
         if ((Application.isPlaying) && (!UnityEditor.EditorApplication.isPaused))
         #endif
         {
             // can happen if an exception occurred that prevented correct instance counting
             CustomDebug.LogWarning("More than one destroy of SingletonMonoBehaviour " + typeof(T).Name);
         }
     }
 }
    /// <summary>
    /// Destroys the specified game object, respectively sets the object inactive and adds it to the pool.
    /// </summary>
    /// <param name="obj">The game object.</param>
    /// <remarks>
    /// Can be used on none-poolable objects as well. It is good practice to use <c>ObjectPoolController.Destroy</c>
    /// whenever you may possibly make your prefab poolable in the future. <para/>
    /// Must also be used on none-poolable objects with poolable child objects so the poolable child objects are correctly
    /// moved to the pool.
    /// </remarks>
    /// <seealso cref="Instantiate(GameObject)"/>
    static public void Destroy(GameObject obj)   // destroys poolable and none-poolable objects. Destroys poolable children correctly
    {
        PoolableObject poolObj = obj.GetComponent <PoolableObject>();

        if (poolObj == null)
        {
            _DetachChildrenAndDestroy(obj.transform); // child objects may be poolable
            GameObject.Destroy(obj);                  // prefab not pooled, destroy normally
            return;
        }
        if (poolObj._myPool != null)
        {
            poolObj._myPool._SetAvailable(poolObj, true);
        }
        else
        {
            if (!poolObj._createdWithPoolController)
            {
                CustomDebug.LogWarning("Poolable object " + obj.name + " not created with ObjectPoolController");
            }
            GameObject.Destroy(obj);   // prefab not pooled, destroy normally
        }
    }
Beispiel #19
0
 void InitReference(bool force)
 {
     if (force || ((tk2dSprite == null) && (tk2dLabel == null) && (quad == null) && (drawableMesh == null)))
     {
         tk2dSprite   = Target.GetComponent <tk2dBaseSprite>();
         tk2dLabel    = Target.GetComponent <tk2dTextMesh>();
         quad         = Target.GetComponent <ColorQuad>();
         drawableMesh = Target.GetComponent <DrawableMesh>();
         objectColor  = Target.GetComponent <ITweenColor>();
         if ((tk2dSprite == null) &&
             (tk2dLabel == null) &&
             (quad == null) &&
             (drawableMesh == null) &&
             (objectColor == null))
         {
             meshRenderer = Target.GetComponent <MeshRenderer>();
             if (meshRenderer != null && (meshRenderer.sharedMaterial == null || !meshRenderer.sharedMaterial.HasProperty("_Color")))
             {
                 CustomDebug.LogWarning("Wrong material!");
                 meshRenderer = null;
             }
         }
     }
 }
Beispiel #20
0
 public override void Close()
 {
     base.Close();
     CustomDebug.LogWarning("Connexion Closed", VerboseLevel.IMPORTANT);
 }
 public virtual void BadReceive()
 {
     CustomDebug.LogWarning("Bad reception", VerboseLevel.INFORMATIONS);
     socket.BeginReceive(new AsyncCallback(ReceiveCallback), null);
 }