/// <summary> /// Constructor. /// </summary> /// <param name="field">The conditional int field to construct.</param> public ConditionIntField(ConditionIntField field) { name = field.name; value = field.value; objectType = field.objectType; objectID = field.objectID; objectName = field.objectName; heroGUID = field.heroGUID; propertyID = field.propertyID; targetHeroObject = field.targetHeroObject; fieldType = field.fieldType; fieldID = field.fieldID; fieldValue = field.fieldValue; heroObject = field.heroObject; }
/// <summary> /// Add hero object to hero kit object. /// </summary> /// <param name="targetObject">The hero kit object.</param> /// <param name="saveData">The save data for the hero kit object.</param> private static void AddHeroObject(HeroKitObject targetObject, HeroSaveData saveData) { // alert: if there are two objects with same name, wrong data could be loaded HeroObject[] heroObjects = Resources.LoadAll <HeroObject>(""); HeroObject heroObject = null; for (int i = 0; i < heroObjects.Length; i++) { if (heroObjects[i].name == saveData.heroName) { heroObject = heroObjects[i]; } } if (targetObject.heroObject != heroObject) { targetObject.ChangeHeroObject(heroObject); } }
/// <summary> /// Spawn a hero kit object or prefab from a pool. /// </summary> /// <param name="poolName">The name of the pool.</param> /// <param name="position">The position in the scene to spawn the object.</param> /// <param name="rotation">The rotation of the object.</param> /// <param name="useHKO">Are you spawning a hero kit object?</param> /// <param name="heroObject">The type of hero kit object to spawn.</param> /// <returns>The hero kit object (if you are spawning a hero kit object). Otherwise, this is always null.</returns> public static HeroKitObject SpawnFromPool(string poolName, Vector3 position, Quaternion rotation, bool useHKO = false, HeroObject heroObject = null) { // increase pool size if it's too small bool growPool = false; HeroKitObject newHKO = null; List <GameObject> poolObjects = GetPool(poolName); if (poolObjects != null) { for (int i = 0; i < poolObjects.Count; i++) { if (!poolObjects[i].activeInHierarchy) { if (useHKO) { newHKO = poolObjects[i].GetComponent <HeroKitObject>(); newHKO.heroObject = heroObject; if (heroObject != null) { poolObjects[i].name = heroObject.name; } } poolObjects[i].transform.position = position; poolObjects[i].transform.rotation = rotation; poolObjects[i].SetActive(true); // if this was the last active item in the list, grow the pool if (i == poolObjects.Count - 1) { growPool = true; } break; } } // double the size of the pool if (growPool) { int itemsToAdd = poolObjects.Count; for (int i = 0; i < itemsToAdd; i++) { GameObject gameObject = UnityEngine.Object.Instantiate(poolObjects[itemsToAdd - 1], poolObjects[itemsToAdd - 1].transform.parent); gameObject.SetActive(false); poolObjects.Add(gameObject); if (useHKO) { HeroKitObject heroKitObject = gameObject.GetComponent <HeroKitObject>(); if (heroKitObject != null) { heroKitObject.heroGUID = HeroKitCommonRuntime.GetHeroGUID(); } } } } } return(newHKO); }
/// <summary> /// Spawn a hero kit object. /// </summary> /// <param name="usePool">Spawn the hero kit object from a pool?</param> /// <param name="poolName">The pool name.</param> /// <param name="position">The position in the scene to spawn the hero kit object.</param> /// <param name="rotation">The rotation of the hero kit object.</param> /// <param name="heroObject">The type of hero kit object to spawn.</param> /// <param name="showLog">Enable debugging for the hero kit object?</param> /// <param name="dontSave">Don't allow hero kit object to be saved?</param> /// <returns>The hero kit object.</returns> public static HeroKitObject SpawnHeroKitObject(bool usePool, string poolName, Vector3 position, Quaternion rotation, HeroObject heroObject, bool showLog, bool dontSave) { HeroKitObject newHKO; // spawn directly in scene if (usePool) { newHKO = SpawnFromPool(poolName, position, rotation, true, heroObject); } else { GameObject template = Resources.Load <GameObject>("Hero Templates/Components/HeroKit Default Object"); GameObject gameObject = UnityEngine.Object.Instantiate(template, position, rotation); gameObject.name = heroObject.name; newHKO = gameObject.GetComponent <HeroKitObject>(); newHKO.heroGUID = HeroKitCommonRuntime.GetHeroGUID(); } newHKO.ChangeHeroObject(heroObject); // debug object? newHKO.debugHeroObject = showLog; // ignore object during save? newHKO.doNotSave = dontSave; return(newHKO); }