예제 #1
0
    protected void CreateCaret()
    {
        // Create our caret and hide it by default:
        GameObject go = new GameObject();

        go.name                    = name + " - caret";
        go.transform.parent        = transform;
        go.transform.localPosition = Vector3.zero;
        go.transform.localRotation = Quaternion.identity;
        go.transform.localScale    = Vector3.one;
        go.layer                   = gameObject.layer;
        caret        = (AutoSprite)go.AddComponent(typeof(AutoSprite));
        caret.plane  = plane;
        caret.offset = caretOffset;
        caret.SetAnchor(caretAnchor);
        caret.persistent = persistent;
        if (!managed)
        {
            if (caret.spriteMesh != null)
            {
                ((SpriteMesh)caret.spriteMesh).material = renderer.sharedMaterial;
            }
        }
        else
        {
            if (manager != null)
            {
                caret.Managed = managed;
                manager.AddSprite(caret);
                caret.SetDrawLayer(drawLayer + 1);                      // Caret should be drawn in front of the field graphic
            }
            else
            {
                Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!");
            }
        }
        caret.autoResize = autoResize;
        if (pixelPerfect)
        {
            caret.pixelPerfect = pixelPerfect;
        }
        else
        {
            caret.SetSize(caretSize.x, caretSize.y);
        }

        if (states[1].spriteFrames.Length != 0)
        {
            caret.animations    = new UVAnimation[1];
            caret.animations[0] = new UVAnimation();
            caret.animations[0].SetAnim(states[1], 0);
            caret.PlayAnim(0, 0);
        }
        caret.renderCamera = renderCamera;
        caret.SetCamera(renderCamera);
        caret.Hide(true);
        transitions[1].list[0].MainSubject = caret.gameObject;

        PositionCaret();

        if (container != null)
        {
            container.AddSubject(caret.gameObject);
        }
    }
	protected void CreateCaret()
	{
		// Create our caret and hide it by default:
		GameObject go = new GameObject();
		go.name = name + " - caret";
		go.transform.parent = transform;
		go.transform.localPosition = Vector3.zero;
		go.transform.localRotation = Quaternion.identity;
		go.transform.localScale = Vector3.one;
		go.layer = gameObject.layer;
		caret = (AutoSprite)go.AddComponent(typeof(AutoSprite));
		caret.plane = plane;
		caret.offset = caretOffset;
		caret.SetAnchor(caretAnchor);
		caret.persistent = persistent;
		if (!managed)
		{
			if (caret.spriteMesh != null)
				((SpriteMesh)caret.spriteMesh).material = renderer.sharedMaterial;
		}
		else
		{
			if (manager != null)
			{
				caret.Managed = managed;
				manager.AddSprite(caret);
				caret.SetDrawLayer(drawLayer + 1);	// Caret should be drawn in front of the field graphic
			}
			else
				Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!");
		}
		caret.autoResize = autoResize;
		if (pixelPerfect)
			caret.pixelPerfect = pixelPerfect;
		else
			caret.SetSize(caretSize.x, caretSize.y);

		if (states[1].spriteFrames.Length != 0)
		{
			caret.animations = new UVAnimation[1];
			caret.animations[0] = new UVAnimation();
			caret.animations[0].SetAnim(states[1], 0);
			caret.PlayAnim(0, 0);
		}
		caret.renderCamera = renderCamera;
		caret.SetCamera(renderCamera);
		caret.Hide(true);
		transitions[1].list[0].MainSubject = caret.gameObject;

		PositionCaret();

		if (container != null)
			container.AddSubject(caret.gameObject);
	}
예제 #3
0
	protected override void Start()
	{
		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;
			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.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.SetCamera(renderCamera);
			emptySprite.Hide(IsHidden());

			Value = m_value;

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

			SetState(0);
		}
	}
예제 #4
0
	protected override void Start()
	{
		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.persistent = persistent;
			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.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;
			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.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.SetCamera(renderCamera);
			emptySprite.Hide(IsHidden());
			
			Value = m_value;

			// Add our child objects as children
			// of our container:
			if(container != null)
			{
				container.AddChild(knob.gameObject);
				container.AddChild(emptySprite.gameObject);
			}

			SetState(0);
		}
	}
예제 #5
0
	protected override void Start()
	{
		base.Start();

		// Create a TextMesh object if none exists:
		if (spriteText == null)
		{
			Text = " ";
			Text = "";
		}

		if(spriteText != null)
		{
			origTextPos = spriteText.transform.localPosition;
			SetMargins(margins);
		}

		// Set the insertion point to the end by default:
		insert = Text.Length;

		// Runtime init stuff:
		if (Application.isPlaying)
		{
			// Create a default collider if none exists:
			if (collider == null)
				AddCollider();

			// Create our caret and hide it by default:
			GameObject go = new GameObject();
			go.name = name + " - caret";
			go.transform.parent = transform;
			go.transform.localPosition = Vector3.zero;
			go.transform.localRotation = Quaternion.identity;
			go.transform.localScale = Vector3.one;
			go.layer = gameObject.layer;
			caret = (AutoSprite)go.AddComponent(typeof(AutoSprite));
			caret.plane = plane;
			caret.offset = caretOffset;
			caret.SetAnchor(caretAnchor);
			caret.persistent = persistent;
			if (!managed)
			{
				if (caret.spriteMesh != null)
					((SpriteMesh)caret.spriteMesh).material = renderer.sharedMaterial;
			}
			else
			{
				if (manager != null)
				{
					caret.Managed = managed;
					manager.AddSprite(caret);
					caret.SetDrawLayer(drawLayer + 1);	// Caret should be drawn in front of the field graphic
				}
				else
					Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!");
			}
			caret.autoResize = autoResize;
			if (pixelPerfect)
				caret.pixelPerfect = pixelPerfect;
			else
				caret.SetSize(caretSize.x, caretSize.y);

			if (states[1].spriteFrames.Length != 0)
			{
				caret.animations = new UVAnimation[1];
				caret.animations[0] = new UVAnimation();
				caret.animations[0].SetAnim(states[1], 0);
				caret.PlayAnim(0, 0);
			}
			caret.SetCamera(renderCamera);
			caret.Hide(true);
			transitions[1].list[0].MainSubject = caret.gameObject;

			PositionCaret();

			if (container != null)
				container.AddChild(caret.gameObject);
		}

		cachedPos = transform.position;
		cachedRot = transform.rotation;
		cachedScale = transform.lossyScale;
		CalcClippingRect();
	}