Beispiel #1
0
 internal WidgetViewReference(Atom <WidgetViewReference> source)
 {
     _type      = WidgetViewReferenceType.Resource;
     _path      = null;
     _reference = null;
     _source    = source;
 }
Beispiel #2
0
        internal AssetReferenceGameObjectTracker(AssetReferenceGameObject _reference, AssetReferenceGameObjectTrackerCallbackDelegate _callback, Transform _parent)
        {
            handle = _reference.InstantiateAsync(_parent);

            loadingTrackers.Add(handle, new Pair(this, _callback));
            handle.Completed += OnCompleted;
        }
        public static AsyncOperationHandle <GameObject> LoadGameObjectAsync(AssetReferenceGameObject pAsset, Action <float> pProgress = null, Action <GameObject> pOnCompleted = null)
        {
            var operation = pAsset.LoadAssetAsync();

            WaitLoadTask(operation, pProgress, pOnCompleted);
            return(operation);
        }
Beispiel #4
0
 private WidgetViewReference(WidgetViewReferenceType type, string path, AssetReferenceGameObject reference)
 {
     _type      = type;
     _path      = path;
     _reference = reference;
     _source    = null;
 }
        public void Dispose()
        {
            if (list != null)
            {
                var temp = list;
                list = null;

                expandCount       = 0;
                aliveCount        = 0;
                currentUsingIndex = 0;
                parent            = null;
                reference         = null;

                foreach (var l in temp)
                {
                    l.Release();
                }

                if (parentCreatedAtRuntime)
                {
                    if (parent != null && parent.gameObject != null)
                    {
                        GameObject.Destroy(parent.gameObject);
                    }
                }
            }
        }
Beispiel #6
0
        public async static Task CreatePool(AssetReferenceGameObject reference, PoolingData poolingData)
        {
            if (ContainsReference(reference))
            {
                return;
            }

            var pool = new Pool();

            pool.assetReference = reference;
            var operationHandle = reference.LoadAssetAsync();

            operationHandle.Completed += (op) => pool.loadedAsset = op.Result;
            int spawnCount = poolingData.GetSpawnCountFor(reference);

#if UNITY_EDITOR
            var parent = new GameObject($"{reference.editorAsset.name} - Pool").transform;
#endif
            for (int i = 0; i < spawnCount; i++)
            {
                var opHandle           = reference.InstantiateAsync(Vector3.zero, Quaternion.identity);
                var instantiatedObject = await opHandle.Task;
#if UNITY_EDITOR
                instantiatedObject.name = $"{reference.editorAsset.name} - {Guid.NewGuid()}";
#endif
                pool.ObjectList.Add(instantiatedObject);
#if UNITY_EDITOR
                instantiatedObject.transform.SetParent(parent);
#endif
                instantiatedObject.SetActive(false);
            }

            pools[reference.RuntimeKey] = pool;
        }
        public static IAddressableObservable <TApi> ToObservable <TApi>(this AssetReferenceGameObject reference)
            where TApi : class
        {
            var observable = ClassPool.Spawn <AddressableObservable <AssetReference, GameObject, TApi> >();

            observable.Initialize(reference);
            return(observable);
        }
Beispiel #8
0
        public AssetReferenceGameObject Build()
        {
            this.AssetGUID = GUIDGenerator.GenerateDeterministicGUID(this.AssetID);
            var assetRef = new AssetReferenceGameObject();

            AccessTools.Field(typeof(AssetReferenceGameObject), "m_debugName").SetValue(assetRef, this.AssetLoadingInfo.FilePath);
            AccessTools.Field(typeof(AssetReferenceGameObject), "m_AssetGUID").SetValue(assetRef, this.AssetGUID);
            return(assetRef);
        }
Beispiel #9
0
        public async static Task <Pool> GetPool(AssetReferenceGameObject reference, PoolingData data = null)
        {
            if (!ContainsReference(reference))
            {
                await CreatePool(reference, data ?? PoolManager.Instance.atBeginningPoolingData);
            }

            return(pools[reference.RuntimeKey]);
        }
Beispiel #10
0
        public static GameObject Instantiate(AssetReferenceGameObject reference, Transform parent = null, bool instantiateInWorldSpace = false)
        {
#if UNITY_OBJECTPOOLING_ADDRESSABLES_MANAGER
            var obj = AddressablesManager.InstantiateSync(reference, parent, instantiateInWorldSpace);
#else
            var handle = reference.InstantiateAsync(parent, instantiateInWorldSpace);
            var obj    = handle.WaitForCompletion();
#endif
            return(obj);
        }
