Example #1
0
        public void Cmd_RequestUnUseTrigger(RequestUseTriggerMessage data)
        {
            DevdogLogger.LogVerbose("[UNet][Server] Client with netID " + netId + " requested to un-use trigger...", this);

            var trigger = data.triggerIdentity.GetComponent <ITrigger>();

            if (trigger != null)
            {
                var canUnUse = trigger.CanUnUse(player);
                if (canUnUse)
                {
                    trigger.Server_UnUse(player);

                    // NOTE: isHost check to avoid doing the same thing twice, which is a bit heavy and spammy to the console...
                    if (isHost == false)
                    {
                        TargetRpc_UnUseTrigger(connectionToClient, data.triggerIdentity);
                    }

//                    foreach (var character in trigger.rangeHandler.GetCharactersInRange())
//                    {
//                        if (character == player)
//                        {
//                            continue;
//                        }
//
//                        Rpc_TriggerUnUsedByOtherClient(trigger.GetComponent<NetworkIdentity>());
//                    }
                }
            }
        }
Example #2
0
        public static Type[] GetAllTypesThatImplement(Type type, bool creatableTypesOnly)
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            var types      = new List <Type>(assemblies.Length);

            foreach (var assembly in assemblies)
            {
                try
                {
                    types.AddRange(assembly.GetTypes());
                }
                catch (Exception e)
                {
                    try
                    {
                        DevdogLogger.LogError(e.Message + assembly.FullName);
                    }
                    catch (Exception e2)
                    {
                        DevdogLogger.LogError(e2.Message);
                    }
                }
            }

            types = types.Where(o => type.IsAssignableFrom(o)).ToList();
            if (creatableTypesOnly)
            {
                types = types.Where(o => o.IsAbstract == false && o.IsInterface == false).ToList();
            }

            return(types.ToArray());
        }
Example #3
0
        public override GameObject Get(bool createWhenNoneLeft = true)
        {
            GameObject obj = null;

            if (inactiveObjectsPool.Count == 0)
            {
                if (createWhenNoneLeft)
                {
                    DevdogLogger.Log("New object created, considering increasing the pool size if this is logged often");
                    obj = Instantiate();
                }
            }
            else
            {
                obj = inactiveObjectsPool[inactiveObjectsPool.Count - 1];
            }

            Assert.IsNotNull(obj, "Couldn't get poolable object from pool!");
            obj.gameObject.SetActive(true);
            obj.gameObject.transform.localScale    = Vector3.one;
            obj.gameObject.transform.localRotation = Quaternion.identity;

            activeObjectsList.Add(obj);
            inactiveObjectsPool.RemoveAt(inactiveObjectsPool.Count - 1);

            return(obj);
        }
Example #4
0
        private void TargetRpc_UnUseTrigger(NetworkConnection target, NetworkIdentity triggerIdentity)
        {
            DevdogLogger.LogVerbose("[UNet][Client] Server told us (netID: " + netId + ") to un-use trigger with netID: " + triggerIdentity.netId, this);

            var trigger = triggerIdentity.GetComponent <ITrigger>();

            if (trigger != null)
            {
                trigger.Server_UnUse(player);
            }
        }
Example #5
0
        private static AudioSource GetNextAudioSource()
        {
            foreach (var audioSource in _audioSources)
            {
                if (audioSource.isPlaying == false)
                {
                    return(audioSource);
                }
            }

            DevdogLogger.LogWarning("All sources taken, can't play audio clip...");
            return(null);
        }
Example #6
0
        /// <summary>
        /// Plays an audio clip, only use this for the UI, it is not pooled so performance isn't superb.
        /// </summary>
        public static void AudioPlayOneShot(AudioClipInfo clip)
        {
            if (clip == null || clip.audioClip == null)
            {
                return;
            }

            if (instance == null)
            {
                DevdogLogger.LogWarning("AudioManager not found, yet trying to play an audio clip....");
            }

            if (_audioQueue.Any(o => o.audioClip == clip.audioClip) == false)
            {
                _audioQueue.Enqueue(clip);
            }
        }
Example #7
0
        public static void DeserializeTo(ref object obj, Type type, string json, List <UnityEngine.Object> objectReferences)
        {
            lock (_lockObject)
            {
                try
                {
                    fsData data = fsJsonParser.Parse(json);
                    SetObjectReferences(objectReferences);
                    currentRootType = type;
                    _serializer.TryDeserialize(data, type, ref obj).AssertSuccessWithoutWarnings();
                }
                catch (Exception e)
                {
                    DevdogLogger.LogError(e.Message + "\n" + e.StackTrace);
//                    throw;
                }
            }
        }
Example #8
0
        public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            try
            {
                var db = Serializer.Context.Get <List <UnityEngine.Object> >();
                if (data.IsNull == false)
                {
                    int index = (int)data.AsInt64;
                    if (index == -1 || index >= db.Count)
                    {
                        DevdogLogger.LogError("Couldn't deserialize UnityEngine.Object : " + instance + " - not found in database. (index: " + index + ")");
                        return(fsResult.Fail("Index out of range " + index));
                    }

                    if (IsAssetWrapper(storageType))
                    {
                        var def = typeof(Asset <>);
                        var t   = def.MakeGenericType(storageType.GetGenericArguments()[0]);

                        var inst = (IAsset)Activator.CreateInstance(t);
                        inst.objectVal = db[index];
                        instance       = inst;
                    }
                    else if (typeof(UnityEngine.Object).IsAssignableFrom(storageType))
                    {
                        instance = db[index];
                    }
                }
                else
                {
                    instance = null;
                }
            }
            catch (Exception e)
            {
                DevdogLogger.LogError(e.Message + "\n" + e.StackTrace);
                return(fsResult.Fail(e.Message));
            }

            return(fsResult.Success);
        }
Example #9
0
        public void Cmd_RequestUseTrigger(RequestUseTriggerMessage data)
        {
            DevdogLogger.LogVerbose("[UNet][Server] Client with netID " + netId + " requested to use trigger...", this);
            if (data.triggerIdentity == null)
            {
                return;
            }

            var trigger = data.triggerIdentity.GetComponent <ITrigger>();

            if (trigger != null)
            {
                var canUse = trigger.CanUse(player);
                if (canUse)
                {
                    trigger.Server_Use(player);

                    // NOTE: isHost check to avoid doing the same thing twice, which is a bit heavy and spammy to the console...
                    if (isHost == false)
                    {
                        TargetRpc_UseTrigger(connectionToClient, data.triggerIdentity);
                    }

//                    // TODO: Relevancy for players needs to be used here.
//                    // TODO: When this trigger is relevant for a player and it's being used by another player (or NPC), it should notify that player the collection is being used / unused (for visuals).
//                    foreach (var character in trigger.rangeHandler.GetCharactersInRange())
//                    {
//                        if (character == player)
//                        {
//                            continue;
//                        }
//
//                        Rpc_TriggerUsedByOtherClient(trigger.GetComponent<NetworkIdentity>());
//                    }
                }
            }
        }