//removes a specified decal public void RemoveDecal(DecalInfo givenInfo, TurnBehaviour turnBehav) { List <Character> tmpList = new List <Character>(); for (int i = decalInfo.Count - 1; i >= 0; i--) { if (decalInfo[i].targets == givenInfo.targets) { for (int k = 0; k < decalInfo[i].projectors.Count; k++) { Destroy(decalInfo[i].projectors[k]); } decalInfo[i].projectors.Clear(); Destroy(decalInfo[i].arrow); if (decalInfo[i].player != givenInfo.player) { tmpList.Add(decalInfo[i].player); } decalInfo.Remove(decalInfo[i]); } } int count = decalInfo.Count; //respawns all other decals that should be on this target to fill in any gaps removing the other one left for (int i = 0; i < tmpList.Count; i++) { RedoDecal(i, tmpList[i], tmpList[i].target.GetComponent <Character>(), turnBehav, tmpList.Count); } }
//using th eother one for redoing the decals didn't work and editing it was too difficult so here this is, a slightly modded version of the instantiate code that uses a passed in number to grab the ring decal element public void RedoDecal(int i, Character character, Character target, TurnBehaviour turnBehaviour, int iter) { if (target != null) { DecalInfo tmpInfo = new DecalInfo(); tmpInfo.player = character; tmpInfo.targets = target; //disc spawning if (iter > 0) { GameObject tmpObj = Instantiate(projector[i]); tmpObj.transform.position = new Vector3(character.target.transform.position.x, tmpObj.transform.position.y, character.target.transform.position.z); //setting colour to character specific colour Material tmpMat = new Material(tmpObj.GetComponent <Projector>().material); tmpMat.SetColor("_Color", character.uiColour); tmpObj.GetComponent <Projector>().material = tmpMat; //tmpObj.GetComponent<Projector>().material.SetColor("_Color", character.uiColour); List <GameObject> tmpList = new List <GameObject>(); tmpList.Add(tmpObj); tmpInfo.projectors = tmpList; //wont spawn an arrow if it's a self/team targeting move, as the arrows look super janked if they do if (character.target.tag != "Player") { //arrow instantiating, spawns an arrow then rotates it towards the enemy from the character GameObject tmpArrow = Instantiate(arrowProjectors); Vector3 midPoint = (character.transform.position + (character.target.transform.position - character.transform.position) / 2); tmpArrow.transform.position = new Vector3(midPoint.x, tmpObj.transform.position.y, midPoint.z); //scales the arrow so it fits between the characters float distance = Vector3.Distance(character.transform.position, character.target.transform.position); tmpArrow.GetComponent <Projector>().orthographicSize = distance / 2; tmpArrow.GetComponent <Projector>().aspectRatio = 1 / Mathf.Pow(tmpArrow.GetComponent <Projector>().orthographicSize, 2); tmpArrow.transform.LookAt(character.target.transform); tmpArrow.transform.eulerAngles = new Vector3(90, tmpArrow.transform.eulerAngles.y, tmpArrow.transform.eulerAngles.z); //setting colour to character specific colour Material tmpMatArr = new Material(tmpArrow.GetComponent <Projector>().material); tmpMatArr.SetColor("_Color", character.uiColour); tmpArrow.GetComponent <Projector>().material = tmpMatArr; //tmpArrow.GetComponent<Projector>().material.SetColor("_Color", character.uiColour); tmpInfo.arrow = tmpArrow; } //storing the decal info into a list decalInfo.Add(tmpInfo); } } }
public static void ApplyDecalRegistry(List <KeyValuePair <string, DecalInfo> > elements) { // Sort by priority in this order: folders -> matching paths -> single decal elements.Sort((a, b) => { int scoreA = a.Key[a.Key.Length - 1] switch { '/' => 2, '*' => 1, _ => 0, }; int scoreB = b.Key[b.Key.Length - 1] switch { '/' => 2, '*' => 1, _ => 0, }; // If both end with '*', then we can still be more precise and sort for the best match return((scoreA == scoreB && scoreA == 1) ? a.Key.Length - b.Key.Length : scoreB - scoreA); }); foreach (KeyValuePair <string, DecalInfo> pair in elements) { string decalPath = pair.Key; DecalInfo info = pair.Value; if (decalPath.EndsWith("*") || decalPath.EndsWith("/")) { // Removing the '/' made the path wrong decalPath = decalPath.TrimEnd('*'); int pathLength = decalPath.Length; foreach (string subDecalPath in GFX.Game.GetTextures().Keys .GroupBy( s => s.StartsWith("decals/") ? s.Substring(7).TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') : null, (s, matches) => s ) .Where(str => str != null && str.StartsWith(decalPath) && str.Length > pathLength) ) { // Decals in subfolders are considered as unmatched if (!subDecalPath.Remove(0, pathLength).Contains("/")) { RegisterDecal(subDecalPath, info); } } } else { // Single decal registered RegisterDecal(decalPath, info); } } }
public static void RegisterDecal(string decalPath, DecalInfo info) { if (RegisteredDecals.ContainsKey(decalPath)) { Logger.Log("Decal Registry", $"Replaced decal {decalPath}"); RegisteredDecals[decalPath] = info; } else { Logger.Log("Decal Registry", $"Registered decal {decalPath}"); RegisteredDecals.Add(decalPath, info); } }
public void SpawnDecal(RaycastHit hit) { DecalInfo decalInfo = GetDecalInfo(hit.collider.tag); Vector3 pos = hit.point; Quaternion rot = Quaternion.LookRotation(hit.normal); if (decalInfo != null) { float scale = Random.Range(decalInfo.m_minScale, decalInfo.m_maxScale); GameObject decalObject = GameObject.Instantiate(decalInfo.m_decal, pos, rot); decalObject.transform.localScale = new Vector3(scale, scale, scale); decalObject.transform.SetParent(hit.collider.transform); } }
/// <summary> /// Reads a DecalRegistry.xml file's contents /// </summary> public static void ReadDecalRegistryXml(string fileContents) { // XmlElement file = Calc.LoadXML(path)["decals"]; XmlDocument doc = new XmlDocument(); doc.LoadXml(fileContents); XmlElement file = doc["decals"]; foreach (XmlNode node in file) { if (node is XmlElement decal) { string decalPath = decal.Attr("path", null).ToLower(); if (decalPath == null) { Logger.Log(LogLevel.Warn, "Decal Registry", "Decal didn't have a path attribute!"); continue; } DecalInfo info = new DecalInfo(); info.CustomProperties = new Dictionary <string, XmlAttributeCollection>(); // Read all the properties foreach (XmlNode node2 in decal.ChildNodes) { if (node2 is XmlElement property) { if (property.Attributes == null) { property.SetAttribute("a", "only here to prevent crashes"); } info.CustomProperties.Add(property.Name, property.Attributes); } } if (RegisteredDecals.ContainsKey(decalPath)) { Logger.Log("Decal Registry", $"Replaced decal {decalPath}"); RegisteredDecals[decalPath] = info; } else { Logger.Log("Decal Registry", $"Registered decal {decalPath}"); RegisteredDecals.Add(decalPath, info); } } } }
private void PoolFilling() { DecalInfo decal = null; for (int i = 0; i < GMController.instance.decalDepot.depot.Length; i++) { if (GMController.instance.decalDepot.depot[i].bulletType == type) { decal = GMController.instance.decalDepot.depot[i]; break; } } decalList = new DecalInfo[poolSize]; for (int i = 0; i < decalList.Length; i++) { GameObject bullet = Instantiate(decal.decal); decalList[i] = new DecalInfo(type, bullet); } poolReady = true; }
/// <summary> /// Reads a DecalRegistry.xml file's contents /// </summary> public static List <KeyValuePair <string, DecalInfo> > ReadDecalRegistryXml(string fileContents) { // XmlElement file = Calc.LoadXML(path)["decals"]; XmlDocument doc = new XmlDocument(); doc.LoadXml(fileContents); XmlElement file = doc["decals"]; List <KeyValuePair <string, DecalInfo> > elements = new(); foreach (XmlNode node in file) { if (node is XmlElement decal) { string decalPath = decal.Attr("path", null).ToLower(); if (decalPath == null) { Logger.Log(LogLevel.Warn, "Decal Registry", "Decal didn't have a path attribute!"); continue; } DecalInfo info = new DecalInfo(); info.CustomProperties = new List <KeyValuePair <string, XmlAttributeCollection> >(); // Read all the properties foreach (XmlNode node2 in decal.ChildNodes) { if (node2 is XmlElement property) { if (property.Attributes == null) { property.SetAttribute("a", "only here to prevent crashes"); } info.CustomProperties.Add(new KeyValuePair <string, XmlAttributeCollection>(property.Name, property.Attributes)); } } elements.Add(new KeyValuePair <string, DecalInfo>(decalPath, info)); } } return(elements); }
void AddHurtDecal(int posIdx, float rot) { DecalInfo newDecal = new DecalInfo(); float size = m_MaxSize[0]; newDecal.m_Pos = GetHeavySplatterPos(posIdx); newDecal.m_Size[0] = size; newDecal.m_Size[1] = size; newDecal.m_UVMin[0] = 0; newDecal.m_UVMin[1] = 0; newDecal.m_UVMax[0] = newDecal.m_UVMax[1] = 1 - 1.0f / m_NumBloodDropTexTiles; newDecal.m_Rot = rot; newDecal.m_SpawnTime = Time.time; newDecal.m_Duration = 99999; newDecal.m_IsDrop = false; newDecal.m_Id = posIdx; m_Decals.Add(newDecal); }