Beispiel #11
0
        private static bool ContainsReference(AssetReferenceGameObject reference)
        {
            foreach (var key in pools.Keys)
            {
                if (key.Equals(reference.RuntimeKey))
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Creates an asset reference to an existing game file.
        /// Primarily useful for reusing base game art.
        /// Cards with custom art should not use this method.
        /// </summary>
        /// <param name="m_debugName">The asset's debug name (usually the path to it)</param>
        /// <param name="m_AssetGUID">The asset's GUID</param>
        public void CreateAndSetCharacterArtPrefabVariantRef(string m_debugName, string m_AssetGUID)
        {
            var assetReferenceGameObject = new AssetReferenceGameObject();

            AccessTools.Field(typeof(AssetReferenceGameObject), "m_debugName")
            .SetValue(assetReferenceGameObject, m_debugName);
            AccessTools.Field(typeof(AssetReferenceGameObject), "m_AssetGUID")
            .SetValue(assetReferenceGameObject, m_AssetGUID);
            this.CharacterPrefabVariantRef = assetReferenceGameObject;

            this.AssetPath = m_AssetGUID;
        }
Beispiel #13
0
    public int GetSpawnCountFor(AssetReferenceGameObject reference)
    {
        int index = 0;

        for (int i = 0; i < toBePooledAtStart.Count; i++)
        {
            if (toBePooledAtStart[i].RuntimeKey.Equals(reference.RuntimeKey))
            {
                index = i;
                break;
            }
        }

        return(counts[index]);
    }
Beispiel #14
0
        public static void ReleaseScreen(string name)
        {
            AssetReferenceGameObject a = null;

            UIScreenReference[] s = instance.uiScreens.screens;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].name == name)
                {
                    a = s[i].asset;
                    break;
                }
            }

            a.ReleaseAsset();
        }
        public static void ChooseRandomResource(BreakableResource __instance, ref AssetReferenceGameObject __result)
        {
            var prefabs = __instance.prefabList;

            if (prefabs.Count != 1)
            {
                return;
            }

            var prefab = prefabs[0];
            var c      = C;

            float[] chances;


            switch (prefab.prefabTechType)
            {
            case TechType.Silver:
                chances = c.Silver;
                break;

            case TechType.Gold:
                chances = c.Gold;
                break;

            case TechType.Copper:
                chances = c.Copper;
                break;

            case TechType.Lead:
                chances = c.Lead;
                break;

            default:
                return;
            }

            if (currIndex >= chances.Length)
            {
                return;
            }

            var roll = random.NextDouble();

            __result = roll > chances[currIndex++] ? __instance.defaultPrefabReference : prefab.prefabReference;
        }
Beispiel #16
0
        public static void ClearPool(AssetReferenceGameObject reference)
        {
            if (!pools.ContainsKey(reference.RuntimeKey))
            {
                return;
            }

            var pool = pools[reference];

            foreach (var pooled in pool.ObjectList)
            {
                if (!Addressables.ReleaseInstance(pooled))
                {
                    GameObject.Destroy(pooled);
                }
            }
        }
Beispiel #17
0
    private void LoadItemAtIndex(SpawnItemList itemList, int index)
    {
        if (m_instanceObject != null)
        {
            //Throwing Data Loss Error - Christian

            /*
             * Destroy(m_instanceObject);
             */
        }

        m_assetLoadedAsset = itemList.GetAssetReferenceAtIndex(index);
        var spawnPosition   = new Vector3();
        var spawnRotation   = Quaternion.identity;
        var parentTransform = this.transform;

        var loadRoutine = m_assetLoadedAsset.LoadAssetAsync();

        loadRoutine.Completed += LoadRoutine_Completed;

        void LoadRoutine_Completed(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle <GameObject> obj)
        {
            m_instanceObject = Instantiate(obj.Result, spawnPosition, spawnRotation, parentTransform);

            //Set name, so object can be stored in correct Output folder
            m_instanceObject.name = obj.Result.name;

            if (StartingEulerAngles == new Vector3(0, 0, 0) && startingPhotoTaken == false)
            {
                //Update Object Name var for screenshoot
                objectNameGet = m_instanceObject.name;

                //First Screenshot goes here and increment counter
                cameraScreenshot.TakeScreenshot();

                //First Photo has been
                startingPhotoTaken = true;
            }
        }
    }
        private AssetReferenceGameObjectPool(AssetReferenceGameObject _reference, string _referenceKey, int _capacity, Transform _parent, Scene _scene, string _rootName)
        {
            if (_rootName != null)
            {
                var root = new GameObject(_rootName);
                SceneManager.MoveGameObjectToScene(root, _scene);
                parent = root.transform;
                parentCreatedAtRuntime = true;
            }
            else
            {
                parent = _parent;
                parentCreatedAtRuntime = false;
            }

            reference         = _reference;
            referenceKey      = _referenceKey;
            aliveCount        = 0;
            currentUsingIndex = 0;
            expandCount       = Mathf.Max(1, _capacity / 2);

            list = new List <AssetReferenceGameObjectTracker>(_capacity);

            if (reference != null)
            {
                for (int i = 0; i < _capacity; ++i)
                {
                    list.Add(reference.InstantiateAsyncAndTrack(OnInstantiateDone, parent));
                }
            }
            else
            {
                for (int i = 0; i < _capacity; ++i)
                {
                    list.Add(referenceKey.InstantiateAsyncAndTrack(OnInstantiateDone, parent));
                }
            }

            OnListExpanded(list.Count);
        }
