//############################################################################################## // Get the needed components, and set up the timer. Then, populate the materials from either // ourselves or a RotatableComponent. Then, if needed, roll a random start index. // Finally, cache the length, set the first-indexed material, and clear the 'finished' flag //############################################################################################## void Start() { meshRenderer = GetComponent <MeshRenderer>(); rotatable = GetComponent <RotatableComponent>(); frameTime = 1.0f / frameRate; frameTimer = new Timer(frameTime); frameTimer.Start(); if (ShouldUseRotatable()) { usingMaterials = rotatable.GetAnimation(); } else { usingMaterials = materials; } if (randomStartIndex) { frameIndex = Random.Range(0, usingMaterials.Length); } else { frameIndex = 0; } previousMaterialCount = usingMaterials.Length; meshRenderer.material = usingMaterials[frameIndex]; finished = false; }
private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerbsEvent <Verb> args) { if (!args.CanAccess || !args.CanInteract || Transform(uid).NoLocalRotation) // Good ol prototype inheritance, eh? { return; } // Check if the object is anchored, and whether we are still allowed to rotate it. if (!component.RotateWhileAnchored && EntityManager.TryGetComponent(component.Owner, out IPhysBody? physics) && physics.BodyType == BodyType.Static) { return; } Verb resetRotation = new () { Act = () => EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation = Angle.Zero, Category = VerbCategory.Rotate, IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png", Text = "Reset", Priority = -2, // show CCW, then CW, then reset CloseMenu = false, }; args.Verbs.Add(resetRotation); // rotate clockwise Verb rotateCW = new() { Act = () => EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation -= component.Increment, Category = VerbCategory.Rotate, IconTexture = "/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png", Priority = -1, CloseMenu = false, // allow for easy double rotations. }; args.Verbs.Add(rotateCW); // rotate counter-clockwise Verb rotateCCW = new() { Act = () => EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation += component.Increment, Category = VerbCategory.Rotate, IconTexture = "/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png", Priority = 0, CloseMenu = false, // allow for easy double rotations. }; args.Verbs.Add(rotateCCW); }
//############################################################################################## // Get the relevant component, and register for damageable delegates //############################################################################################## protected virtual void Start() { character = GetComponent <CharacterController>(); damage = GetComponent <DamageableComponent>(); rotation = GetComponent <RotatableComponent>(); materialAnimation = GetComponent <MaterialAnimationComponent>(); if (damage != null) { damage.RegisterOnDamagedDelegate(Damaged); damage.RegisterOnKilledDelegate(Killed); } }
private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetOtherVerbsEvent args) { if (!args.CanAccess || !args.CanInteract) { return; } // Check if the object is anchored, and whether we are still allowed to rotate it. if (!component.RotateWhileAnchored && EntityManager.TryGetComponent(component.Owner, out IPhysBody? physics) && physics.BodyType == BodyType.Static) { return; } Verb resetRotation = new(); resetRotation.Act = () => EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation = Angle.Zero; resetRotation.Category = VerbCategory.Rotate; resetRotation.IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png"; resetRotation.Text = "Reset"; resetRotation.Priority = -2; // show CCW, then CW, then reset resetRotation.CloseMenu = false; args.Verbs.Add(resetRotation); // rotate clockwise Verb rotateCW = new(); rotateCW.Act = () => EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation += Angle.FromDegrees(-90); rotateCW.Category = VerbCategory.Rotate; rotateCW.IconTexture = "/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png"; rotateCW.Priority = -1; rotateCW.CloseMenu = false; // allow for easy double rotations. args.Verbs.Add(rotateCW); // rotate counter-clockwise Verb rotateCCW = new(); rotateCCW.Act = () => EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation += Angle.FromDegrees(90); rotateCCW.Category = VerbCategory.Rotate; rotateCCW.IconTexture = "/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png"; rotateCCW.Priority = 0; rotateCCW.CloseMenu = false; // allow for easy double rotations. args.Verbs.Add(rotateCCW); }
void Start() { player = GameObject.FindWithTag("Player"); rotatable = GetComponent <RotatableComponent>(); }