private void SetSprite() { string spritePath = DirectionStart + (DirectionEnd != 0 ? "_" + DirectionEnd : ""); Sprite[] Color = SpriteManager.WireSprites[this.Color.ToString()]; SpriteRenderer SR = gameObject.GetComponentInChildren <SpriteRenderer>(); //the red sprite is spliced differently than the rest for some reason :^( int spriteIndex = WireDirections.GetSpriteIndex(spritePath); if (this.Color == WiringColor.red) { spriteIndex *= 2; if (TRay) { spriteIndex++; } } else if (TRay) { spriteIndex += 36; } SR.sprite = Color[spriteIndex]; if (SR.sprite == null) { this.Color = WiringColor.red; SetDirection(1); } }
public void damEditor(int DirectionStart, int DirectionEnd, WiringColor ct) { CableType = ct; //This ensures that End is just null when they are the same if (DirectionStart == DirectionEnd || DirectionEnd == 0) { SetDirection(DirectionStart); return; } //This ensures that the DirectionStart is always the lower one after constructing it. //It solves some complexity issues with the sprite's path //Casting here is to solve nullable somehow not noticing my nullcheck earlier this.DirectionStart = Math.Min(DirectionStart, DirectionEnd); this.DirectionEnd = Math.Max(DirectionStart, DirectionEnd); //Logger.Log(DirectionStart.ToString() + " <DirectionStart and DirectionEnd> " + DirectionEnd.ToString(), Category.Electrical); SetSprite(); }
public void SetDirection(Connection REWireEndA, Connection REWireEndB, WiringColor RECableType = WiringColor.unknown) { if (REWireEndA == REWireEndB) { Logger.LogWarningFormat("Wire connection both starts ({0}) and ends ({1}) in the same place!", Category.Electrical, REWireEndA, REWireEndB); return; } if (RECableType != WiringColor.unknown) { CableType = RECableType; } WireEndA = REWireEndA; WireEndB = REWireEndB; SetSprite(); if (isServer) { CheckOverlap = true; ElectricalManager.Instance.electricalSync.CableUpdates.Add(this); } }
public void SetDirection(Connection REWireEndA, Connection REWireEndB, WiringColor RECableType = WiringColor.unknown) { if (REWireEndA == REWireEndB) { Logger.LogWarningFormat("Wire connection both starts ({0}) and ends ({1}) in the same place!", Category.Electrical, REWireEndA, REWireEndB); return; } if (!(RECableType == WiringColor.unknown)) { CableType = RECableType; } WireEndA = REWireEndA; WireEndB = REWireEndB; //Logger.Log(WireEndB.ToString() + " <WireEndB and WireEndA> " + WireEndA.ToString(), Category.Electrical); SetSprite(); if (isServer) { FindOverlapsAndCombine(); } }
// Use this for initialization private void Start() { IsCable = false; var ListOfICable = this.GetComponents <ICable>(); foreach (ICable Cable in ListOfICable) { if (Cable.IsCable) { //Logger.Log ("Found it", Category.Electrical); RelatedCable = Cable; } } if (!(RelatedCable == null)) { Color = RelatedCable.CableType; DirectionEnd = RelatedCable.DirectionEnd; DirectionStart = RelatedCable.DirectionStart; //FIXME this breaks wires that were placed via unity editor: // need to address when we allow users to add wires at runtime SetDirection(DirectionStart, DirectionEnd); } }
public static ElectricalCableMessage Send(GameObject cable, Connection WireEndA, Connection WireEndB, WiringColor CableType = WiringColor.unknown) { ElectricalCableMessage msg = new ElectricalCableMessage { REWireEndA = WireEndA, REWireEndB = WireEndB, RECableType = CableType, Cable = cable.NetId() }; msg.SendToAll(); return(msg); }