Beispiel #19
0
        public static void Add(AssetReferenceGameObject assetRef)
        {
            if (assetRef.RuntimeKeyIsValid())
            {
                if (assetRef.Asset == null && !AssetRefs.Contains(assetRef))
                {
                    AssetRefs.Enqueue(assetRef);

                    if (AssetRefs.Count == 1)
                    {
                        LoadNext();
                    }
                }
                else
                {
                    DispatchCompletedAllIfEmpty();
                }
            }
            else
            {
                DispatchCompletedAllIfEmpty();
            }
        }
Beispiel #20
0
        public void RegisterPoolItem(string key, AssetReferenceGameObject objectToPool, int prepoolAmount)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            if (this.keys.Contains(key))
            {
                return;
            }

            if (objectToPool == null)
            {
                return;
            }

            this.keys.Add(key);
            this.pooler.Register(new AddressableGameObjectPooler.PoolItem {
                Key           = key,
                Object        = objectToPool,
                PrepoolAmount = prepoolAmount
            });
        }
Beispiel #21
0
        public static void GetScreen(string name, System.Action <GameObject> onComplete)
        {
            AssetReferenceGameObject a = null;

            UIScreenReference[] s = instance.uiScreens.screens;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].name == name)
                {
                    a = s[i].asset;
                    break;
                }
            }

            a.InstantiateAsync(instance.transform).Completed += (asyncOperationHandle) =>
            {
                GameObject screen = asyncOperationHandle.Result;
                Canvas     canvas = screen.GetComponent <Canvas>();
                canvas.renderMode  = RenderMode.ScreenSpaceCamera;
                canvas.worldCamera = instance.uiCam;

                onComplete?.Invoke(asyncOperationHandle.Result);
            };
        }
Beispiel #22
0
 void LoadAndInstantiate(AssetReferenceGameObject reference)
 {
     reference.LoadAssetAsync <GameObject>().Completed += FinishByInstantiate;
 }
 public ComponentLoadingHandle(AssetReferenceGameObject gameObjectReference)
     : base(gameObjectReference)
 {
 }
