Пример #1
0
    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);
        }
    }
Пример #2
0
	public override void Start()
	{
		if (m_started)
			return;

		base.Start();

		// Assign our aggregate layers:
		aggregateLayers = new SpriteRoot[2][];
		aggregateLayers[0] = filledLayers;
		aggregateLayers[1] = emptyLayers;

		// Runtime init stuff:
		if(Application.isPlaying)
		{
			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 other sprite for the 
			// empty/background portion:
			GameObject emptyObj = new GameObject();
			emptyObj.name = name + " - Empty Bar";
			emptyObj.transform.parent = transform;
			emptyObj.transform.localPosition = Vector3.zero;
			emptyObj.transform.localScale = Vector3.one;
			emptyObj.transform.localRotation = Quaternion.identity;
			emptyObj.layer = gameObject.layer;
			emptySprite = (AutoSprite)emptyObj.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());

			Value = m_value;

			if (container != null)
				container.AddChild(emptyObj);

			SetState(0);
		}

		// 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);
	}
Пример #3
0
	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:
#if !UNITY_FLASH
			knob.transitions[0] = transitions[2];
			knob.transitions[1] = transitions[3];
			knob.transitions[2] = transitions[4];
#else
			EZTransitionList t = transitions[2];
			knob.transitions[0] = t;	t = transitions[3];
			knob.transitions[1] = t;	t = transitions[4];
			knob.transitions[2] = t;
#endif

			// 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);
	}
Пример #4
0
    public override void Start()
    {
        if (m_started)
        {
            return;
        }

        base.Start();

        // Assign our aggregate layers:
        aggregateLayers    = new SpriteRoot[2][];
        aggregateLayers[0] = filledLayers;
        aggregateLayers[1] = emptyLayers;

        // Runtime init stuff:
        if (Application.isPlaying)
        {
            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 other sprite for the
            // empty/background portion:
            GameObject emptyObj = new GameObject();
            emptyObj.name                    = name + " - Empty Bar";
            emptyObj.transform.parent        = transform;
            emptyObj.transform.localPosition = Vector3.zero;
            emptyObj.transform.localScale    = Vector3.one;
            emptyObj.transform.localRotation = Quaternion.identity;
            emptyObj.layer                   = gameObject.layer;
            emptySprite                   = (AutoSprite)emptyObj.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());

            Value = m_value;

            if (container != null)
            {
                container.AddChild(emptyObj);
            }

            SetState(0);
        }

        // 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);
        }
    }