public override void Copy(SpriteRoot s, ControlCopyFlags flags) { base.Copy(s, flags); if (!(s is UIScrollKnob)) { return; } UIScrollKnob b = (UIScrollKnob)s; if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State) { origPos = b.origPos; ctrlPlane = b.ctrlPlane; slider = b.slider; } if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings) { maxScrollPos = b.maxScrollPos; colliderSizeFactor = b.colliderSizeFactor; } }
// Called by the knob when it moves. public void ScrollKnobMoved(UIScrollKnob knob, float val) { m_value = val; float truncVal = truncFloor + m_value * truncRange; UpdateAppearance(truncVal); if (scriptWithMethodToInvoke != null) { scriptWithMethodToInvoke.Invoke(methodToInvoke, 0); } if (changeDelegate != null) { changeDelegate(this); } }
public void ScrollKnobMoved(UIScrollKnob knob, float val) { this.m_value = val; float truncVal = this.truncFloor + this.m_value * this.truncRange; this.UpdateAppearance(truncVal); if (this.scriptWithMethodToInvoke != null) { this.scriptWithMethodToInvoke.Invoke(this.methodToInvoke, 0f); } if (this.callChangeDelegate && this.changeDelegate != null) { this.changeDelegate(this); } this.callChangeDelegate = true; }
public override void Start() { if (m_started) { return; } base.Start(); // Assign our aggregate layers: aggregateLayers = new SpriteRoot[2][]; aggregateLayers[0] = filledLayers; aggregateLayers[1] = emptyLayers; // The knob will handle its own layers // Runtime init stuff: if (Application.isPlaying) { // Calculate our truncation floor and range: truncFloor = stopKnobFromEdge / width; truncRange = 1f - truncFloor * 2f; filledIndices = new int[filledLayers.Length]; emptyIndices = new int[emptyLayers.Length]; // Populate our state indices based on if we // find any valid states/animations in each // sprite layer: for (int i = 0; i < filledLayers.Length; ++i) { if (filledLayers[i] == null) { Debug.LogError("A null layer sprite was encountered on control \"" + name + "\". Please fill in the layer reference, or remove the empty element."); continue; } filledIndices[i] = filledLayers[i].GetStateIndex("filled"); if (filledIndices[i] != -1) { filledLayers[i].SetState(filledIndices[i]); } } for (int i = 0; i < emptyLayers.Length; ++i) { if (emptyLayers[i] == null) { Debug.LogError("A null layer sprite was encountered on control \"" + name + "\". Please fill in the layer reference, or remove the empty element."); continue; } emptyIndices[i] = emptyLayers[i].GetStateIndex("empty"); if (emptyIndices[i] != -1) { emptyLayers[i].SetState(emptyIndices[i]); } } // Create our knob: GameObject go = new GameObject(); go.name = name + " - Knob"; go.transform.parent = transform; go.transform.localPosition = CalcKnobStartPos(); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = gameObject.layer; knob = (UIScrollKnob)go.AddComponent(typeof(UIScrollKnob)); knob.plane = plane; knob.SetOffset(knobOffset); knob.persistent = persistent; knob.bleedCompensation = bleedCompensation; if (!managed) { if (knob.spriteMesh != null) { ((SpriteMesh)knob.spriteMesh).material = GetComponent <Renderer>().sharedMaterial; } } else { if (manager != null) { knob.Managed = managed; manager.AddSprite(knob); knob.SetDrawLayer(drawLayer + 1); // Knob should be drawn in front of the bar // Force it to update its UVs: knob.SetControlState(UIButton.CONTROL_STATE.ACTIVE); // We have to change to active so that when we set to normal, it isn't considered a redundant change and ignored. knob.SetControlState(UIButton.CONTROL_STATE.NORMAL); } else { Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!"); } } if (pixelPerfect) { knob.pixelPerfect = true; } else { knob.SetSize(knobSize.x, knobSize.y); } knob.ignoreClipping = ignoreClipping; knob.color = color; knob.SetColliderSizeFactor(knobColliderSizeFactor); knob.SetSlider(this); knob.SetMaxScroll(width - (stopKnobFromEdge * 2f)); knob.SetInputDelegate(inputDelegate); // Setup knob's transitions: knob.transitions[0] = transitions[2]; knob.transitions[1] = transitions[3]; knob.transitions[2] = transitions[4]; // Tell the knob what it will look like: knob.layers = knobLayers; // Child the knob's layers to the knob: for (int i = 0; i < knobLayers.Length; ++i) { knobLayers[i].transform.parent = knob.transform; } knob.animations[0].SetAnim(states[2], 0); knob.animations[1].SetAnim(states[3], 1); knob.animations[2].SetAnim(states[4], 2); knob.SetupAppearance(); knob.SetCamera(renderCamera); knob.Hide(IsHidden()); knob.autoResize = autoResize; // Create our other sprite for the // empty/background portion: go = new GameObject(); go.name = name + " - Empty Bar"; go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = gameObject.layer; emptySprite = (AutoSprite)go.AddComponent(typeof(AutoSprite)); emptySprite.plane = plane; emptySprite.autoResize = autoResize; emptySprite.pixelPerfect = pixelPerfect; emptySprite.persistent = persistent; emptySprite.ignoreClipping = ignoreClipping; emptySprite.bleedCompensation = bleedCompensation; if (!managed) { emptySprite.GetComponent <Renderer>().sharedMaterial = GetComponent <Renderer>().sharedMaterial; } else { if (manager != null) { emptySprite.Managed = managed; manager.AddSprite(emptySprite); emptySprite.SetDrawLayer(drawLayer); // Knob should be drawn in front of the bar } else { Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!"); } } emptySprite.color = color; emptySprite.SetAnchor(anchor); emptySprite.Setup(width, height, m_spriteMesh.material); if (states[1].spriteFrames.Length != 0) { emptySprite.animations = new UVAnimation[1]; emptySprite.animations[0] = new UVAnimation(); emptySprite.animations[0].SetAnim(states[1], 0); emptySprite.PlayAnim(0, 0); } emptySprite.renderCamera = renderCamera; emptySprite.Hide(IsHidden()); // Add our child objects as children // of our container: if (container != null) { container.AddChild(knob.gameObject); container.AddChild(emptySprite.gameObject); } SetState(0); // Force the value to update: m_value = -1f; Value = defaultValue; } // Since hiding while managed depends on // setting our mesh extents to 0, and the // foregoing code causes us to not be set // to 0, re-hide ourselves: if (managed && m_hidden) { Hide(true); } }
// Called by the knob when it moves. public void ScrollKnobMoved(UIScrollKnob knob, float val) { m_value = val; float truncVal = truncFloor + m_value * truncRange; UpdateAppearance(truncVal); if (scriptWithMethodToInvoke != null) scriptWithMethodToInvoke.Invoke(methodToInvoke, 0); if (changeDelegate != null) changeDelegate(this); }
public override void Start() { if (m_started) return; base.Start(); // Assign our aggregate layers: aggregateLayers = new SpriteRoot[2][]; aggregateLayers[0] = filledLayers; aggregateLayers[1] = emptyLayers; // The knob will handle its own layers // Runtime init stuff: if(Application.isPlaying) { // Calculate our truncation floor and range: truncFloor = stopKnobFromEdge / width; truncRange = 1f - truncFloor * 2f; filledIndices = new int[filledLayers.Length]; emptyIndices = new int[emptyLayers.Length]; // Populate our state indices based on if we // find any valid states/animations in each // sprite layer: for (int i = 0; i < filledLayers.Length; ++i) { if (filledLayers[i] == null) { Debug.LogError("A null layer sprite was encountered on control \"" + name + "\". Please fill in the layer reference, or remove the empty element."); continue; } filledIndices[i] = filledLayers[i].GetStateIndex("filled"); if (filledIndices[i] != -1) filledLayers[i].SetState(filledIndices[i]); } for (int i = 0; i < emptyLayers.Length; ++i) { if (emptyLayers[i] == null) { Debug.LogError("A null layer sprite was encountered on control \"" + name + "\". Please fill in the layer reference, or remove the empty element."); continue; } emptyIndices[i] = emptyLayers[i].GetStateIndex("empty"); if (emptyIndices[i] != -1) emptyLayers[i].SetState(emptyIndices[i]); } // Create our knob: GameObject go = new GameObject(); go.name = name + " - Knob"; go.transform.parent = transform; go.transform.localPosition = CalcKnobStartPos(); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = gameObject.layer; knob = (UIScrollKnob) go.AddComponent(typeof(UIScrollKnob)); knob.plane = plane; knob.SetOffset(knobOffset); knob.persistent = persistent; knob.bleedCompensation = bleedCompensation; if (!managed) { if (knob.spriteMesh != null) ((SpriteMesh)knob.spriteMesh).material = renderer.sharedMaterial; } else { if (manager != null) { knob.Managed = managed; manager.AddSprite(knob); knob.SetDrawLayer(drawLayer + 1); // Knob should be drawn in front of the bar } else Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!"); } knob.autoResize = autoResize; if (pixelPerfect) { knob.pixelPerfect = true; } else knob.SetSize(knobSize.x, knobSize.y); knob.ignoreClipping = ignoreClipping; knob.color = color; knob.SetColliderSizeFactor(knobColliderSizeFactor); knob.SetSlider(this); knob.SetMaxScroll(width - (stopKnobFromEdge * 2f)); knob.SetInputDelegate(inputDelegate); // Setup knob's transitions: knob.transitions[0] = transitions[2]; knob.transitions[1] = transitions[3]; knob.transitions[2] = transitions[4]; // Tell the knob what it will look like: knob.layers = knobLayers; // Child the knob's layers to the knob: for (int i = 0; i < knobLayers.Length; ++i) knobLayers[i].transform.parent = knob.transform; knob.animations[0].SetAnim(states[2], 0); knob.animations[1].SetAnim(states[3], 1); knob.animations[2].SetAnim(states[4], 2); knob.SetupAppearance(); knob.SetCamera(renderCamera); knob.Hide(IsHidden()); // Create our other sprite for the // empty/background portion: go = new GameObject(); go.name = name + " - Empty Bar"; go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = gameObject.layer; emptySprite = (AutoSprite) go.AddComponent(typeof(AutoSprite)); emptySprite.plane = plane; emptySprite.autoResize = autoResize; emptySprite.pixelPerfect = pixelPerfect; emptySprite.persistent = persistent; emptySprite.ignoreClipping = ignoreClipping; emptySprite.bleedCompensation = bleedCompensation; if (!managed) emptySprite.renderer.sharedMaterial = renderer.sharedMaterial; else { if (manager != null) { emptySprite.Managed = managed; manager.AddSprite(emptySprite); emptySprite.SetDrawLayer(drawLayer); // Knob should be drawn in front of the bar } else Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!"); } emptySprite.color = color; emptySprite.SetAnchor(anchor); emptySprite.Setup(width, height, m_spriteMesh.material); if (states[1].spriteFrames.Length != 0) { emptySprite.animations = new UVAnimation[1]; emptySprite.animations[0] = new UVAnimation(); emptySprite.animations[0].SetAnim(states[1], 0); emptySprite.PlayAnim(0, 0); } emptySprite.renderCamera = renderCamera; emptySprite.Hide(IsHidden()); // Add our child objects as children // of our container: if(container != null) { container.AddChild(knob.gameObject); container.AddChild(emptySprite.gameObject); } SetState(0); // Force the value to update: m_value = -1f; Value = defaultValue; } // Since hiding while managed depends on // setting our mesh extents to 0, and the // foregoing code causes us to not be set // to 0, re-hide ourselves: if (managed && m_hidden) Hide(true); }
public override void Start() { if (this.m_started) { return; } base.Start(); if (Application.isPlaying) { this.truncFloor = this.stopKnobFromEdge / this.width; this.truncRange = 1f - this.truncFloor * 2f; this.knob = (UIScrollKnob) new GameObject { name = base.name + " - Knob", transform = { parent = base.transform, localPosition = this.CalcKnobStartPos(), localRotation = Quaternion.identity, localScale = Vector3.one }, layer = base.gameObject.layer }.AddComponent(typeof(UIScrollKnob)); this.knob.plane = this.plane; this.knob.SetOffset(this.knobOffset); this.knob.persistent = this.persistent; this.knob.bleedCompensation = this.bleedCompensation; if (!this.managed) { if (this.knob.spriteMesh != null) { ((SpriteMesh)this.knob.spriteMesh).material = base.renderer.sharedMaterial; } } else if (this.manager != null) { this.knob.Managed = this.managed; this.manager.AddSprite(this.knob); this.knob.SetDrawLayer(this.drawLayer + 1); } else { TsLog.LogError("Sprite on object \"" + base.name + "\" not assigned to a SpriteManager!", new object[0]); } this.knob.SetSpriteTile(this.m_sprKnobTile.m_eTileMode, this.m_sprKnobTile.m_fTileWidth, this.m_sprKnobTile.m_fTileHeight); this.knob.autoResize = this.autoResize; if (this.pixelPerfect) { this.knob.pixelPerfect = true; } else { this.knob.SetSize(this.knobSize.x, this.knobSize.y); } this.knob.ignoreClipping = this.ignoreClipping; this.knob.SetColliderSizeFactor(this.knobColliderSizeFactor); this.knob.SetSlider(this); this.knob.SetMaxScroll(this.width - this.stopKnobFromEdge * 2f); this.knob.SetInputDelegate(this.inputDelegate); this.knob.transitions[0] = this.transitions[1]; this.knob.transitions[1] = this.transitions[2]; this.knob.transitions[2] = this.transitions[3]; this.knob.layers = this.knobLayers; for (int i = 0; i < this.knobLayers.Length; i++) { this.knobLayers[i].transform.parent = this.knob.transform; } this.knob.animations[0].SetAnim(this.states[1], 0); this.knob.animations[1].SetAnim(this.states[2], 1); this.knob.animations[2].SetAnim(this.states[3], 2); this.knob.SetupAppearance(); this.knob.SetCamera(this.renderCamera); this.knob.Hide(base.IsHidden()); if (this.container != null) { this.container.AddChild(this.knob.gameObject); this.container.AddChild(this.emptySprite.gameObject); this.container.AddChild(this.upButton.gameObject); this.container.AddChild(this.downButton.gameObject); this.downButton.PlayAnim(0, 0); this.upButton.PlayAnim(0, 0); } BoxCollider boxCollider = (BoxCollider)base.gameObject.AddComponent(typeof(BoxCollider)); boxCollider.size = new Vector3(this.width, this.height, 0f); boxCollider.center = new Vector3(this.width / 2f, this.height / 2f, 0f); boxCollider.isTrigger = true; this.customCollider = true; this.SetState(0); this.m_value = -1f; this.Value = this.defaultValue; } if (this.managed && this.m_hidden) { this.Hide(true); } this.SetColor(this.color); }