Beispiel #24
0
 private void OnObjectSelectCallback(AssetReferenceGameObject goRef)
 {
     chosenInGameObject = goRef;
 }
 public AssetReferenceGameObjectPool(AssetReferenceGameObject _reference, int _capacity, Transform _parent) : this(_reference, null, _capacity, _parent, default, null)
 {
 }
        private static void BreakIntoResources_Patch(BreakableResource __instance)
        {
            __instance.SendMessage("OnBreakResource", null, SendMessageOptions.DontRequireReceiver);
            if (__instance.gameObject.GetComponent <VFXBurstModel>())
            {
                __instance.gameObject.BroadcastMessage("OnKill");
            }
            else
            {
                UnityEngine.Object.Destroy(__instance.gameObject);
            }
            if (__instance.customGoalText != "")
            {
                GoalManager.main.OnCustomGoalEvent(__instance.customGoalText);
            }
            bool flag = false;

            for (int i = 0; i < __instance.numChances; i++)
            {
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-01 - start choose random ress");
                AssetReferenceGameObject assetReferenceGameObject = __instance.ChooseRandomResource();
                if (assetReferenceGameObject != null)
                {
                    QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-02 - Random Resouce is called");
                    if (Player.main.GetVehicle() is Exosuit exosuit)
                    {
                        var installedmodule = exosuit.modules.GetCount(MetalHands_BZ.MetalHandsClawModuleTechType);
                        if (((installedmodule > 0) | (MetalHands_BZ.Config.Config_fastcollect == true)) & exosuit.storageContainer.container.HasRoomFor(1, 1))
                        {
                            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-10 - Start AddToPrawn over randomress");
                            CoroutineHost.StartCoroutine(AddtoPrawn(__instance, exosuit, assetReferenceGameObject));
                        }
                        else
                        {
                            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-11 - Spawn original way randomress");
                            __instance.SpawnResourceFromPrefab(assetReferenceGameObject);
                        }
                    }
                    else
                    {
                        Inventory inventory = Inventory.Get();
                        if (((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands_BZ.MetalHandsMK2TechType) | (MetalHands_BZ.Config.Config_fastcollect == true)) & inventory.HasRoomFor(1, 1))
                        {
                            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-20 - Player has glove - randomress");
                            CoroutineHost.StartCoroutine(AddbrokenRestoPlayerInv(__instance, assetReferenceGameObject));
                        }
                        else
                        {
                            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-04 - Spawn original way - defaultress");
                            __instance.SpawnResourceFromPrefab(assetReferenceGameObject);
                        }
                    }
                    flag = true;
                }
            }
            if (!flag)
            {
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-01 - default resouce is called");
                if (Player.main.GetVehicle() is Exosuit exosuit)
                {
                    var installedmodule = exosuit.modules.GetCount(MetalHands_BZ.MetalHandsClawModuleTechType);
                    if (((installedmodule > 0) | (MetalHands_BZ.Config.Config_fastcollect == true)) && exosuit.storageContainer.container.HasRoomFor(1, 1))
                    {
                        QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-02 - Start AddToPrawn over defaultress");
                        CoroutineHost.StartCoroutine(AddtoPrawn(__instance, exosuit, __instance.defaultPrefabReference));
                    }
                    else
                    {
                        QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "01-11 - Spawn original way randomress");
                        __instance.SpawnResourceFromPrefab(__instance.defaultPrefabReference);
                    }
                }
                else
                {
                    Inventory inventory = Inventory.Get();
                    if (((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands_BZ.MetalHandsMK2TechType) | (MetalHands_BZ.Config.Config_fastcollect == true)) & inventory.HasRoomFor(1, 1))
                    {
                        QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-03 - Player has glove - defaultress");
                        CoroutineHost.StartCoroutine(AddbrokenRestoPlayerInv(__instance, __instance.defaultPrefabReference));
                    }
                    else
                    {
                        QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "03-04 - Spawn original way - defaultress");
                        __instance.SpawnResourceFromPrefab(__instance.defaultPrefabReference);
                    }
                }
            }
            FMODUWE.PlayOneShot(__instance.breakSound, __instance.transform.position, 1f);
            if (__instance.hitFX)
            {
                global::Utils.PlayOneShotPS(__instance.breakFX, __instance.transform.position, Quaternion.Euler(new Vector3(270f, 0f, 0f)), null);
            }
        }
        private static IEnumerator AddbrokenRestoPlayerInv(BreakableResource __instance, AssetReferenceGameObject gameObject)
        {
            CoroutineTask <GameObject> task = AddressablesUtility.InstantiateAsync(gameObject.RuntimeKey as string);

            yield return(task);

            GameObject prefab     = task.GetResult();
            var        pickupable = prefab.GetComponent <Pickupable>();

            pickupable.Initialize();
            CraftData.AddToInventory(pickupable.GetTechType());

            yield break;
        }
        private static IEnumerator AddtoPrawn(BreakableResource __instance, Exosuit exosuit, AssetReferenceGameObject gameObject)
        {
            CoroutineTask <GameObject> task = AddressablesUtility.InstantiateAsync(gameObject.RuntimeKey as string);

            yield return(task);

            GameObject prefab     = task.GetResult();
            var        pickupable = prefab.GetComponent <Pickupable>();

            pickupable.Initialize();
            var item = new InventoryItem(pickupable);

            exosuit.storageContainer.container.UnsafeAdd(item);

            string name = Language.main.GetOrFallback(pickupable.GetTechType().AsString(), pickupable.GetTechType().AsString());

            ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));
            uGUI_IconNotifier.main.Play(pickupable.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);
            pickupable.PlayPickupSound();

            yield break;
        }
 public GameObjectAssetLoader(GameObject root, AssetReferenceGameObject assetReference) : base(assetReference)
 {
     this.root = root;
 }
 public AssetReferenceGameObjectPool(AssetReferenceGameObject _reference, int _capacity, Scene _scene, string _parentName) : this(_reference, null, _capacity, null, _scene, _parentName)
 {
 }