Example #1
0
	public PassiveEffect hasPassiveEffectForTime(EWhenToApply aTimeToApply,float aTargetHPVal,float aMyHP,ElementalType aAttackerType,ElementalType aDefendentType,BetterList<BattleMonster> aAllies,BetterList<BattleMonster> aOpponents,ERangedStatus aRange,BattleMonster aAttacker,ElementalType aAttackingMoveElement,EStatusEffects aStatusEffectInduced = EStatusEffects.None) {
		for(int i = 0;i<_effects.size;i++) {
			if(_effects[i].applyAt==aTimeToApply) {
				
				if((_effects[i].applyAt==EWhenToApply.AtEndOfMoveQueue)||
				   (_effects[i].applyAt==EWhenToApply.BattleStart)||
				   (_effects[i].applyAt==EWhenToApply.WhenHit)
				) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenAttackingWithMoveType)&&(aAttackingMoveElement==_effects[i].whenMoveElementType)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenTheirHPHigherThan)&&(aTargetHPVal>_effects[i].HPPercentage)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenTheirHPLowerThan)&&(aTargetHPVal<_effects[i].HPPercentage)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenMyHPHigherThan)&&(aMyHP>(1/_effects[i].HPPercentage))) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenMyHPLowerThan)&&(aMyHP<(1/_effects[i].HPPercentage))) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenAttackerIsType)&&(aAttackerType==_effects[i].whenMoveElementType)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenDefendentIsType)&&(aDefendentType==_effects[i].whenMoveElementType)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenAlliesAreType)&&(listContainsElement(_effects[i].whenMoveElementType,aAllies).size>0)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenDefendentIsType)&&(listContainsElement(_effects[i].whenMoveElementType,aOpponents).size>0)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenOneOpponentisSameAsEffectOwner)&&(listContainsElement(aAttackerType,aOpponents).size>0)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenHitByMoveType)&&(aAttackerType==_effects[i].whenMoveElementType)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenHitByRangeType)&&(aRange==_effects[i].whenRangeType)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenOpponentHasStatusEffect)&&(listContainsStatusEffect(_effects[i].whenStatusEffects,aOpponents).size>0)) {
					return _effects[i];
				}
				if((_effects[i].applyAt==EWhenToApply.WhenStatusEffectsSuffered)&&((_effects[i].whenStatusEffects&aAttacker.statusEffects)!=EStatusEffects.None)) {
					return _effects[i];
				}
				
				if((_effects[i].applyAt==EWhenToApply.WhenHitByMoveTypeAtEndOfMoveQueue)&&(_effects[i].whenMoveElementType==aAttackingMoveElement)) {
					return _effects[i];
				}
			}
		}
		return null;
	}
Example #2
0
	public void activate(BetterList<RacingAI> aFinishers) {


		this.gameObject.SetActive(true);
		aFinishers.Sort(finishPositionSort);
		int i = 0;
		for(i = 0;i<aFinishers.size;i++) {
			completeMembers[i].init(aFinishers[i],i);
			
			completeMembers[i].gameObject.SetActive(true);
		}
		if(ChampionshipSeason.ACTIVE_SEASON.getTeamFromDriver(completeMembers[0].driver.driverRecord)==ChampionshipSeason.ACTIVE_SEASON.getUsersTeam()) {
			MobileNativeRateUs ratePopUp =  new MobileNativeRateUs("Enjoying Racing Manager?", "Rate us 5 Stars to help with future updates!","5 Stars","Not Right Now","Never!");
			#if UNITY_IOS
				ratePopUp.SetAppleId("975017895");
			#endif
			#if UNITY_ANDROID
				ratePopUp.SetAndroidAppUrl("market://details?id=com.blueomega.gpmanager");
			#endif
			ratePopUp.addEventListener(BaseEvent.COMPLETE,OnRatePopUpClose);
			ratePopUp.Start();
		} 
		for(int c = i;c<completeMembers.Count;c++) {
			completeMembers[i].gameObject.SetActive(false);
		}
	}
Example #3
0
		protected IEnumerator doAttackAnimation(MoveLibItem aMoveItem) {
			
			BetterList<BattleMonster> allTargets = new BetterList<BattleMonster>();
			allTargets.Add(this.monster);
			yield return new WaitForSeconds(0.45f);
			for(int i = 0;i<allTargets.size;i++) {
				
				GameObject animPrefab = aMoveItem.attackAnimationPrefab;
				if(animPrefab!=null)
					animPrefab.tag = "ParticleSystems";
				MoveAnimationLibItem anim = aMoveItem.attackAnimation;
				if(anim.movementType=="Normal") {
					if(animPrefab!=null)
						animPrefab.transform.position = allTargets[i].SpawnPosition;
				} else {
					if(animPrefab!=null) {
						animPrefab.transform.position = monster.SpawnPosition;
						Hashtable h = new Hashtable();
						h.Add("position",new Vector3(10,0,0));
						h.Add ("time",aMoveItem.attackAnimation.seconds);
						h.Add ("oncompletetarget",this.gameObject);
						h.Add ("oncomplete","AttackAnimationFinish");
						h.Add ("oncompleteparams",animPrefab);
					//	h.Add("easetype",iTween.EaseType.easeInQuad);
					//	iTween.MoveTo(animPrefab,h);
					}
				}
			}
			putParticlesInfront();
			//		StartCoroutine(pauseForDefenseAnim(targetMonster,0.01f/*aMoveQueue.moveData.attackAnimation.seconds*0.5f*/));
			//StartCoroutine(pauseForAttack(aMoveQueue,aMoveQueue.moveData.attackAnimation.seconds));
		}
Example #4
0
 public override CLS_Content.Value New(CLS_Content content, BetterList<CLS_Content.Value> _params)
 {
     CLS_Content.Value val = new CLS_Content.Value();
     val.type = typeof(UnityEngine.Random);
     val.value = new UnityEngine.Random();
     return val;
 }
 public void WriteToBuffers(BetterList<Vector3> v, BetterList<Vector2> u, BetterList<Color32> c, BetterList<Vector3> n, BetterList<Vector4> t)
 {
     if ((this.mRtpVerts != null) && (this.mRtpVerts.size > 0))
     {
         if (n == null)
         {
             for (int i = 0; i < this.mRtpVerts.size; i++)
             {
                 v.Add(this.mRtpVerts.buffer[i]);
                 u.Add(this.uvs.buffer[i]);
                 c.Add(this.cols.buffer[i]);
             }
         }
         else
         {
             for (int j = 0; j < this.mRtpVerts.size; j++)
             {
                 v.Add(this.mRtpVerts.buffer[j]);
                 u.Add(this.uvs.buffer[j]);
                 c.Add(this.cols.buffer[j]);
                 n.Add(this.mRtpNormal);
                 t.Add(this.mRtpTan);
             }
         }
     }
 }
Example #6
0
 public override CLS_Content.Value New(CLS_Content content, BetterList<CLS_Content.Value> _params)
 {
     CLS_Content.Value val = new CLS_Content.Value();
     val.type = typeof(Time);
     val.value = new Time();
     return val;
 }
Example #7
0
	public BetterList<EStatusEffects> StatusEffectsAsList() {
		BetterList<EStatusEffects> r = new BetterList<EStatusEffects> ();
		if ((this._currentStatusEffects & EStatusEffects.Burn) == EStatusEffects.Burn) {
			r.Add(EStatusEffects.Burn);
		}
		if ((this._currentStatusEffects & EStatusEffects.Confusion) == EStatusEffects.Confusion) {
			r.Add(EStatusEffects.Confusion);
		}
		if ((this._currentStatusEffects & EStatusEffects.Flinch) == EStatusEffects.Flinch) {
			r.Add(EStatusEffects.Flinch);
		}
		if ((this._currentStatusEffects & EStatusEffects.Freeze) == EStatusEffects.Freeze) {
			r.Add(EStatusEffects.Freeze);
		}
		if ((this._currentStatusEffects & EStatusEffects.Paralyze) == EStatusEffects.Paralyze) {
			r.Add(EStatusEffects.Paralyze);
		}
		if ((this._currentStatusEffects & EStatusEffects.Poison) == EStatusEffects.Poison) {
			r.Add(EStatusEffects.Poison);
		}
		if ((this._currentStatusEffects & EStatusEffects.Sleep) == EStatusEffects.Sleep) {
			r.Add(EStatusEffects.Sleep);
		}
		return r;
	}
 public override CLS_Content.Value New(CLS_Content content, BetterList<CLS_Content.Value> _params)
 {
     CLS_Content.Value val = new CLS_Content.Value();
     val.type = typeof(SphereCollider);
     val.value = new SphereCollider();
     return val;
 }
Example #9
0
				public BattleInit(NPCBattlesRow aNPCBattle,BetterList<NPCBattleMonstersRow> aNPCMonsters) {
					battleBackground = aNPCBattle._BattleBG;
					if(REF!=null) {
						REF.cleanUp();
					}
					REF = this;
					_npcRef = aNPCBattle;
					this.itemsToAward = aNPCBattle._ItemsReward;
					this.money = aNPCBattle._CashReward;
					teams[0] = new BattleInitTeam();
					teams[0].controlType = ETeamControllerType.SinglePlayerUser;
					Debug.Log("Including NPC Actor: "+aNPCBattle._IncludedNPCActor);
					if(aNPCBattle._IncludedNPCActor!=null&&aNPCBattle._IncludedNPCActor.Length>0) {
						string alliesMonster = DialogueLua.GetActorField(aNPCBattle._IncludedNPCActor,"PrimaryMonster").AsString;
						Debug.Log ("Allies monster is: "+alliesMonster);
						int lev = PlayerMain.REF.highMonster.level;
						MonsterDataMain m = new MonsterDataMain();
						m.initMonster(MonsterLibrary.REF.getMonster(alliesMonster).ID,(byte) lev,true);
						teams[0].addFightingMonster(m,2,aNPCBattle._IncludedNPCActor);
					} 
			
					teams[1] = new BattleInitTeam();
					teams[1].controlType = ETeamControllerType.RegularAI;
					teams[1].initTeamFromBattlesRow(aNPCBattle,aNPCMonsters);;
					forcedConversation = aNPCBattle._ForcedConversation;
					convoNPCName = aNPCBattle._ConversationMainActor;
				}
Example #10
0
		public void handleMultiplayerMoveQueue(BetterList<MoveQueueItem> aList) {
			for(int i = 0; i < aList.size ; i++) {
				aList[i].actioningMonster = this.monsterFromPosition(aList[i].actionPosition);
				BattleBase.MultiplayerDebugText("Actioning Monster: "+aList[i].actioningMonster.name+" - Wants to perform: "+aList[i].moveData.Name);
				aList[i].actioningMonster.setFutureMove(aList[i].moveData,aList[i].targetTeam,aList[i].targetMonster,false);
			}
			
		}
Example #11
0
	public BetterList<ITMItem> getRandomItems(int aItemCount) {
		BetterList<ITMItem> r = new BetterList<ITMItem>();
		while(aItemCount>0) {
			r.Add(randomLibrary().randomItem());
			aItemCount--;
		}
		return r;
	}
Example #12
0
		public void setPreceedingMove(BetterList<MoveTreeCompletionDataRow> aAllMoves) {
			_preceedingMove = null;
			for(int i = 0 ; i < aAllMoves.size ; i++) {
				if(_moveTreeItemRef!=null&&_moveTreeItemRef.PreceedingMove!=null&&aAllMoves[i]!=null&&aAllMoves[i].itemRef.ID == _moveTreeItemRef.PreceedingMove.ID) {
					_preceedingMove = aAllMoves[i];
				}
			}
		}
 public BetterList<string> GetListOfSprites(string match)
 {
     if (this.mReplacement != null)
     {
         return this.mReplacement.GetListOfSprites(match);
     }
     if (string.IsNullOrEmpty(match))
     {
         return this.GetListOfSprites();
     }
     if (this.mSprites.Count == 0)
     {
         this.Upgrade();
     }
     BetterList<string> list = new BetterList<string>();
     int num = 0;
     int count = this.mSprites.Count;
     while (num < count)
     {
         UISpriteData data = this.mSprites[num];
         if (((data != null) && !string.IsNullOrEmpty(data.name)) && string.Equals(match, data.name, StringComparison.OrdinalIgnoreCase))
         {
             list.Add(data.name);
             return list;
         }
         num++;
     }
     char[] separator = new char[] { ' ' };
     string[] strArray = match.Split(separator, StringSplitOptions.RemoveEmptyEntries);
     for (int i = 0; i < strArray.Length; i++)
     {
         strArray[i] = strArray[i].ToLower();
     }
     int num4 = 0;
     int num5 = this.mSprites.Count;
     while (num4 < num5)
     {
         UISpriteData data2 = this.mSprites[num4];
         if ((data2 != null) && !string.IsNullOrEmpty(data2.name))
         {
             string str = data2.name.ToLower();
             int num6 = 0;
             for (int j = 0; j < strArray.Length; j++)
             {
                 if (str.Contains(strArray[j]))
                 {
                     num6++;
                 }
             }
             if (num6 == strArray.Length)
             {
                 list.Add(data2.name);
             }
         }
         num4++;
     }
     return list;
 }
Example #14
0
		public void initTargets(BetterList<BattleMonster> aMonster,BattleTeam aOwningTeam) {
			for(int i = 0;i<textures.Length;i++) {
				textures[i].gameObject.SetActive(false);
			}
			for(int i = 0;i<buttons.Length;i++) {
				buttons[i].gameObject.SetActive(false);
			}
			myMonsters = aMonster;
			owningTeam = aOwningTeam;
			int index = 0;
			for(int i = 0;i<aMonster.size;i++) {
				if(aMonster[i]!=null) {
					switch(aMonster[i].myPosition) {
						case(EMonsterPos.Top): 
							index = BattleConstants.TOP_INDEX;
						break;
						case(EMonsterPos.Front):
							index = BattleConstants.FRONT_INDEX;
						break;
						case(EMonsterPos.Bottom):
							index = BattleConstants.BOTTOM_INDEX;
						break;
					}
					buttons[index].gameObject.SetActive(true);
					textures[index].enabled = true;
					textures[index].mainTexture = (Texture) Resources.Load("FlatMonsters/"+aMonster[i].monster.monsterBreedRef.Name.ToLower().Replace(" ",""));
					if(textures[index].mainTexture!=null) {
						textures[index].width = textures[index].mainTexture.width;
						textures[index].height = 100;//t.mainTexture.height;
						textures[index].aspectRatio = textures[index].mainTexture.width/textures[index].mainTexture.height;
						textures[index].keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight;
						textures[index].aspectRatio = (float) textures[index].mainTexture.width/(float) textures[index].mainTexture.height;
						textures[index].height = 90;//t.mainTexture.height;
						textures[index].gameObject.SetActive(true);
					}
					if(aMonster[i].monster.restingStatus!=ERestingStatus.Awake) {
						buttons[index].enabled = false;
					//	textures[index].GetComponent<BoxCollider2D>().enabled = false;
						TweenAlpha.Begin(textures[index].gameObject.transform.parent.gameObject,0.25f,0.1f);
						
					} else {
						
						buttons[index].enabled = true;
						//	textures[index].GetComponent<BoxCollider2D>().enabled = true;
						TweenAlpha.Begin(textures[index].gameObject.transform.parent.gameObject,0.25f,1f);
					}
					
				}
				else {
					
					buttons[index].enabled = false;
					//	textures[index].GetComponent<BoxCollider2D>().enabled = true;
					TweenAlpha.Begin(textures[index].gameObject.transform.parent.gameObject,0.25f,0.1f);
				}
			}

			
		}
Example #15
0
	public void initPreceedingMove(BetterList<MoveTreeItem> aOtherItems) {
		_preceedingMove = null;
		if (_preceedingMoveID > 0) {
			for(int i = 0;i < aOtherItems.size ; i++) {
				if(aOtherItems[i].ID==_preceedingMoveID) {
					_preceedingMove = aOtherItems[i];
				}
			}
		}
	}
Example #16
0
 public CLS_Content.Value Call(CLS_Content content, BetterList<CLS_Content.Value> param)
 {
     string output = "trace:";
     for (int i = 0; i < param.size; i++)
     {
         output += " " + param[i].value;
     }
     UnityEngine.Debug.Log(output);
     //content.environment.logger.Log(output);
     return CLS_Content.Value.Void;
 }
Example #17
0
	private BetterList<MoveTreeCompletionDataRow> getBranchByPower(EMoveBranch aMoveBranch,byte aMaxMoves) {
		BetterList<MoveTreeCompletionDataRow> r = new BetterList<MoveTreeCompletionDataRow>();
		int i = _items.size;
		while(i>0&&r.size<aMaxMoves) {
			i--;
			if(_items[i].moveBranch==aMoveBranch&&_items[i].canBeSelected) {
				r.Add(_items[i]);
			}
		}
		return r;
	}
Example #18
0
	public BetterList<MonsterLibraryRecord> getMonstersOfElement(ElementalType aElementalType) {
		BetterList<MonsterLibraryRecord> rec = new BetterList<MonsterLibraryRecord>();
		for(int i = 0; i < list.size ; i++) {
			if((list[i].PrimaryElement==aElementalType)||(list[i].SecondaryElement==aElementalType)) {
				if(list[i].Name!="No Creature")
					rec.Add(list[i]);
			
			}
		}
		return rec;
	}
Example #19
0
	public BetterList<MoveTreeCompletionDataRow> getBranch(EMoveBranch aBranch) {
		BetterList<MoveTreeCompletionDataRow> r = new BetterList<MoveTreeCompletionDataRow>();
		int i = _items.size;
		while(i>0) {
			i--;
			if(_items[i].moveBranch==aBranch) {
				r.Add(_items[i]);
			}
		}
		return r;
	}
Example #20
0
		private string createStatChangeString(BetterList<string> aStatNames) {
			string r = this.name+" "+aStatNames[0];
			aStatNames.RemoveAt(0);
			while(aStatNames.size>1) {
				r+= ", "+aStatNames[0];
				aStatNames.RemoveAt(0);
			}
			if(aStatNames.size>0) { 
				r += " and "+aStatNames[0];
			}
			return r;
		}
        public override CLS_Content.Value MemberCall(CLS_Content content, object object_this, string function, BetterList<CLS_Content.Value> _params, bool isBaseCall = false)
        {
            if (function == "ClosestPointOnBounds")
            {
                CLS_Content.Value val = new CLS_Content.Value();
                val.type = typeof(Vector3);
                val.value = ((Collider)object_this).ClosestPointOnBounds(((Vector3)_params[0].value));
                return val;
            }

            return base.MemberCall(content, object_this, function, _params, isBaseCall);
        }
Example #22
0
		public static BetterList<NPCBattleMonstersRow> getMonstersForBattle(string aBattleName) {
			BetterList<NPCBattleMonstersRow> r = new BetterList<NPCBattleMonstersRow>();
			List<NPCBattleMonstersRow> l = NPCBattleMonsters.Instance.Rows;
			for(int i = 0;i<l.Count&&r.size<3;i++) {
				if(l[i]._BattleName==aBattleName) {
					r.Add(l[i]);
				}
			}
			if(r.size==0) {
				Debug.LogError("Battle: "+aBattleName+" Had no monsters!");
			}
			return r;
		}
	void OnEnable ()
	{
		Dictionary<string, string[]> dict = Localization.dictionary;

		if (dict.Count > 0)
		{
			mKeys = new BetterList<string>();

			foreach (KeyValuePair<string, string[]> pair in dict)
			{
				if (pair.Key == "KEY") continue;
				mKeys.Add(pair.Key);
			}
			mKeys.Sort(delegate (string left, string right) { return left.CompareTo(right); });
		}
	}
 private void ApplyShadow(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y)
 {
     Color mEffectColor = this.mEffectColor;
     mEffectColor.a *= base.alpha * base.mPanel.finalAlpha;
     Color32 color2 = ((this.bitmapFont == null) || !this.bitmapFont.premultipliedAlpha) ? mEffectColor : NGUITools.ApplyPMA(mEffectColor);
     for (int i = start; i < end; i++)
     {
         verts.Add(verts.buffer[i]);
         uvs.Add(uvs.buffer[i]);
         cols.Add(cols.buffer[i]);
         Vector3 vector = verts.buffer[i];
         vector.x += x;
         vector.y += y;
         verts.buffer[i] = vector;
         cols.buffer[i] = color2;
     }
 }
Example #25
0
		public float doAgilityChange(float aMultiplier,BetterList<string> aImprovedStatsArr,BetterList<string> aDecreasedStatsArr) {
			if(aMultiplier>1.0f&&this._agilityEffector<MAX_EFFECTOR_VALUE) {
				this._agilityEffector *= aMultiplier;
				aImprovedStatsArr.Add("Agility");
				return delayPerItem;
			} else
			if(aMultiplier<1.0f&&this._agilityEffector>MIN_EFFECTOR_VALUE) {
				if((EMonsterStat.Agility&this.invulnerableToChanges)!=EMonsterStat.Agility) {
					this._agilityEffector *= aMultiplier;
					aDecreasedStatsArr.Add ("Agility");
				} else {
					this.doCommentaryMessage(this.name+" is Invulnerable to Agility Changes",ECommentaryMessageType.StandardMessage);
				}
				return delayPerItem;
			}
			return 0;
		}
Example #26
0
    /// <summary>
    /// Virtual function called by the UIScreen that fills the buffers.
    /// </summary>
    public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color> cols)
    {
        verts.Add(new Vector3(1f,  0f, 0f));
        verts.Add(new Vector3(1f, -1f, 0f));
        verts.Add(new Vector3(0f, -1f, 0f));
        verts.Add(new Vector3(0f,  0f, 0f));

        uvs.Add(Vector2.one);
        uvs.Add(new Vector2(1f, 0f));
        uvs.Add(Vector2.zero);
        uvs.Add(new Vector2(0f, 1f));

        cols.Add(color);
        cols.Add(color);
        cols.Add(color);
        cols.Add(color);
    }
Example #27
0
	public override void OnFill (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
	{
		base.OnFill (verts, uvs, cols);
		
		
		Vector2 uv0 = new Vector2(mOuterUV.xMin, mOuterUV.yMin);
		Vector2 uv1 = new Vector2(mOuterUV.xMax, mOuterUV.yMax);
		
		verts.Add(new Vector3(1f,  0f, 0f));
		verts.Add(new Vector3(1f,  0f, extrusionDepth));
		verts.Add(new Vector3(1f,  -1f, extrusionDepth));
		verts.Add(new Vector3(1f,  -1f, 0f));
		
		verts.Add(new Vector3(1f,  0f, 0f));
		verts.Add(new Vector3(0f,  0f, 0f));
		verts.Add(new Vector3(0f,  0f, extrusionDepth));
		verts.Add(new Vector3(1f,  0f, extrusionDepth));
		
		verts.Add(new Vector3(0f,  -1f, 0f));
		verts.Add(new Vector3(0f,  -1f, extrusionDepth));
		verts.Add(new Vector3(0f,  0f, extrusionDepth));
		verts.Add(new Vector3(0f,  0f, 0f));
		
		verts.Add(new Vector3(1f,  -1f, extrusionDepth));
		verts.Add(new Vector3(0f,  -1f, extrusionDepth));
		verts.Add(new Vector3(0f,  -1f, 0f));
		verts.Add(new Vector3(1f,  -1f, 0f));
		
		for( int i = 0 ; i < 4 ; i++ ) {
			uvs.Add(uv1);
			uvs.Add(new Vector2(uv1.x, uv0.y));
			uvs.Add(uv0);
			uvs.Add(new Vector2(uv0.x, uv1.y));
		}
		
#if UNITY_3_5_4
		Color col = color;
#else
		Color32 col = color;
#endif
		for( int i = 0 ; i < 16 ; i++ ) {
			cols.Add(col);
		}
		
	}
Example #28
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="list"></param>
    public static void Execute(BetterList<System.Action> list)
    {
        if (list != null)
        {
            for (int i = 0; i < list.size; )
            {
                System.Action del = list[i];
                if (del != null)
                {
                    del();

                    if (i >= list.size) break;
                    if (list[i] != del) continue;
                }
                ++i;
            }
        }
    }
Example #29
0
        public override CLS_Content.Value StaticCall(CLS_Content content, string function, BetterList<CLS_Content.Value> _params)
        {
            if (function == "Equals")
            {
                CLS_Content.Value val = new CLS_Content.Value();
                val.type = typeof(bool);
                val.value = Time.Equals(_params[0].value, _params[1].value);
                return val;
            }
            else if (function == "ReferenceEquals")
            {
                CLS_Content.Value val = new CLS_Content.Value();
                val.type = typeof(bool);
                val.value = Time.ReferenceEquals(_params[0].value, _params[1].value);
                return val;
            }

            return base.StaticCall(content, function, _params);
        }
Example #30
0
        public override CLS_Content.Value MemberCall(CLS_Content content, object object_this, string function, BetterList<CLS_Content.Value> _params, bool isBaseCall = false)
        {
            if (function == "Equals")
            {
                CLS_Content.Value val = new CLS_Content.Value();
                val.type = typeof(bool);
                val.value = ((Time)object_this).Equals(_params[0].value);
                return val;
            }
            else if (function == "ToString")
            {
                CLS_Content.Value val = new CLS_Content.Value();
                val.type = typeof(string);
                val.value = ((Time)object_this).ToString();
                return val;
            }

            return base.MemberCall(content, object_this, function, _params, isBaseCall);
        }
Example #31
0
    /// <summary>
    /// Draw the on-screen selection, knobs, and handle all interaction logic.
    /// </summary>

    public void OnSceneGUI()
    {
        NGUIEditorTools.HideMoveTool(true);
        if (!UIWidget.showHandles)
        {
            return;
        }

        mWidget = target as UIWidget;

        Transform t = mWidget.cachedTransform;

        Event     e    = Event.current;
        int       id   = GUIUtility.GetControlID(s_Hash, FocusType.Passive);
        EventType type = e.GetTypeForControl(id);

        Action actionUnderMouse = mAction;

        Vector3[] handles = GetHandles(mWidget.worldCorners);

        NGUIHandles.DrawShadowedLine(handles, handles[0], handles[1], handlesColor);
        NGUIHandles.DrawShadowedLine(handles, handles[1], handles[2], handlesColor);
        NGUIHandles.DrawShadowedLine(handles, handles[2], handles[3], handlesColor);
        NGUIHandles.DrawShadowedLine(handles, handles[0], handles[3], handlesColor);

        // If the widget is anchored, draw the anchors
        if (mWidget.isAnchored)
        {
            DrawAnchorHandle(mWidget.leftAnchor, mWidget.cachedTransform, handles, 0, id);
            DrawAnchorHandle(mWidget.topAnchor, mWidget.cachedTransform, handles, 1, id);
            DrawAnchorHandle(mWidget.rightAnchor, mWidget.cachedTransform, handles, 2, id);
            DrawAnchorHandle(mWidget.bottomAnchor, mWidget.cachedTransform, handles, 3, id);
        }

        if (type == EventType.Repaint)
        {
            bool showDetails = (mAction == UIWidgetInspector.Action.Scale) || NGUISettings.drawGuides;
            if (mAction == UIWidgetInspector.Action.None && e.modifiers == EventModifiers.Control)
            {
                showDetails = true;
            }
            if (NGUITools.GetActive(mWidget) && mWidget.parent == null)
            {
                showDetails = true;
            }
            if (showDetails)
            {
                NGUIHandles.DrawSize(handles, mWidget.width, mWidget.height);
            }
        }

        // Presence of the legacy stretch component prevents resizing
        bool canResize = (mWidget.GetComponent <UIStretch>() == null);

        bool[] resizable = new bool[8];

        resizable[4] = canResize;               // left
        resizable[5] = canResize;               // top
        resizable[6] = canResize;               // right
        resizable[7] = canResize;               // bottom

        UILabel lbl = mWidget as UILabel;

        if (lbl != null)
        {
            if (lbl.overflowMethod == UILabel.Overflow.ResizeFreely)
            {
                resizable[4] = false;                   // left
                resizable[5] = false;                   // top
                resizable[6] = false;                   // right
                resizable[7] = false;                   // bottom
            }
            else if (lbl.overflowMethod == UILabel.Overflow.ResizeHeight)
            {
                resizable[5] = false;                   // top
                resizable[7] = false;                   // bottom
            }
        }

        if (mWidget.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnHeight)
        {
            resizable[4] = false;
            resizable[6] = false;
        }
        else if (mWidget.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnWidth)
        {
            resizable[5] = false;
            resizable[7] = false;
        }

        resizable[0] = resizable[7] && resizable[4];         // bottom-left
        resizable[1] = resizable[5] && resizable[4];         // top-left
        resizable[2] = resizable[5] && resizable[6];         // top-right
        resizable[3] = resizable[7] && resizable[6];         // bottom-right

        UIWidget.Pivot pivotUnderMouse = GetPivotUnderMouse(handles, e, resizable, true, ref actionUnderMouse);

        switch (type)
        {
        case EventType.Repaint:
        {
            Vector3 v0 = HandleUtility.WorldToGUIPoint(handles[0]);
            Vector3 v2 = HandleUtility.WorldToGUIPoint(handles[2]);

            if ((v2 - v0).magnitude > 60f)
            {
                Vector3 v1 = HandleUtility.WorldToGUIPoint(handles[1]);
                Vector3 v3 = HandleUtility.WorldToGUIPoint(handles[3]);

                Handles.BeginGUI();
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        DrawKnob(handles[i], mWidget.pivot == pivotPoints[i], resizable[i], id);
                    }

                    if ((v1 - v0).magnitude > 80f)
                    {
                        if (mWidget.leftAnchor.target == null || mWidget.leftAnchor.absolute != 0)
                        {
                            DrawKnob(handles[4], mWidget.pivot == pivotPoints[4], resizable[4], id);
                        }

                        if (mWidget.rightAnchor.target == null || mWidget.rightAnchor.absolute != 0)
                        {
                            DrawKnob(handles[6], mWidget.pivot == pivotPoints[6], resizable[6], id);
                        }
                    }

                    if ((v3 - v0).magnitude > 80f)
                    {
                        if (mWidget.topAnchor.target == null || mWidget.topAnchor.absolute != 0)
                        {
                            DrawKnob(handles[5], mWidget.pivot == pivotPoints[5], resizable[5], id);
                        }

                        if (mWidget.bottomAnchor.target == null || mWidget.bottomAnchor.absolute != 0)
                        {
                            DrawKnob(handles[7], mWidget.pivot == pivotPoints[7], resizable[7], id);
                        }
                    }
                }
                Handles.EndGUI();
            }
        }
        break;

        case EventType.MouseDown:
        {
            if (actionUnderMouse != Action.None)
            {
                mStartMouse     = e.mousePosition;
                mAllowSelection = true;

                if (e.button == 1)
                {
                    if (e.modifiers == 0)
                    {
                        GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                        e.Use();
                    }
                }
                else if (e.button == 0 && actionUnderMouse != Action.None && Raycast(handles, out mStartDrag))
                {
                    mWorldPos      = t.position;
                    mLocalPos      = t.localPosition;
                    mStartRot      = t.localRotation.eulerAngles;
                    mStartDir      = mStartDrag - t.position;
                    mStartWidth    = mWidget.width;
                    mStartHeight   = mWidget.height;
                    mStartLeft.x   = mWidget.leftAnchor.relative;
                    mStartLeft.y   = mWidget.leftAnchor.absolute;
                    mStartRight.x  = mWidget.rightAnchor.relative;
                    mStartRight.y  = mWidget.rightAnchor.absolute;
                    mStartBottom.x = mWidget.bottomAnchor.relative;
                    mStartBottom.y = mWidget.bottomAnchor.absolute;
                    mStartTop.x    = mWidget.topAnchor.relative;
                    mStartTop.y    = mWidget.topAnchor.absolute;

                    mDragPivot            = pivotUnderMouse;
                    mActionUnderMouse     = actionUnderMouse;
                    GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                    e.Use();
                }
            }
        }
        break;

        case EventType.MouseDrag:
        {
            // Prevent selection once the drag operation begins
            bool dragStarted = (e.mousePosition - mStartMouse).magnitude > 3f;
            if (dragStarted)
            {
                mAllowSelection = false;
            }

            if (GUIUtility.hotControl == id)
            {
                e.Use();

                if (mAction != Action.None || mActionUnderMouse != Action.None)
                {
                    Vector3 pos;

                    if (Raycast(handles, out pos))
                    {
                        if (mAction == Action.None && mActionUnderMouse != Action.None)
                        {
                            // Wait until the mouse moves by more than a few pixels
                            if (dragStarted)
                            {
                                if (mActionUnderMouse == Action.Move)
                                {
                                    NGUISnap.Recalculate(mWidget);
                                }
                                else if (mActionUnderMouse == Action.Rotate)
                                {
                                    mStartRot = t.localRotation.eulerAngles;
                                    mStartDir = mStartDrag - t.position;
                                }
                                else if (mActionUnderMouse == Action.Scale)
                                {
                                    mStartWidth  = mWidget.width;
                                    mStartHeight = mWidget.height;
                                    mDragPivot   = pivotUnderMouse;
                                }
                                mAction = actionUnderMouse;
                            }
                        }

                        if (mAction != Action.None)
                        {
                            NGUIEditorTools.RegisterUndo("Change Rect", t);
                            NGUIEditorTools.RegisterUndo("Change Rect", mWidget);

                            // Reset the widget before adjusting anything
                            t.position     = mWorldPos;
                            mWidget.width  = mStartWidth;
                            mWidget.height = mStartHeight;
                            mWidget.leftAnchor.Set(mStartLeft.x, mStartLeft.y);
                            mWidget.rightAnchor.Set(mStartRight.x, mStartRight.y);
                            mWidget.bottomAnchor.Set(mStartBottom.x, mStartBottom.y);
                            mWidget.topAnchor.Set(mStartTop.x, mStartTop.y);

                            if (mAction == Action.Move)
                            {
                                // Move the widget
                                t.position = mWorldPos + (pos - mStartDrag);

                                // Snap the widget
                                Vector3 after = NGUISnap.Snap(t.localPosition, mWidget.localCorners, e.modifiers != EventModifiers.Control);

                                // Calculate the final delta
                                Vector3 localDelta = (after - mLocalPos);

                                // Restore the position
                                t.position = mWorldPos;

                                // Adjust the widget by the delta
                                NGUIMath.MoveRect(mWidget, localDelta.x, localDelta.y);
                            }
                            else if (mAction == Action.Rotate)
                            {
                                Vector3 dir   = pos - t.position;
                                float   angle = Vector3.Angle(mStartDir, dir);

                                if (angle > 0f)
                                {
                                    float dot = Vector3.Dot(Vector3.Cross(mStartDir, dir), t.forward);
                                    if (dot < 0f)
                                    {
                                        angle = -angle;
                                    }
                                    angle = mStartRot.z + angle;
                                    angle = (NGUISnap.allow && e.modifiers != EventModifiers.Control) ?
                                            Mathf.Round(angle / 15f) * 15f : Mathf.Round(angle);
                                    t.localRotation = Quaternion.Euler(mStartRot.x, mStartRot.y, angle);
                                }
                            }
                            else if (mAction == Action.Scale)
                            {
                                // Move the widget
                                t.position = mWorldPos + (pos - mStartDrag);

                                // Calculate the final delta
                                Vector3 localDelta = (t.localPosition - mLocalPos);

                                // Restore the position
                                t.position = mWorldPos;

                                // Adjust the widget's position and scale based on the delta, restricted by the pivot
                                NGUIMath.ResizeWidget(mWidget, mDragPivot, localDelta.x, localDelta.y, 2, 2);
                                ReEvaluateAnchorType();
                            }
                        }
                    }
                }
            }
        }
        break;

        case EventType.MouseUp:
        {
            if (GUIUtility.hotControl == id)
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;

                if (e.button < 2)
                {
                    bool handled = false;

                    if (e.button == 1)
                    {
                        // Right-click: Open a context menu listing all widgets underneath
                        NGUIEditorTools.ShowSpriteSelectionMenu(e.mousePosition);
                        handled = true;
                    }
                    else if (mAction == Action.None)
                    {
                        if (mAllowSelection)
                        {
                            // Left-click: Select the topmost widget
                            NGUIEditorTools.SelectWidget(e.mousePosition);
                            handled = true;
                        }
                    }
                    else
                    {
                        // Finished dragging something
                        Vector3 pos = t.localPosition;
                        pos.x           = Mathf.Round(pos.x);
                        pos.y           = Mathf.Round(pos.y);
                        pos.z           = Mathf.Round(pos.z);
                        t.localPosition = pos;
                        handled         = true;
                    }

                    if (handled)
                    {
                        e.Use();
                    }
                }

                // Clear the actions
                mActionUnderMouse = Action.None;
                mAction           = Action.None;
            }
            else if (mAllowSelection)
            {
                BetterList <UIWidget> widgets = NGUIEditorTools.SceneViewRaycast(e.mousePosition);
                if (widgets.size > 0)
                {
                    Selection.activeGameObject = widgets[0].gameObject;
                }
            }
            mAllowSelection = true;
        }
        break;

        case EventType.KeyDown:
        {
            if (e.keyCode == KeyCode.UpArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget);
                NGUIMath.MoveRect(mWidget, 0f, 1f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.DownArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget);
                NGUIMath.MoveRect(mWidget, 0f, -1f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.LeftArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget);
                NGUIMath.MoveRect(mWidget, -1f, 0f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.RightArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mWidget);
                NGUIMath.MoveRect(mWidget, 1f, 0f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.Escape)
            {
                if (GUIUtility.hotControl == id)
                {
                    if (mAction != Action.None)
                    {
                        Undo.PerformUndo();
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;

                    mActionUnderMouse = Action.None;
                    mAction           = Action.None;
                    e.Use();
                }
                else
                {
                    Selection.activeGameObject = null;
                }
            }
        }
        break;
        }
    }
Example #32
0
    public static string CheckEmotion(string str, UIAtlas atlas)
    {
        Tools_StringCheck.listEmotionData.Clear();
        int length = str.Length;
        int num    = -6;
        BetterList <string> listOfSprites = atlas.GetListOfSprites();

        for (int num2 = 0; num2 != length; num2++)
        {
            if (str[num2] == '#' && num2 + 4 < length && str[num2 + 1] == 'e')
            {
                EmotionData item = default(EmotionData);
                item.serialNumber = str.Substring(num2 + 2, 3);
                if (listOfSprites.Contains(item.serialNumber))
                {
                    if (Tools_StringCheck.IsShowVIPStr(str, num2))
                    {
                        int num3 = (num != 0) ? (num + 6) : (num + 7);
                        item.strContent    = str.Substring(num3, num2 + 5 - num3).Replace(str.Substring(num2, 5), (num2 != 0) ? "      " : "       ");
                        item.position      = num2;
                        item.row           = 1;
                        item.totalConSpace = item.strContent.Length;
                        item.totalNonSpace = (float)(str.Substring(num3, num2 + 5 - num3).Length - 5) + 1.5f;
                        Tools_StringCheck.listEmotionData.Add(item);
                        num = num2;
                        Regex regex = new Regex(str.Substring(num2, 5));
                        str    = regex.Replace(str, (num2 != 0) ? "      " : "       ", 1);
                        length = str.Length;
                    }
                }
            }
        }
        string text = string.Empty;

        if (Tools_StringCheck.listEmotionData != null && Tools_StringCheck.listEmotionData.Count != 0)
        {
            if (Tools_StringCheck.listEmotionData[Tools_StringCheck.listEmotionData.Count - 1].position == 0)
            {
                if (str.Length != 7)
                {
                    text = str.Substring(Tools_StringCheck.listEmotionData[Tools_StringCheck.listEmotionData.Count - 1].position + 7);
                }
            }
            else
            {
                text = str.Substring(Tools_StringCheck.listEmotionData[Tools_StringCheck.listEmotionData.Count - 1].position + 6);
            }
        }
        else
        {
            text = str;
        }
        string text2 = null;

        for (int num4 = 0; num4 != Tools_StringCheck.listEmotionData.Count; num4++)
        {
            text2 += Tools_StringCheck.listEmotionData[num4].strContent;
        }
        if (!string.IsNullOrEmpty(text))
        {
            text2 += text;
        }
        return(text2);
    }
    /// <summary>
    /// Filled sprite fill function.
    /// </summary>

    protected void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mFillAmount < 0.001f)
        {
            return;
        }

        Color colF = color;

        colF.a = finalAlpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;
        Vector4 v   = drawingDimensions;
        Vector4 u   = drawingUVs;

        // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely
        if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical)
        {
            if (mFillDirection == FillDirection.Horizontal)
            {
                float fill = (u.z - u.x) * mFillAmount;

                if (mInvert)
                {
                    v.x = v.z - (v.z - v.x) * mFillAmount;
                    u.x = u.z - fill;
                }
                else
                {
                    v.z = v.x + (v.z - v.x) * mFillAmount;
                    u.z = u.x + fill;
                }
            }
            else if (mFillDirection == FillDirection.Vertical)
            {
                float fill = (u.w - u.y) * mFillAmount;

                if (mInvert)
                {
                    v.y = v.w - (v.w - v.y) * mFillAmount;
                    u.y = u.w - fill;
                }
                else
                {
                    v.w = v.y + (v.w - v.y) * mFillAmount;
                    u.w = u.y + fill;
                }
            }
        }

        mTempPos[0] = new Vector2(v.x, v.y);
        mTempPos[1] = new Vector2(v.x, v.w);
        mTempPos[2] = new Vector2(v.z, v.w);
        mTempPos[3] = new Vector2(v.z, v.y);

        mTempUVs[0] = new Vector2(u.x, u.y);
        mTempUVs[1] = new Vector2(u.x, u.w);
        mTempUVs[2] = new Vector2(u.z, u.w);
        mTempUVs[3] = new Vector2(u.z, u.y);

        if (mFillAmount < 1f)
        {
            if (mFillDirection == FillDirection.Radial90)
            {
                if (RadialCut(mTempPos, mTempUVs, mFillAmount, mInvert, 0))
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        verts.Add(mTempPos[i]);
                        uvs.Add(mTempUVs[i]);
                        cols.Add(col);
                    }
                }
                return;
            }

            if (mFillDirection == FillDirection.Radial180)
            {
                for (int side = 0; side < 2; ++side)
                {
                    float fx0, fx1, fy0, fy1;

                    fy0 = 0f;
                    fy1 = 1f;

                    if (side == 0)
                    {
                        fx0 = 0f; fx1 = 0.5f;
                    }
                    else
                    {
                        fx0 = 0.5f; fx1 = 1f;
                    }

                    mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0);
                    mTempPos[1].x = mTempPos[0].x;
                    mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1);
                    mTempPos[3].x = mTempPos[2].x;

                    mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0);
                    mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1);
                    mTempPos[2].y = mTempPos[1].y;
                    mTempPos[3].y = mTempPos[0].y;

                    mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0);
                    mTempUVs[1].x = mTempUVs[0].x;
                    mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1);
                    mTempUVs[3].x = mTempUVs[2].x;

                    mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0);
                    mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1);
                    mTempUVs[2].y = mTempUVs[1].y;
                    mTempUVs[3].y = mTempUVs[0].y;

                    float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side);

                    if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4)))
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            verts.Add(mTempPos[i]);
                            uvs.Add(mTempUVs[i]);
                            cols.Add(col);
                        }
                    }
                }
                return;
            }

            if (mFillDirection == FillDirection.Radial360)
            {
                for (int corner = 0; corner < 4; ++corner)
                {
                    float fx0, fx1, fy0, fy1;

                    if (corner < 2)
                    {
                        fx0 = 0f; fx1 = 0.5f;
                    }
                    else
                    {
                        fx0 = 0.5f; fx1 = 1f;
                    }

                    if (corner == 0 || corner == 3)
                    {
                        fy0 = 0f; fy1 = 0.5f;
                    }
                    else
                    {
                        fy0 = 0.5f; fy1 = 1f;
                    }

                    mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0);
                    mTempPos[1].x = mTempPos[0].x;
                    mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1);
                    mTempPos[3].x = mTempPos[2].x;

                    mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0);
                    mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1);
                    mTempPos[2].y = mTempPos[1].y;
                    mTempPos[3].y = mTempPos[0].y;

                    mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0);
                    mTempUVs[1].x = mTempUVs[0].x;
                    mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1);
                    mTempUVs[3].x = mTempUVs[2].x;

                    mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0);
                    mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1);
                    mTempUVs[2].y = mTempUVs[1].y;
                    mTempUVs[3].y = mTempUVs[0].y;

                    float val = mInvert ?
                                mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) :
                                mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4));

                    if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4)))
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            verts.Add(mTempPos[i]);
                            uvs.Add(mTempUVs[i]);
                            cols.Add(col);
                        }
                    }
                }
                return;
            }
        }

        // Fill the buffer with the quad for the sprite
        for (int i = 0; i < 4; ++i)
        {
            verts.Add(mTempPos[i]);
            uvs.Add(mTempUVs[i]);
            cols.Add(col);
        }
    }
Example #34
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// </summary>

    static public void Print(string text, Font font, int size, FontStyle style, Color32 color,
                             bool encoding, TextAlignment alignment, int lineWidth, bool premultiply,
                             BetterList <Vector3> verts,
                             BetterList <Vector2> uvs,
                             BetterList <Color32> cols)
    {
        if (font == null || string.IsNullOrEmpty(text))
        {
            return;
        }

        float baseline = 0f;

        // We need to know the baseline first
        font.RequestCharactersInTexture("j", size, style);
        font.GetCharacterInfo('j', out mTempChar, size, style);
        baseline = size + mTempChar.vert.yMax;

        // Ensure that the text we're about to print exists in the font's texture
        font.RequestCharactersInTexture(text, size, style);

        // Start with the specified color
        mColors.Add(color);

        int     indexOffset = verts.size;
        int     maxX = 0;
        int     x = 0;
        int     y = 0;
        int     lineHeight = size;
        Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
        Vector2 u0 = Vector2.zero, u1 = Vector2.zero;

        int textLength = text.Length;

        for (int i = 0; i < textLength; ++i)
        {
            char c = text[i];

            if (c == '\n')
            {
                if (x > maxX)
                {
                    maxX = x;
                }

                if (alignment != TextAlignment.Left)
                {
                    Align(verts, indexOffset, alignment, x, lineWidth);
                    indexOffset = verts.size;
                }

                x  = 0;
                y += lineHeight;
                continue;
            }

            if (c < ' ')
            {
                continue;
            }

            if (encoding && ParseSymbol(text, ref i, mColors, premultiply))
            {
                color = mColors[mColors.size - 1];
                --i;
                continue;
            }

            if (!font.GetCharacterInfo(c, out mTempChar, size, style))
            {
                continue;
            }

            v0.x = (x + mTempChar.vert.xMin);
            v0.y = -(y - mTempChar.vert.yMax + baseline);

            v1.x = v0.x + mTempChar.vert.width;
            v1.y = v0.y - mTempChar.vert.height;

            u0.x = mTempChar.uv.xMin;
            u0.y = mTempChar.uv.yMin;
            u1.x = mTempChar.uv.xMax;
            u1.y = mTempChar.uv.yMax;

            x += (int)mTempChar.width;

            for (int b = 0; b < 4; ++b)
            {
                cols.Add(color);
            }

            if (mTempChar.flipped)
            {
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
            }
            else
            {
                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u0.x, u0.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u1.x, u1.y));
            }

            verts.Add(new Vector3(v1.x, v0.y));
            verts.Add(new Vector3(v0.x, v0.y));
            verts.Add(new Vector3(v0.x, v1.y));
            verts.Add(new Vector3(v1.x, v1.y));
        }

        if (alignment != TextAlignment.Left && indexOffset < verts.size)
        {
            Align(verts, indexOffset, alignment, x, lineWidth);
            indexOffset = verts.size;
        }
        mColors.Clear();
    }
Example #35
0
    /// <summary>
    /// Advanced sprite fill function. Contributed by Nicki Hansen.
    /// </summary>

    protected void AdvancedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (!mSprite.hasBorder)
        {
            SimpleFill(verts, uvs, cols);
            return;
        }

        Texture tex = material.mainTexture;

        if (tex == null)
        {
            return;
        }

        Vector4 dr = drawingDimensions;
        Vector4 br = border * atlas.pixelSize;

        Vector2 tileSize = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height);

        tileSize *= atlas.pixelSize;

        if (tileSize.x < 1f)
        {
            tileSize.x = 1f;
        }
        if (tileSize.y < 1f)
        {
            tileSize.y = 1f;
        }

        mTempPos[0].x = dr.x;
        mTempPos[0].y = dr.y;
        mTempPos[3].x = dr.z;
        mTempPos[3].y = dr.w;

        mTempPos[1].x = mTempPos[0].x + br.x;
        mTempPos[1].y = mTempPos[0].y + br.y;
        mTempPos[2].x = mTempPos[3].x - br.z;
        mTempPos[2].y = mTempPos[3].y - br.w;

        mTempUVs[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin);
        mTempUVs[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin);
        mTempUVs[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax);
        mTempUVs[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax);

        Color colF = color;

        colF.a = finalAlpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        for (int x = 0; x < 3; ++x)
        {
            int x2 = x + 1;

            for (int y = 0; y < 3; ++y)
            {
                if (centerType == AdvancedType.Invisible && x == 1 && y == 1)
                {
                    continue;
                }
                int y2 = y + 1;

                if (x == 1 && y == 1)                 // Center
                {
                    if (centerType == AdvancedType.Tiled)
                    {
                        float startPositionX = mTempPos[x].x;
                        float endPositionX   = mTempPos[x2].x;
                        float startPositionY = mTempPos[y].y;
                        float endPositionY   = mTempPos[y2].y;
                        float textureStartX  = mTempUVs[x].x;
                        float textureStartY  = mTempUVs[y].y;
                        float tileStartY     = startPositionY;

                        while (tileStartY < endPositionY)
                        {
                            float tileStartX  = startPositionX;
                            float textureEndY = mTempUVs[y2].y;
                            float tileEndY    = tileStartY + tileSize.y;

                            if (tileEndY > endPositionY)
                            {
                                textureEndY = Mathf.Lerp(textureStartY, textureEndY, (endPositionY - tileStartY) / tileSize.y);
                                tileEndY    = endPositionY;
                            }

                            while (tileStartX < endPositionX)
                            {
                                float tileEndX    = tileStartX + tileSize.x;
                                float textureEndX = mTempUVs[x2].x;

                                if (tileEndX > endPositionX)
                                {
                                    textureEndX = Mathf.Lerp(textureStartX, textureEndX, (endPositionX - tileStartX) / tileSize.x);
                                    tileEndX    = endPositionX;
                                }

                                FillBuffers(tileStartX, tileEndX, tileStartY, tileEndY, textureStartX,
                                            textureEndX, textureStartY, textureEndY, col, verts, uvs, cols);

                                tileStartX += tileSize.x;
                            }
                            tileStartY += tileSize.y;
                        }
                    }
                    else if (centerType == AdvancedType.Sliced)
                    {
                        FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y,
                                    mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols);
                    }
                }
                else if (x == 1)                 // Top or bottom
                {
                    if ((y == 0 && bottomType == AdvancedType.Tiled) || (y == 2 && topType == AdvancedType.Tiled))
                    {
                        float startPositionX = mTempPos[x].x;
                        float endPositionX   = mTempPos[x2].x;
                        float startPositionY = mTempPos[y].y;
                        float endPositionY   = mTempPos[y2].y;
                        float textureStartX  = mTempUVs[x].x;
                        float textureStartY  = mTempUVs[y].y;
                        float textureEndY    = mTempUVs[y2].y;
                        float tileStartX     = startPositionX;

                        while (tileStartX < endPositionX)
                        {
                            float tileEndX    = tileStartX + tileSize.x;
                            float textureEndX = mTempUVs[x2].x;

                            if (tileEndX > endPositionX)
                            {
                                textureEndX = Mathf.Lerp(textureStartX, textureEndX, (endPositionX - tileStartX) / tileSize.x);
                                tileEndX    = endPositionX;
                            }

                            FillBuffers(tileStartX, tileEndX, startPositionY, endPositionY, textureStartX,
                                        textureEndX, textureStartY, textureEndY, col, verts, uvs, cols);

                            tileStartX += tileSize.x;
                        }
                    }
                    else if ((y == 0 && bottomType == AdvancedType.Sliced) || (y == 2 && topType == AdvancedType.Sliced))
                    {
                        FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y,
                                    mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols);
                    }
                }
                else if (y == 1)                 // Left or right
                {
                    if ((x == 0 && leftType == AdvancedType.Tiled) || (x == 2 && rightType == AdvancedType.Tiled))
                    {
                        float startPositionX = mTempPos[x].x;
                        float endPositionX   = mTempPos[x2].x;
                        float startPositionY = mTempPos[y].y;
                        float endPositionY   = mTempPos[y2].y;
                        float textureStartX  = mTempUVs[x].x;
                        float textureEndX    = mTempUVs[x2].x;
                        float textureStartY  = mTempUVs[y].y;
                        float tileStartY     = startPositionY;

                        while (tileStartY < endPositionY)
                        {
                            float textureEndY = mTempUVs[y2].y;
                            float tileEndY    = tileStartY + tileSize.y;

                            if (tileEndY > endPositionY)
                            {
                                textureEndY = Mathf.Lerp(textureStartY, textureEndY, (endPositionY - tileStartY) / tileSize.y);
                                tileEndY    = endPositionY;
                            }

                            FillBuffers(startPositionX, endPositionX, tileStartY, tileEndY, textureStartX,
                                        textureEndX, textureStartY, textureEndY, col, verts, uvs, cols);

                            tileStartY += tileSize.y;
                        }
                    }
                    else if ((x == 0 && leftType == AdvancedType.Sliced) || (x == 2 && rightType == AdvancedType.Sliced))
                    {
                        FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y,
                                    mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols);
                    }
                }
                else                 // Corner
                {
                    FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y,
                                mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols);
                }
            }
        }
    }
Example #36
0
    public BetterList <string> GetListOfSprites(string match)
    {
        if (this.mReplacement)
        {
            return(this.mReplacement.GetListOfSprites(match));
        }
        if (string.IsNullOrEmpty(match))
        {
            return(this.GetListOfSprites());
        }
        if (this.mSprites.Count == 0)
        {
            this.Upgrade();
        }
        BetterList <string> betterList = new BetterList <string>();
        int i     = 0;
        int count = this.mSprites.Count;

        while (i < count)
        {
            UISpriteData uISpriteData = this.mSprites[i];
            if (uISpriteData != null && !string.IsNullOrEmpty(uISpriteData.name) && string.Equals(match, uISpriteData.name, StringComparison.OrdinalIgnoreCase))
            {
                betterList.Add(uISpriteData.name);
                return(betterList);
            }
            i++;
        }
        string[] array = match.Split(new char[]
        {
            ' '
        }, StringSplitOptions.RemoveEmptyEntries);
        for (int j = 0; j < array.Length; j++)
        {
            array[j] = array[j].ToLower();
        }
        int k      = 0;
        int count2 = this.mSprites.Count;

        while (k < count2)
        {
            UISpriteData uISpriteData2 = this.mSprites[k];
            if (uISpriteData2 != null && !string.IsNullOrEmpty(uISpriteData2.name))
            {
                string text = uISpriteData2.name.ToLower();
                int    num  = 0;
                for (int l = 0; l < array.Length; l++)
                {
                    if (text.Contains(array[l]))
                    {
                        num++;
                    }
                }
                if (num == array.Length)
                {
                    betterList.Add(uISpriteData2.name);
                }
            }
            k++;
        }
        return(betterList);
    }
Example #37
0
    /// <summary>
    /// Want your own custom sorting logic? Override this function.
    /// </summary>

    protected virtual void Sort(BetterList <Transform> list)
    {
        list.Sort(SortByName);
    }
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
#endif
    {
        int VertStart = verts.size;
        int UVStart   = uvs.size;
        int ColStart  = cols.size;

        base.OnFill(verts, uvs, cols);

        switch (mGradientDirection)
        {
        case GradientDirection.LeftToRight:
            mLerpFunction = fLeftToRight;
            break;

        case GradientDirection.RightToLeft:
            mLerpFunction = fRightToLeft;
            break;

        case GradientDirection.TopToBottom:
            mLerpFunction = fTopToBottom;
            break;

        case GradientDirection.BottomToTop:
            mLerpFunction = fBottomToTop;
            break;

        default:
            mLerpFunction = fLeftToRight;
            break;
        }

        for (int i = VertStart, j = ColStart; i < verts.size; ++i, ++j)
        {
            float f = mLerpFunction(verts[i]);
            cols[j] = Color.Lerp(color, mGradientColor, mCurve.Evaluate(f));
        }
    }
Example #39
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        Event     currentEvent = Event.current;
        EventType type         = currentEvent.type;

        int x = cellPadding, y = cellPadding;
        int width    = Screen.width - cellPadding;
        int spacingX = cellSize + cellPadding;
        int spacingY = spacingX;

        if (mMode == Mode.DetailedMode)
        {
            spacingY += 32;
        }

        GameObject dragged         = draggedObject;
        bool       isDragging      = (dragged != null);
        int        indexUnderMouse = GetCellUnderMouse(spacingX, spacingY);
        Item       selection       = isDragging ? FindItem(dragged) : null;
        string     searchFilter    = NGUISettings.searchField;

        int newTab = mTab;

        GUILayout.BeginHorizontal();
        if (GUILayout.Toggle(newTab == 0, "1", "ButtonLeft"))
        {
            newTab = 0;
        }
        if (GUILayout.Toggle(newTab == 1, "2", "ButtonMid"))
        {
            newTab = 1;
        }
        if (GUILayout.Toggle(newTab == 2, "3", "ButtonMid"))
        {
            newTab = 2;
        }
        if (GUILayout.Toggle(newTab == 3, "4", "ButtonMid"))
        {
            newTab = 3;
        }
        if (GUILayout.Toggle(newTab == 4, "5", "ButtonRight"))
        {
            newTab = 4;
        }
        GUILayout.EndHorizontal();

        if (mTab != newTab)
        {
            Save();
            mTab   = newTab;
            mReset = true;
            NGUISettings.SetInt("NGUI Prefab Tab", mTab);
            Load();
        }

        if (mReset && type == EventType.Repaint)
        {
            mReset = false;
            foreach (Item item in mItems)
            {
                GeneratePreview(item, null);
            }
            RectivateLights();
        }

        // Search field
        GUILayout.BeginHorizontal();
        {
            string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f));

            if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
            {
                after = "";
                GUIUtility.keyboardControl = 0;
            }

            if (searchFilter != after)
            {
                NGUISettings.searchField = after;
                searchFilter             = after;
            }
        }
        GUILayout.EndHorizontal();

        bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40);

        if (type == EventType.MouseDown)
        {
            mMouseIsInside = true;
        }
        else if (type == EventType.MouseDrag)
        {
            mMouseIsInside = true;

            if (indexUnderMouse != -1 && eligibleToDrag)
            {
                // Drag operation begins
                if (draggedObjectIsOurs)
                {
                    DragAndDrop.StartDrag("Prefab Tool");
                }
                currentEvent.Use();
            }
        }
        else if (type == EventType.MouseUp)
        {
            DragAndDrop.PrepareStartDrag();
            mMouseIsInside = false;
            Repaint();
        }
        else if (type == EventType.DragUpdated)
        {
            // Something dragged into the window
            mMouseIsInside = true;
            UpdateVisual();
            currentEvent.Use();
        }
        else if (type == EventType.DragPerform)
        {
            // We've dropped a new object into the window
            if (dragged != null)
            {
                if (selection != null)
                {
                    DestroyTexture(selection);
                    mItems.Remove(selection);
                }

                AddItem(dragged, indexUnderMouse);
                draggedObject = null;
            }
            mMouseIsInside = false;
            currentEvent.Use();
        }
        else if (type == EventType.DragExited || type == EventType.Ignore)
        {
            mMouseIsInside = false;
        }

        // If the mouse is not inside the window, clear the selection and dragged object
        if (!mMouseIsInside)
        {
            selection = null;
            dragged   = null;
        }

        // Create a list of indices, inserting an entry of '-1' underneath the dragged object
        BetterList <int> indices = new BetterList <int>();

        for (int i = 0; i < mItems.size;)
        {
            if (dragged != null && indices.size == indexUnderMouse)
            {
                indices.Add(-1);
            }

            if (mItems[i] != selection)
            {
                if (string.IsNullOrEmpty(searchFilter) ||
                    mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    indices.Add(i);
                }
            }
            ++i;
        }

        // There must always be '-1' (Add/Move slot) present
        if (!indices.Contains(-1))
        {
            indices.Add(-1);
        }

        // We want to start dragging something from within the window
        if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1)
        {
            GUIUtility.keyboardControl = 0;

            if (currentEvent.button == 0 && indexUnderMouse < indices.size)
            {
                int index = indices[indexUnderMouse];

                if (index != -1 && index < mItems.size)
                {
                    selection     = mItems[index];
                    draggedObject = selection.prefab;
                    dragged       = selection.prefab;
                    currentEvent.Use();
                }
            }
        }
        //else if (type == EventType.MouseUp && currentEvent.button == 1 && indexUnderMouse > mItems.size)
        //{
        //    NGUIContextMenu.AddItem("Reset", false, RemoveItem, index);
        //    NGUIContextMenu.Show();
        //}

        // Draw the scroll view with prefabs
        mPos = GUILayout.BeginScrollView(mPos);
        {
            Color normal = new Color(1f, 1f, 1f, 0.5f);

            for (int i = 0; i < indices.size; ++i)
            {
                int  index = indices[i];
                Item ent   = (index != -1) ? mItems[index] : selection;

                if (ent != null && ent.prefab == null)
                {
                    mItems.RemoveAt(index);
                    continue;
                }

                Rect rect  = new Rect(x, y, cellSize, cellSize);
                Rect inner = rect;
                inner.xMin += 2f;
                inner.xMax -= 2f;
                inner.yMin += 2f;
                inner.yMax -= 2f;
                rect.yMax  -= 1f;                // Button seems to be mis-shaped. It's height is larger than its width by a single pixel.

                if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null)))
                {
                    mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add";
                }
                else
                {
                    mContent.tooltip = "";
                }

                //if (ent == selection)
                {
                    GUI.color = normal;
                    NGUIEditorTools.DrawTiledTexture(inner, NGUIEditorTools.backdropTexture);
                }

                GUI.color           = Color.white;
                GUI.backgroundColor = normal;

                if (GUI.Button(rect, mContent, "Button"))
                {
                    if (ent == null || currentEvent.button == 0)
                    {
                        string path = EditorUtility.OpenFilePanel("Add a prefab", NGUISettings.currentPath, "prefab");

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            Item newEnt = CreateItemByPath(path);

                            if (newEnt != null)
                            {
                                mItems.Add(newEnt);
                                Save();
                            }
                        }
                    }
                    else if (currentEvent.button == 1)
                    {
                        NGUIContextMenu.AddItem("Delete", false, RemoveItem, index);
                        NGUIContextMenu.Show();
                    }
                }

                string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", "");

                if (ent != null)
                {
                    if (ent.tex != null)
                    {
                        GUI.DrawTexture(inner, ent.tex);
                    }
                    else if (mMode != Mode.DetailedMode)
                    {
                        GUI.Label(inner, caption, mStyle);
                        caption = "";
                    }
                }
                else
                {
                    GUI.Label(inner, "Add", mStyle);
                }

                if (mMode == Mode.DetailedMode)
                {
                    GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                    GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                    GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, "ProgressBarBack");
                    GUI.contentColor    = Color.white;
                    GUI.backgroundColor = Color.white;
                }

                x += spacingX;

                if (x + spacingX > width)
                {
                    y += spacingY;
                    x  = cellPadding;
                }
            }
            GUILayout.Space(y);
        }
        GUILayout.EndScrollView();

        // Mode
        Mode modeAfter = (Mode)EditorGUILayout.EnumPopup(mMode);

        if (modeAfter != mMode)
        {
            mMode  = modeAfter;
            mReset = true;
            NGUISettings.SetEnum("NGUI Prefab Mode", mMode);
        }
    }
Example #40
0
    /// <summary>
    /// Set the draw call's geometry.
    /// </summary>

    public void Set(BetterList <Vector3> verts, BetterList <Vector3> norms, BetterList <Vector4> tans, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        int count = verts.size;

        // Safety check to ensure we get valid values
        if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0)
        {
            // Cache all components
            if (mFilter == null)
            {
                mFilter = gameObject.GetComponent <MeshFilter>();
            }
            if (mFilter == null)
            {
                mFilter = gameObject.AddComponent <MeshFilter>();
            }
            if (mRen == null)
            {
                mRen = gameObject.GetComponent <MeshRenderer>();
            }

            if (mRen == null)
            {
                mRen = gameObject.AddComponent <MeshRenderer>();
#if UNITY_EDITOR
                mRen.enabled = isActive;
#endif
                UpdateMaterials();
            }
            else if (mMat != null && mMat.mainTexture != mSharedMat.mainTexture)
            {
                UpdateMaterials();
            }

            if (verts.size < 65000)
            {
                int  indexCount     = (count >> 1) * 3;
                bool rebuildIndices = (mIndices == null || mIndices.Length != indexCount);

                // Populate the index buffer
                if (rebuildIndices)
                {
                    // It takes 6 indices to draw a quad of 4 vertices
                    mIndices = new int[indexCount];
                    int index = 0;

                    for (int i = 0; i < count; i += 4)
                    {
                        mIndices[index++] = i;
                        mIndices[index++] = i + 1;
                        mIndices[index++] = i + 2;

                        mIndices[index++] = i + 2;
                        mIndices[index++] = i + 3;
                        mIndices[index++] = i;
                    }
                }

                // Set the mesh values
                Mesh mesh = GetMesh(ref rebuildIndices, verts.size);
                mesh.vertices = verts.ToArray();
                if (norms != null)
                {
                    mesh.normals = norms.ToArray();
                }
                if (tans != null)
                {
                    mesh.tangents = tans.ToArray();
                }
                mesh.uv       = uvs.ToArray();
                mesh.colors32 = cols.ToArray();
                if (rebuildIndices)
                {
                    mesh.triangles = mIndices;
                }
                mesh.RecalculateBounds();
                mFilter.mesh = mesh;
            }
            else
            {
                if (mFilter.mesh != null)
                {
                    mFilter.mesh.Clear();
                }
                Debug.LogError("Too many vertices on one panel: " + verts.size);
            }
        }
        else
        {
            if (mFilter.mesh != null)
            {
                mFilter.mesh.Clear();
            }
            Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count);
        }
    }
Example #41
0
    public virtual void Reposition()
    {
        if (Application.isPlaying && !mInitDone && NGUITools.GetActive(this))
        {
            mReposition = true;
            return;
        }

        if (!mInitDone)
        {
            Init();
        }

        mReposition = false;
        Transform myTrans = transform;

        int x    = 0;
        int y    = 0;
        int maxX = 0;
        int maxY = 0;

        if (sorting != Sorting.None || sorted)
        {
            BetterList <Transform> list = new BetterList <Transform>();

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);
                if (t && (!hideInactive || NGUITools.GetActive(t.gameObject)))
                {
                    list.Add(t);
                }
            }

            if (sorting == Sorting.Alphabetic)
            {
                list.Sort(SortByName);
            }
            else if (sorting == Sorting.Horizontal)
            {
                list.Sort(SortHorizontal);
            }
            else if (sorting == Sorting.Vertical)
            {
                list.Sort(SortVertical);
            }
            else
            {
                Sort(list);
            }

            for (int i = 0, imax = list.size; i < imax; ++i)
            {
                Transform t = list[i];

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float   depth = t.localPosition.z;
                Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                                new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                new Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
                }
                else
                {
                    t.localPosition = pos;
                }

                maxX = Mathf.Max(maxX, x);
                maxY = Mathf.Max(maxY, y);

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }
        else
        {
            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float   depth = t.localPosition.z;
                Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                                new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                new Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
                }
                else
                {
                    t.localPosition = pos;
                }

                maxX = Mathf.Max(maxX, x);
                maxY = Mathf.Max(maxY, y);

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }

        if (keepWithinPanel && mPanel != null)
        {
            mPanel.ConstrainTargetToBounds(myTrans, true);
        }

        if (onReposition != null)
        {
            onReposition();
        }
    }
Example #42
0
 protected void FilledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
 {
     float x = 0f;
     float y = 0f;
     float num3 = 1f;
     float num4 = -1f;
     float xMin = this.mOuterUV.xMin;
     float yMin = this.mOuterUV.yMin;
     float xMax = this.mOuterUV.xMax;
     float yMax = this.mOuterUV.yMax;
     if ((this.mFillDirection == FillDirection.Horizontal) || (this.mFillDirection == FillDirection.Vertical))
     {
         float num9 = (xMax - xMin) * this.mFillAmount;
         float num10 = (yMax - yMin) * this.mFillAmount;
         if (this.fillDirection == FillDirection.Horizontal)
         {
             if (this.mInvert)
             {
                 x = 1f - this.mFillAmount;
                 xMin = xMax - num9;
             }
             else
             {
                 num3 *= this.mFillAmount;
                 xMax = xMin + num9;
             }
         }
         else if (this.fillDirection == FillDirection.Vertical)
         {
             if (this.mInvert)
             {
                 num4 *= this.mFillAmount;
                 yMin = yMax - num10;
             }
             else
             {
                 y = -(1f - this.mFillAmount);
                 yMax = yMin + num10;
             }
         }
     }
     Vector2[] xy = new Vector2[4];
     Vector2[] uv = new Vector2[4];
     xy[0] = new Vector2(num3, y);
     xy[1] = new Vector2(num3, num4);
     xy[2] = new Vector2(x, num4);
     xy[3] = new Vector2(x, y);
     uv[0] = new Vector2(xMax, yMax);
     uv[1] = new Vector2(xMax, yMin);
     uv[2] = new Vector2(xMin, yMin);
     uv[3] = new Vector2(xMin, yMax);
     Color c = base.color;
     c.a *= 255;//base.mPanel.alpha;
     Color32 item = !this.atlas.premultipliedAlpha ? c : NGUITools.ApplyPMA(c);
     if (this.fillDirection == FillDirection.Radial90)
     {
         if (!this.AdjustRadial(xy, uv, this.mFillAmount, this.mInvert))
         {
             return;
         }
     }
     else
     {
         if (this.fillDirection == FillDirection.Radial180)
         {
             Vector2[] v = new Vector2[4];
             Vector2[] vectorArray4 = new Vector2[4];
             for (int j = 0; j < 2; j++)
             {
                 float num12;
                 float num13;
                 v[0] = new Vector2(0f, 0f);
                 v[1] = new Vector2(0f, 1f);
                 v[2] = new Vector2(1f, 1f);
                 v[3] = new Vector2(1f, 0f);
                 vectorArray4[0] = new Vector2(0f, 0f);
                 vectorArray4[1] = new Vector2(0f, 1f);
                 vectorArray4[2] = new Vector2(1f, 1f);
                 vectorArray4[3] = new Vector2(1f, 0f);
                 if (this.mInvert)
                 {
                     if (j > 0)
                     {
                         this.Rotate(v, j);
                         this.Rotate(vectorArray4, j);
                     }
                 }
                 else if (j < 1)
                 {
                     this.Rotate(v, 1 - j);
                     this.Rotate(vectorArray4, 1 - j);
                 }
                 if (j == 1)
                 {
                     num12 = !this.mInvert ? 1f : 0.5f;
                     num13 = !this.mInvert ? 0.5f : 1f;
                 }
                 else
                 {
                     num12 = !this.mInvert ? 0.5f : 1f;
                     num13 = !this.mInvert ? 1f : 0.5f;
                 }
                 v[1].y = Mathf.Lerp(num12, num13, v[1].y);
                 v[2].y = Mathf.Lerp(num12, num13, v[2].y);
                 vectorArray4[1].y = Mathf.Lerp(num12, num13, vectorArray4[1].y);
                 vectorArray4[2].y = Mathf.Lerp(num12, num13, vectorArray4[2].y);
                 float fill = (this.mFillAmount * 2f) - j;
                 bool flag = (j % 2) == 1;
                 if (this.AdjustRadial(v, vectorArray4, fill, !flag))
                 {
                     if (this.mInvert)
                     {
                         flag = !flag;
                     }
                     if (flag)
                     {
                         for (int k = 0; k < 4; k++)
                         {
                             num12 = Mathf.Lerp(xy[0].x, xy[2].x, v[k].x);
                             num13 = Mathf.Lerp(xy[0].y, xy[2].y, v[k].y);
                             float num16 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray4[k].x);
                             float num17 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray4[k].y);
                             verts.Add(new Vector3(num12, num13, 0f));
                             uvs.Add(new Vector2(num16, num17));
                             cols.Add(item);
                         }
                     }
                     else
                     {
                         for (int m = 3; m > -1; m--)
                         {
                             num12 = Mathf.Lerp(xy[0].x, xy[2].x, v[m].x);
                             num13 = Mathf.Lerp(xy[0].y, xy[2].y, v[m].y);
                             float num19 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray4[m].x);
                             float num20 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray4[m].y);
                             verts.Add(new Vector3(num12, num13, 0f));
                             uvs.Add(new Vector2(num19, num20));
                             cols.Add(item);
                         }
                     }
                 }
             }
             return;
         }
         if (this.fillDirection == FillDirection.Radial360)
         {
             float[] numArray = new float[] { 0.5f, 1f, 0f, 0.5f, 0.5f, 1f, 0.5f, 1f, 0f, 0.5f, 0.5f, 1f, 0f, 0.5f, 0f, 0.5f };
             Vector2[] vectorArray5 = new Vector2[4];
             Vector2[] vectorArray6 = new Vector2[4];
             for (int n = 0; n < 4; n++)
             {
                 vectorArray5[0] = new Vector2(0f, 0f);
                 vectorArray5[1] = new Vector2(0f, 1f);
                 vectorArray5[2] = new Vector2(1f, 1f);
                 vectorArray5[3] = new Vector2(1f, 0f);
                 vectorArray6[0] = new Vector2(0f, 0f);
                 vectorArray6[1] = new Vector2(0f, 1f);
                 vectorArray6[2] = new Vector2(1f, 1f);
                 vectorArray6[3] = new Vector2(1f, 0f);
                 if (this.mInvert)
                 {
                     if (n > 0)
                     {
                         this.Rotate(vectorArray5, n);
                         this.Rotate(vectorArray6, n);
                     }
                 }
                 else if (n < 3)
                 {
                     this.Rotate(vectorArray5, 3 - n);
                     this.Rotate(vectorArray6, 3 - n);
                 }
                 for (int num22 = 0; num22 < 4; num22++)
                 {
                     int index = !this.mInvert ? (n * 4) : ((3 - n) * 4);
                     float from = numArray[index];
                     float to = numArray[index + 1];
                     float num26 = numArray[index + 2];
                     float num27 = numArray[index + 3];
                     vectorArray5[num22].x = Mathf.Lerp(from, to, vectorArray5[num22].x);
                     vectorArray5[num22].y = Mathf.Lerp(num26, num27, vectorArray5[num22].y);
                     vectorArray6[num22].x = Mathf.Lerp(from, to, vectorArray6[num22].x);
                     vectorArray6[num22].y = Mathf.Lerp(num26, num27, vectorArray6[num22].y);
                 }
                 float num28 = (this.mFillAmount * 4f) - n;
                 bool flag2 = (n % 2) == 1;
                 if (this.AdjustRadial(vectorArray5, vectorArray6, num28, !flag2))
                 {
                     if (this.mInvert)
                     {
                         flag2 = !flag2;
                     }
                     if (flag2)
                     {
                         for (int num29 = 0; num29 < 4; num29++)
                         {
                             float num30 = Mathf.Lerp(xy[0].x, xy[2].x, vectorArray5[num29].x);
                             float num31 = Mathf.Lerp(xy[0].y, xy[2].y, vectorArray5[num29].y);
                             float num32 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray6[num29].x);
                             float num33 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray6[num29].y);
                             verts.Add(new Vector3(num30, num31, 0f));
                             uvs.Add(new Vector2(num32, num33));
                             cols.Add(item);
                         }
                     }
                     else
                     {
                         for (int num34 = 3; num34 > -1; num34--)
                         {
                             float num35 = Mathf.Lerp(xy[0].x, xy[2].x, vectorArray5[num34].x);
                             float num36 = Mathf.Lerp(xy[0].y, xy[2].y, vectorArray5[num34].y);
                             float num37 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray6[num34].x);
                             float num38 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray6[num34].y);
                             verts.Add(new Vector3(num35, num36, 0f));
                             uvs.Add(new Vector2(num37, num38));
                             cols.Add(item);
                         }
                     }
                 }
             }
             return;
         }
     }
     for (int i = 0; i < 4; i++)
     {
         verts.Add(xy[i]);
         uvs.Add(uv[i]);
         cols.Add(item);
     }
 }
Example #43
0
 protected void TiledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
 {
     Texture mainTexture = this.material.mainTexture;
     if (mainTexture != null)
     {
         Rect mInner = this.mInner;
         if (this.atlas.coordinates == UIAtlas.Coordinates.TexCoords)
         {
             mInner = NGUIMath.ConvertToPixels(mInner, mainTexture.width, mainTexture.height, true);
         }
         Vector2 localScale = base.cachedTransform.localScale;
         float pixelSize = this.atlas.pixelSize;
         float num2 = Mathf.Abs((float)(mInner.width / localScale.x)) * pixelSize;
         float num3 = Mathf.Abs((float)(mInner.height / localScale.y)) * pixelSize;
         if ((num2 < 0.01f) || (num3 < 0.01f))
         {
             Debug.LogWarning("The tiled sprite (" + NGUITools.GetHierarchy(base.gameObject) + ") is too small.\nConsider using a bigger one.");
             num2 = 0.01f;
             num3 = 0.01f;
         }
         Vector2 vector2 = new Vector2(mInner.xMin / ((float)mainTexture.width), mInner.yMin / ((float)mainTexture.height));
         Vector2 vector3 = new Vector2(mInner.xMax / ((float)mainTexture.width), mInner.yMax / ((float)mainTexture.height));
         Vector2 vector4 = vector3;
         Color c = base.color;
         c.a *= 255;//base.mPanel.alpha;
         Color32 item = !this.atlas.premultipliedAlpha ? c : NGUITools.ApplyPMA(c);
         for (float i = 0f; i < 1f; i += num3)
         {
             float x = 0f;
             vector4.x = vector3.x;
             float num6 = i + num3;
             if (num6 > 1f)
             {
                 vector4.y = vector2.y + (((vector3.y - vector2.y) * (1f - i)) / (num6 - i));
                 num6 = 1f;
             }
             while (x < 1f)
             {
                 float num7 = x + num2;
                 if (num7 > 1f)
                 {
                     vector4.x = vector2.x + (((vector3.x - vector2.x) * (1f - x)) / (num7 - x));
                     num7 = 1f;
                 }
                 verts.Add(new Vector3(num7, -i, 0f));
                 verts.Add(new Vector3(num7, -num6, 0f));
                 verts.Add(new Vector3(x, -num6, 0f));
                 verts.Add(new Vector3(x, -i, 0f));
                 uvs.Add(new Vector2(vector4.x, 1f - vector2.y));
                 uvs.Add(new Vector2(vector4.x, 1f - vector4.y));
                 uvs.Add(new Vector2(vector2.x, 1f - vector4.y));
                 uvs.Add(new Vector2(vector2.x, 1f - vector2.y));
                 cols.Add(item);
                 cols.Add(item);
                 cols.Add(item);
                 cols.Add(item);
                 x += num2;
             }
         }
     }
 }
Example #44
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color> cols)
    {
        Texture tex = mainTexture;

        if (tex == null)
        {
            return;
        }

        Rect    outer = new Rect(mRect.x * tex.width, mRect.y * tex.height, tex.width * mRect.width, tex.height * mRect.height);
        Rect    inner = outer;
        Vector4 br    = border;

        inner.xMin += br.x;
        inner.yMin += br.y;
        inner.xMax -= br.z;
        inner.yMax -= br.w;

        float w = 1f / tex.width;
        float h = 1f / tex.height;

        outer.xMin *= w;
        outer.xMax *= w;
        outer.yMin *= h;
        outer.yMax *= h;

        inner.xMin *= w;
        inner.xMax *= w;
        inner.yMin *= h;
        inner.yMax *= h;

        int offset = verts.size;

        Fill(verts, uvs, cols, outer, inner);

        if (onPostFill != null)
        {
            onPostFill(this, offset, verts, uvs, cols);
        }
    }
Example #45
0
    /// <summary>
    /// Tiled sprite fill function.
    /// </summary>

    protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = material.mainTexture;

        if (tex == null)
        {
            return;
        }

        Vector4 dr   = drawingDimensions;
        Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height);

        size *= atlas.pixelSize;

        Color colF = color;

        colF.a = finalAlpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        float x0 = dr.x;
        float y0 = dr.y;

        float u0 = mInnerUV.xMin;
        float v0 = mInnerUV.yMin;

        while (y0 < dr.w)
        {
            x0 = dr.x;
            float y1 = y0 + size.y;
            float v1 = mInnerUV.yMax;

            if (y1 > dr.w)
            {
                v1 = Mathf.Lerp(mInnerUV.yMin, mInnerUV.yMax, (dr.w - y0) / size.y);
                y1 = dr.w;
            }

            while (x0 < dr.z)
            {
                float x1 = x0 + size.x;
                float u1 = mInnerUV.xMax;

                if (x1 > dr.z)
                {
                    u1 = Mathf.Lerp(mInnerUV.xMin, mInnerUV.xMax, (dr.z - x0) / size.x);
                    x1 = dr.z;
                }

                verts.Add(new Vector3(x0, y0));
                verts.Add(new Vector3(x0, y1));
                verts.Add(new Vector3(x1, y1));
                verts.Add(new Vector3(x1, y0));

                uvs.Add(new Vector2(u0, v0));
                uvs.Add(new Vector2(u0, v1));
                uvs.Add(new Vector2(u1, v1));
                uvs.Add(new Vector2(u1, v0));

                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
                cols.Add(col);

                x0 += size.x;
            }
            y0 += size.y;
        }
    }
    /// <summary>
    /// Fill the draw buffers.
    /// </summary>

#if UNITY_3_5_4 || UNITY_3_5_2 || UNITY_3_5_3
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color> cols)
Example #47
0
    /// <summary>
    /// Draw the on-screen selection, knobs, and handle all interaction logic.
    /// </summary>

    public void OnSceneGUI()
    {
        if (!UIWidget.showHandles)
        {
            return;
        }

        mWidget = target as UIWidget;

        Handles.color = mOutlineColor;
        Transform t = mWidget.cachedTransform;

        Event     e    = Event.current;
        int       id   = GUIUtility.GetControlID(s_Hash, FocusType.Passive);
        EventType type = e.GetTypeForControl(id);

        Vector3[] corners = NGUIMath.CalculateWidgetCorners(mWidget);
        Handles.DrawLine(corners[0], corners[1]);
        Handles.DrawLine(corners[1], corners[2]);
        Handles.DrawLine(corners[2], corners[3]);
        Handles.DrawLine(corners[0], corners[3]);

        Vector3[] worldPos = new Vector3[8];

        worldPos[0] = corners[0];
        worldPos[1] = corners[1];
        worldPos[2] = corners[2];
        worldPos[3] = corners[3];

        worldPos[4] = (corners[0] + corners[1]) * 0.5f;
        worldPos[5] = (corners[1] + corners[2]) * 0.5f;
        worldPos[6] = (corners[2] + corners[3]) * 0.5f;
        worldPos[7] = (corners[0] + corners[3]) * 0.5f;

        Vector2[] screenPos = new Vector2[8];
        for (int i = 0; i < 8; ++i)
        {
            screenPos[i] = HandleUtility.WorldToGUIPoint(worldPos[i]);
        }

        Bounds b = new Bounds(screenPos[0], Vector3.zero);

        for (int i = 1; i < 8; ++i)
        {
            b.Encapsulate(screenPos[i]);
        }

        // Time to figure out what kind of action is underneath the mouse
        Action actionUnderMouse = mAction;

        UIWidget.Pivot pivotUnderMouse = UIWidget.Pivot.Center;

        if (actionUnderMouse == Action.None)
        {
            int   index = 0;
            float dist  = GetScreenDistance(worldPos, e.mousePosition, out index);

            if (mWidget.showResizeHandles && dist < 10f)
            {
                pivotUnderMouse  = mPivots[index];
                actionUnderMouse = Action.Scale;
            }
            else if (e.modifiers == 0 && SceneViewDistanceToRectangle(corners, e.mousePosition) == 0f)
            {
                actionUnderMouse = Action.Move;
            }
            else if (dist < 30f)
            {
                actionUnderMouse = Action.Rotate;
            }
        }

        // Change the mouse cursor to a more appropriate one
#if !UNITY_3_5
        {
            Vector2 min = b.min;
            Vector2 max = b.max;

            min.x -= 30f;
            max.x += 30f;
            min.y -= 30f;
            max.y += 30f;

            Rect rect = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);

            if (actionUnderMouse == Action.Rotate)
            {
                SetCursorRect(rect, MouseCursor.RotateArrow);
            }
            else if (actionUnderMouse == Action.Move)
            {
                SetCursorRect(rect, MouseCursor.MoveArrow);
            }
            else if (mWidget.showResizeHandles && actionUnderMouse == Action.Scale)
            {
                SetCursorRect(rect, MouseCursor.ScaleArrow);
            }
            else
            {
                SetCursorRect(rect, MouseCursor.Arrow);
            }
        }
#endif

        switch (type)
        {
        case EventType.Repaint:
        {
            if (mWidget.showResizeHandles)
            {
                Handles.BeginGUI();
                {
                    for (int i = 0; i < 8; ++i)
                    {
                        DrawKnob(worldPos[i], mWidget.pivot == mPivots[i], id);
                    }
                }
                Handles.EndGUI();
            }
        }
        break;

        case EventType.MouseDown:
        {
            mStartMouse     = e.mousePosition;
            mAllowSelection = true;

            if (e.button == 1)
            {
                if (e.modifiers == 0)
                {
                    GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                    e.Use();
                }
            }
            else if (e.button == 0 && actionUnderMouse != Action.None && Raycast(corners, out mStartDrag))
            {
                mStartPos             = t.position;
                mStartRot             = t.localRotation.eulerAngles;
                mStartDir             = mStartDrag - t.position;
                mStartScale           = t.localScale;
                mDragPivot            = pivotUnderMouse;
                mActionUnderMouse     = actionUnderMouse;
                GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                e.Use();
            }
        }
        break;

        case EventType.MouseDrag:
        {
            // Prevent selection once the drag operation begins
            bool dragStarted = (e.mousePosition - mStartMouse).magnitude > 3f;
            if (dragStarted)
            {
                mAllowSelection = false;
            }

            if (GUIUtility.hotControl == id)
            {
                e.Use();

                if (mAction != Action.None || mActionUnderMouse != Action.None)
                {
                    Vector3 pos;

                    if (Raycast(corners, out pos))
                    {
                        if (mAction == Action.None && mActionUnderMouse != Action.None)
                        {
                            // Wait until the mouse moves by more than a few pixels
                            if (dragStarted)
                            {
                                if (mActionUnderMouse == Action.Move)
                                {
                                    mStartPos = t.position;
                                    NGUIEditorTools.RegisterUndo("Move widget", t);
                                }
                                else if (mActionUnderMouse == Action.Rotate)
                                {
                                    mStartRot = t.localRotation.eulerAngles;
                                    mStartDir = mStartDrag - t.position;
                                    NGUIEditorTools.RegisterUndo("Rotate widget", t);
                                }
                                else if (mActionUnderMouse == Action.Scale)
                                {
                                    mStartPos   = t.localPosition;
                                    mStartScale = t.localScale;
                                    mDragPivot  = pivotUnderMouse;
                                    NGUIEditorTools.RegisterUndo("Scale widget", t);
                                }
                                mAction = actionUnderMouse;
                            }
                        }

                        if (mAction != Action.None)
                        {
                            if (mAction == Action.Move)
                            {
                                t.position      = mStartPos + (pos - mStartDrag);
                                pos             = t.localPosition;
                                pos.x           = Mathf.RoundToInt(pos.x);
                                pos.y           = Mathf.RoundToInt(pos.y);
                                t.localPosition = pos;
                            }
                            else if (mAction == Action.Rotate)
                            {
                                Vector3 dir   = pos - t.position;
                                float   angle = Vector3.Angle(mStartDir, dir);

                                if (angle > 0f)
                                {
                                    float dot = Vector3.Dot(Vector3.Cross(mStartDir, dir), t.forward);
                                    if (dot < 0f)
                                    {
                                        angle = -angle;
                                    }
                                    angle = mStartRot.z + angle;
                                    if (e.modifiers != EventModifiers.Shift)
                                    {
                                        angle = Mathf.Round(angle / 15f) * 15f;
                                    }
                                    else
                                    {
                                        angle = Mathf.Round(angle);
                                    }
                                    t.localRotation = Quaternion.Euler(mStartRot.x, mStartRot.y, angle);
                                }
                            }
                            else if (mAction == Action.Scale)
                            {
                                // World-space delta since the drag started
                                Vector3 delta = pos - mStartDrag;

                                // Adjust the widget's position and scale based on the delta, restricted by the pivot
                                AdjustPosAndScale(mWidget, mStartPos, mStartScale, delta, mDragPivot);
                            }
                        }
                    }
                }
            }
        }
        break;

        case EventType.MouseUp:
        {
            if (GUIUtility.hotControl == id)
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;

                if (e.button < 2)
                {
                    bool handled = false;

                    if (e.button == 1)
                    {
                        // Right-click: Select the widget below
                        SelectWidget(mWidget, e.mousePosition, false);
                        handled = true;
                    }
                    else if (mAction == Action.None)
                    {
                        if (mAllowSelection)
                        {
                            // Left-click: Select the widget above
                            SelectWidget(mWidget, e.mousePosition, true);
                            handled = true;
                        }
                    }
                    else
                    {
                        // Finished dragging something
                        mAction           = Action.None;
                        mActionUnderMouse = Action.None;
                        Vector3 pos   = t.localPosition;
                        Vector3 scale = t.localScale;

                        if (mWidget.pixelPerfectAfterResize)
                        {
                            t.localPosition = pos;
                            t.localScale    = scale;

                            mWidget.MakePixelPerfect();
                        }
                        else
                        {
                            pos.x   = Mathf.Round(pos.x);
                            pos.y   = Mathf.Round(pos.y);
                            scale.x = Mathf.Round(scale.x);
                            scale.y = Mathf.Round(scale.y);

                            t.localPosition = pos;
                            t.localScale    = scale;
                        }
                        handled = true;
                    }

                    if (handled)
                    {
                        mActionUnderMouse = Action.None;
                        mAction           = Action.None;
                        e.Use();
                    }
                }
            }
            else if (mAllowSelection)
            {
                BetterList <UIWidget> widgets = SceneViewRaycast(mWidget.panel, e.mousePosition);
                if (widgets.size > 0)
                {
                    Selection.activeGameObject = widgets[0].gameObject;
                }
            }
            mAllowSelection = true;
        }
        break;

        case EventType.KeyDown:
        {
            if (e.keyCode == KeyCode.UpArrow)
            {
                Vector3 pos = t.localPosition;
                pos.y          += 1f;
                t.localPosition = pos;
                e.Use();
            }
            else if (e.keyCode == KeyCode.DownArrow)
            {
                Vector3 pos = t.localPosition;
                pos.y          -= 1f;
                t.localPosition = pos;
                e.Use();
            }
            else if (e.keyCode == KeyCode.LeftArrow)
            {
                Vector3 pos = t.localPosition;
                pos.x          -= 1f;
                t.localPosition = pos;
                e.Use();
            }
            else if (e.keyCode == KeyCode.RightArrow)
            {
                Vector3 pos = t.localPosition;
                pos.x          += 1f;
                t.localPosition = pos;
                e.Use();
            }
            else if (e.keyCode == KeyCode.Escape)
            {
                if (GUIUtility.hotControl == id)
                {
                    if (mAction != Action.None)
                    {
                        if (mAction == Action.Move)
                        {
                            t.position = mStartPos;
                        }
                        else if (mAction == Action.Rotate)
                        {
                            t.localRotation = Quaternion.Euler(mStartRot);
                        }
                        else if (mAction == Action.Scale)
                        {
                            t.position   = mStartPos;
                            t.localScale = mStartScale;
                        }
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;

                    mActionUnderMouse = Action.None;
                    mAction           = Action.None;
                    e.Use();
                }
                else
                {
                    Selection.activeGameObject = null;
                }
            }
        }
        break;
        }
    }
    /// <summary>
    /// Tiled sprite fill function.
    /// </summary>

    protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = material.mainTexture;

        if (tex == null)
        {
            return;
        }

        Vector4 v = drawingDimensions;
        Vector4 u;

        if (mFlip == Flip.Horizontally || mFlip == Flip.Both)
        {
            u.x = mInnerUV.xMax;
            u.z = mInnerUV.xMin;
        }
        else
        {
            u.x = mInnerUV.xMin;
            u.z = mInnerUV.xMax;
        }

        if (mFlip == Flip.Vertically || mFlip == Flip.Both)
        {
            u.y = mInnerUV.yMax;
            u.w = mInnerUV.yMin;
        }
        else
        {
            u.y = mInnerUV.yMin;
            u.w = mInnerUV.yMax;
        }

        Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height);

        size *= atlas.pixelSize;

        Color colF = color;

        colF.a = finalAlpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        float x0 = v.x;
        float y0 = v.y;

        float u0 = u.x;
        float v0 = u.y;

        while (y0 < v.w)
        {
            x0 = v.x;
            float y1 = y0 + size.y;
            float v1 = u.w;

            if (y1 > v.w)
            {
                v1 = Mathf.Lerp(u.y, u.w, (v.w - y0) / size.y);
                y1 = v.w;
            }

            while (x0 < v.z)
            {
                float x1 = x0 + size.x;
                float u1 = u.z;

                if (x1 > v.z)
                {
                    u1 = Mathf.Lerp(u.x, u.z, (v.z - x0) / size.x);
                    x1 = v.z;
                }

                verts.Add(new Vector3(x0, y0));
                verts.Add(new Vector3(x0, y1));
                verts.Add(new Vector3(x1, y1));
                verts.Add(new Vector3(x1, y0));

                uvs.Add(new Vector2(u0, v0));
                uvs.Add(new Vector2(u0, v1));
                uvs.Add(new Vector2(u1, v1));
                uvs.Add(new Vector2(u1, v0));

                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
                cols.Add(col);

                x0 += size.x;
            }
            y0 += size.y;
        }
    }
Example #49
0
    /// <summary>
    /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1.
    /// </summary>

    protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (!mSprite.hasBorder)
        {
            SimpleFill(verts, uvs, cols);
            return;
        }

        Vector4 dr = drawingDimensions;
        Vector4 br = border * atlas.pixelSize;

        mTempPos[0].x = dr.x;
        mTempPos[0].y = dr.y;
        mTempPos[3].x = dr.z;
        mTempPos[3].y = dr.w;

        mTempPos[1].x = mTempPos[0].x + br.x;
        mTempPos[1].y = mTempPos[0].y + br.y;
        mTempPos[2].x = mTempPos[3].x - br.z;
        mTempPos[2].y = mTempPos[3].y - br.w;

        mTempUVs[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin);
        mTempUVs[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin);
        mTempUVs[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax);
        mTempUVs[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax);

        Color colF = color;

        colF.a = finalAlpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        for (int x = 0; x < 3; ++x)
        {
            int x2 = x + 1;

            for (int y = 0; y < 3; ++y)
            {
                if (centerType == AdvancedType.Invisible && x == 1 && y == 1)
                {
                    continue;
                }

                int y2 = y + 1;

                verts.Add(new Vector3(mTempPos[x].x, mTempPos[y].y));
                verts.Add(new Vector3(mTempPos[x].x, mTempPos[y2].y));
                verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y2].y));
                verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y].y));

                uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y].y));
                uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y2].y));
                uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y2].y));
                uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y].y));

                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
            }
        }
    }
    /// <summary>
    /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1.
    /// </summary>

    protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mSprite == null)
        {
            return;
        }

        if (!mSprite.hasBorder)
        {
            SimpleFill(verts, uvs, cols);
            return;
        }

        Vector4 br = border * atlas.pixelSize;
        Vector2 po = pivotOffset;

        float fw = 1f / mWidth;
        float fh = 1f / mHeight;

        Vector2[] v = new Vector2[4];
        v[0] = new Vector2(mSprite.paddingLeft * fw, mSprite.paddingBottom * fh);
        v[3] = new Vector2(1f - mSprite.paddingRight * fw, 1f - mSprite.paddingTop * fh);

        v[1].x = v[0].x + fw * br.x;
        v[1].y = v[0].y + fh * br.y;
        v[2].x = v[3].x - fw * br.z;
        v[2].y = v[3].y - fh * br.w;

        for (int i = 0; i < 4; ++i)
        {
            v[i].x -= po.x;
            v[i].y -= po.y;
            v[i].x *= mWidth;
            v[i].y *= mHeight;
        }

        Vector2[] u = new Vector2[4];
        u[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin);
        u[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin);
        u[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax);
        u[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax);

        Color colF = color;

        colF.a *= mPanel.alpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        for (int x = 0; x < 3; ++x)
        {
            int x2 = x + 1;

            for (int y = 0; y < 3; ++y)
            {
                if (!mFillCenter && x == 1 && y == 1)
                {
                    continue;
                }

                int y2 = y + 1;

                verts.Add(new Vector3(v[x].x, v[y].y));
                verts.Add(new Vector3(v[x].x, v[y2].y));
                verts.Add(new Vector3(v[x2].x, v[y2].y));
                verts.Add(new Vector3(v[x2].x, v[y].y));

                uvs.Add(new Vector2(u[x].x, u[y].y));
                uvs.Add(new Vector2(u[x].x, u[y2].y));
                uvs.Add(new Vector2(u[x2].x, u[y2].y));
                uvs.Add(new Vector2(u[x2].x, u[y].y));

                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
            }
        }
    }
Example #51
0
    /// <summary>
    /// Virtual function called by the UIPanel that fills the buffers.
    /// </summary>

    virtual public void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        // Call this in your derived classes:
        //if (onPostFill != null)
        //	onPostFill(this, verts.size, verts, uvs, cols);
    }
    /// <summary>
    /// Tiled sprite fill function.
    /// </summary>

    protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = material.mainTexture;

        if (tex == null)
        {
            return;
        }

        Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height);

        size *= atlas.pixelSize;

        float width  = Mathf.Abs(size.x / mWidth);
        float height = Mathf.Abs(size.y / mHeight);

        if (width * height < 0.0001f)
        {
            width  = 0.01f;
            height = 0.01f;
        }

        Color colF = color;

        colF.a *= mPanel.alpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        Vector2 pv      = pivotOffset;
        Vector2 min     = new Vector2(mInnerUV.xMin, mInnerUV.yMin);
        Vector2 max     = new Vector2(mInnerUV.xMax, mInnerUV.yMax);
        Vector2 clipped = max;
        float   y1      = 0f;

        while (y1 < 1f)
        {
            float x1 = 0f;
            clipped.x = max.x;
            float y2 = y1 + height;

            if (y2 > 1f)
            {
                clipped.y = min.y + (max.y - min.y) * (1f - y1) / (y2 - y1);
                y2        = 1f;
            }

            while (x1 < 1f)
            {
                float x2 = x1 + width;

                if (x2 > 1f)
                {
                    clipped.x = min.x + (max.x - min.x) * (1f - x1) / (x2 - x1);
                    x2        = 1f;
                }

                // Convert from normalized (0-1 range) coordinates to pixels
                float fx1 = (x1 - pv.x) * mWidth;
                float fx2 = (x2 - pv.x) * mWidth;
                float fy1 = (y1 - pv.y) * mHeight;
                float fy2 = (y2 - pv.y) * mHeight;

                verts.Add(new Vector3(fx1, fy1));
                verts.Add(new Vector3(fx1, fy2));
                verts.Add(new Vector3(fx2, fy2));
                verts.Add(new Vector3(fx2, fy1));

                uvs.Add(new Vector2(min.x, min.y));
                uvs.Add(new Vector2(min.x, clipped.y));
                uvs.Add(new Vector2(clipped.x, clipped.y));
                uvs.Add(new Vector2(clipped.x, min.y));

                cols.Add(col);
                cols.Add(col);
                cols.Add(col);
                cols.Add(col);

                x1 += width;
            }
            y1 += height;
        }
    }
    /// <summary>
    /// Filled sprite fill function.
    /// </summary>

    protected void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mFillAmount < 0.001f)
        {
            return;
        }

        Color colF = color;

        colF.a *= mPanel.alpha;
        Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF;

        Vector2[] xy = new Vector2[4];
        Vector2[] uv = new Vector2[4];

        Vector4 v = drawingDimensions;

        float tx0 = mOuterUV.xMin;
        float ty0 = mOuterUV.yMin;
        float tx1 = mOuterUV.xMax;
        float ty1 = mOuterUV.yMax;

        // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely
        if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical)
        {
            if (mFillDirection == FillDirection.Horizontal)
            {
                float fill = (tx1 - tx0) * mFillAmount;

                if (mInvert)
                {
                    v.x = v.z - (v.z - v.x) * mFillAmount;
                    tx0 = tx1 - fill;
                }
                else
                {
                    v.z = v.x + (v.z - v.x) * mFillAmount;
                    tx1 = tx0 + fill;
                }
            }
            else if (mFillDirection == FillDirection.Vertical)
            {
                float fill = (ty1 - ty0) * mFillAmount;

                if (mInvert)
                {
                    v.y = v.w - (v.w - v.y) * mFillAmount;
                    ty0 = ty1 - fill;
                }
                else
                {
                    v.w = v.y + (v.w - v.y) * mFillAmount;
                    ty1 = ty0 + fill;
                }
            }
        }

        xy[0] = new Vector2(v.x, v.y);
        xy[1] = new Vector2(v.x, v.w);
        xy[2] = new Vector2(v.z, v.w);
        xy[3] = new Vector2(v.z, v.y);

        uv[0] = new Vector2(tx0, ty0);
        uv[1] = new Vector2(tx0, ty1);
        uv[2] = new Vector2(tx1, ty1);
        uv[3] = new Vector2(tx1, ty0);

        if (mFillAmount < 1f)
        {
            if (mFillDirection == FillDirection.Radial90)
            {
                if (RadialCut(xy, uv, mFillAmount, mInvert, 0))
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        verts.Add(xy[i]);
                        uvs.Add(uv[i]);
                        cols.Add(col);
                    }
                }
                return;
            }

            if (mFillDirection == FillDirection.Radial180)
            {
                for (int side = 0; side < 2; ++side)
                {
                    float fx0, fx1, fy0, fy1;

                    fy0 = 0f;
                    fy1 = 1f;

                    if (side == 0)
                    {
                        fx0 = 0f; fx1 = 0.5f;
                    }
                    else
                    {
                        fx0 = 0.5f; fx1 = 1f;
                    }

                    xy[0].x = Mathf.Lerp(v.x, v.z, fx0);
                    xy[1].x = xy[0].x;
                    xy[2].x = Mathf.Lerp(v.x, v.z, fx1);
                    xy[3].x = xy[2].x;

                    xy[0].y = Mathf.Lerp(v.y, v.w, fy0);
                    xy[1].y = Mathf.Lerp(v.y, v.w, fy1);
                    xy[2].y = xy[1].y;
                    xy[3].y = xy[0].y;

                    uv[0].x = Mathf.Lerp(tx0, tx1, fx0);
                    uv[1].x = uv[0].x;
                    uv[2].x = Mathf.Lerp(tx0, tx1, fx1);
                    uv[3].x = uv[2].x;

                    uv[0].y = Mathf.Lerp(ty0, ty1, fy0);
                    uv[1].y = Mathf.Lerp(ty0, ty1, fy1);
                    uv[2].y = uv[1].y;
                    uv[3].y = uv[0].y;

                    float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side);

                    if (RadialCut(xy, uv, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4)))
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            verts.Add(xy[i]);
                            uvs.Add(uv[i]);
                            cols.Add(col);
                        }
                    }
                }
                return;
            }

            if (mFillDirection == FillDirection.Radial360)
            {
                for (int corner = 0; corner < 4; ++corner)
                {
                    float fx0, fx1, fy0, fy1;

                    if (corner < 2)
                    {
                        fx0 = 0f; fx1 = 0.5f;
                    }
                    else
                    {
                        fx0 = 0.5f; fx1 = 1f;
                    }

                    if (corner == 0 || corner == 3)
                    {
                        fy0 = 0f; fy1 = 0.5f;
                    }
                    else
                    {
                        fy0 = 0.5f; fy1 = 1f;
                    }

                    xy[0].x = Mathf.Lerp(v.x, v.z, fx0);
                    xy[1].x = xy[0].x;
                    xy[2].x = Mathf.Lerp(v.x, v.z, fx1);
                    xy[3].x = xy[2].x;

                    xy[0].y = Mathf.Lerp(v.y, v.w, fy0);
                    xy[1].y = Mathf.Lerp(v.y, v.w, fy1);
                    xy[2].y = xy[1].y;
                    xy[3].y = xy[0].y;

                    uv[0].x = Mathf.Lerp(tx0, tx1, fx0);
                    uv[1].x = uv[0].x;
                    uv[2].x = Mathf.Lerp(tx0, tx1, fx1);
                    uv[3].x = uv[2].x;

                    uv[0].y = Mathf.Lerp(ty0, ty1, fy0);
                    uv[1].y = Mathf.Lerp(ty0, ty1, fy1);
                    uv[2].y = uv[1].y;
                    uv[3].y = uv[0].y;

                    float val = mInvert ?
                                mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) :
                                mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4));

                    if (RadialCut(xy, uv, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4)))
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            verts.Add(xy[i]);
                            uvs.Add(uv[i]);
                            cols.Add(col);
                        }
                    }
                }
                return;
            }
        }

        // Fill the buffer with the quad for the sprite
        for (int i = 0; i < 4; ++i)
        {
            verts.Add(xy[i]);
            uvs.Add(uv[i]);
            cols.Add(col);
        }
    }
Example #54
0
    //判断屏幕内是否有怪
    void AutoTest()
    {
        GameObject player = CharacterManager.player;

        if (player == null || hideArrowScene())
        {
            HideArrow();
            return;
        }
        if (ClientNetMgr.GetSingle().IsConnect())//如果有网络连接
        {
            if (SceneManager.GetActiveScene().name == GameLibrary.Moba1V1_TP1)
            {
                //GameObject[] ats = CharacterManager.instance.autos;
                //if (ats.Length > 0 && Vector3.Distance(player.transform.position, ats[ats.Length - 1].transform.position) > 3f)
                //{
                //    ShowArrow(ats[ats.Length - 1].transform);
                //}
            }
            else
            {
                if (SceneBaseManager.instance != null)
                {
                    List <SpawnMonster>         spawns      = SceneBaseManager.instance.spwanList;
                    BetterList <CharacterState> enemyList   = SceneBaseManager.instance.enemy;
                    BetterList <Transform>      targetTrans = new BetterList <Transform>();
                    for (int m = 0; m < spawns.Count; m++)
                    {
                        if (!spawns[m].spawnOver)
                        {
                            targetTrans.Add(spawns[m].transform);
                        }
                    }
                    for (int m = 0; m < enemyList.size; m++)
                    {
                        if (enemyList[m] != null)
                        {
                            targetTrans.Add(enemyList[m].transform);
                        }
                    }

                    if (targetTrans.size <= 0)
                    {
                        return;
                    }
                    for (int i = 0; i < targetTrans.size; i++)
                    {
                        Vector2 screenPos = Camera.main.WorldToScreenPoint(targetTrans[i].position);
                        if ((screenPos.x > 0 && screenPos.x < Screen.width) && (screenPos.y > 0 && screenPos.y < Screen.height))
                        {
                            HideArrow();
                            break;
                        }
                        else
                        {
                            mindis = Vector3.Distance(player.transform.position, targetTrans[0].position);
                            for (int j = 0; j < targetTrans.size; j++)
                            {
                                dis = Vector3.Distance(player.transform.position, targetTrans[j].position);
                                if (mindis >= dis)
                                {
                                    mindis  = dis;
                                    monster = targetTrans[j];
                                }
                            }
                            ShowArrow(monster);
                        }
                    }
                }
            }
        }
    }
Example #55
0
 public void WriteToBuffers(BetterList <Vector3> v, BetterList <Vector2> u, BetterList <Color32> c, BetterList <Vector3> n, BetterList <Vector4> t)
 {
     this.geometry.WriteToBuffers(v, u, c, n, t);
 }
Example #56
0
    /// <summary>
    /// Convenience function that retrieves a list of all sprite names that contain the specified phrase
    /// </summary>

    public BetterList <string> GetListOfSprites(string match)
    {
        if (mReplacement)
        {
            return(mReplacement.GetListOfSprites(match));
        }
        if (string.IsNullOrEmpty(match))
        {
            return(GetListOfSprites());
        }

        if (mSprites.Count == 0)
        {
            Upgrade();
        }
        BetterList <string> list = new BetterList <string>();

        // First try to find an exact match
        for (int i = 0, imax = mSprites.Count; i < imax; ++i)
        {
            UISpriteData s = mSprites[i];

            if (s != null && !string.IsNullOrEmpty(s.name) && string.Equals(match, s.name, StringComparison.OrdinalIgnoreCase))
            {
                list.Add(s.name);
                return(list);
            }
        }

        // No exact match found? Split up the search into space-separated components.
        string[] keywords = match.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i < keywords.Length; ++i)
        {
            keywords[i] = keywords[i].ToLower();
        }

        // Try to find all sprites where all keywords are present
        for (int i = 0, imax = mSprites.Count; i < imax; ++i)
        {
            UISpriteData s = mSprites[i];

            if (s != null && !string.IsNullOrEmpty(s.name))
            {
                string tl      = s.name.ToLower();
                int    matches = 0;

                for (int b = 0; b < keywords.Length; ++b)
                {
                    if (tl.Contains(keywords[b]))
                    {
                        ++matches;
                    }
                }
                if (matches == keywords.Length)
                {
                    list.Add(s.name);
                }
            }
        }
        return(list);
    }
Example #57
0
 public virtual void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
 {
 }
    /// <summary>
    /// Virtual function called by the UIScreen that fills the buffers.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Texture tex = mainTexture;

        if (tex != null)
        {
            if (mSprite == null)
            {
                mSprite = atlas.GetSprite(spriteName);
            }
            if (mSprite == null)
            {
                return;
            }

            mOuterUV.Set(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
            mInnerUV.Set(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop,
                         mSprite.width - mSprite.borderLeft - mSprite.borderRight,
                         mSprite.height - mSprite.borderBottom - mSprite.borderTop);

            mOuterUV = NGUIMath.ConvertToTexCoords(mOuterUV, tex.width, tex.height);
            mInnerUV = NGUIMath.ConvertToTexCoords(mInnerUV, tex.width, tex.height);
        }

        switch (type)
        {
        case Type.Simple:
            SimpleFill(verts, uvs, cols);
            break;

        case Type.Sliced:
            SlicedFill(verts, uvs, cols);
            break;

        case Type.Filled:
            FilledFill(verts, uvs, cols);
            break;

        case Type.Tiled:
            TiledFill(verts, uvs, cols);
            break;
        }
    }
Example #59
0
    protected void SlicedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
    {
        if (this.mOuterUV == this.mInnerUV)
        {
            this.SimpleFill(verts, uvs, cols);
        }
        else
        {
            Vector2[] vectorArray = new Vector2[4];
            Vector2[] vectorArray2 = new Vector2[4];
            Texture mainTexture = this.mainTexture;
            vectorArray[0] = Vector2.zero;
            vectorArray[1] = Vector2.zero;
            vectorArray[2] = new Vector2(1f, -1f);
            vectorArray[3] = new Vector2(1f, -1f);
            if (mainTexture == null)
            {
                for (int j = 0; j < 4; j++)
                {
                    vectorArray2[j] = Vector2.zero;
                }
            }
            else
            {
                float pixelSize = this.atlas.pixelSize;
                float num2 = (this.mInnerUV.xMin - this.mOuterUV.xMin) * pixelSize;
                float num3 = (this.mOuterUV.xMax - this.mInnerUV.xMax) * pixelSize;
                float num4 = (this.mInnerUV.yMax - this.mOuterUV.yMax) * pixelSize;
                float num5 = (this.mOuterUV.yMin - this.mInnerUV.yMin) * pixelSize;
                Vector3 localScale = base.cachedTransform.localScale;
                localScale.x = Mathf.Max(0f, localScale.x);
                localScale.y = Mathf.Max(0f, localScale.y);
                Vector2 vector2 = new Vector2(localScale.x / ((float)mainTexture.width), localScale.y / ((float)mainTexture.height));
                Vector2 vector3 = new Vector2(num2 / vector2.x, num4 / vector2.y);
                Vector2 vector4 = new Vector2(num3 / vector2.x, num5 / vector2.y);
                UIWidget.Pivot pivot = base.pivot;
                switch (pivot)
                {
                    case UIWidget.Pivot.Right:
                    case UIWidget.Pivot.TopRight:
                    case UIWidget.Pivot.BottomRight:
                        vectorArray[0].x = Mathf.Min((float)0f, (float)(1f - (vector4.x + vector3.x)));
                        vectorArray[1].x = vectorArray[0].x + vector3.x;
                        vectorArray[2].x = vectorArray[0].x + Mathf.Max(vector3.x, 1f - vector4.x);
                        vectorArray[3].x = vectorArray[0].x + Mathf.Max((float)(vector3.x + vector4.x), (float)1f);
                        break;

                    default:
                        vectorArray[1].x = vector3.x;
                        vectorArray[2].x = Mathf.Max(vector3.x, 1f - vector4.x);
                        vectorArray[3].x = Mathf.Max((float)(vector3.x + vector4.x), (float)1f);
                        break;
                }
                switch (pivot)
                {
                    case UIWidget.Pivot.Bottom:
                    case UIWidget.Pivot.BottomLeft:
                    case UIWidget.Pivot.BottomRight:
                        vectorArray[0].y = Mathf.Max((float)0f, (float)(-1f - (vector4.y + vector3.y)));
                        vectorArray[1].y = vectorArray[0].y + vector3.y;
                        vectorArray[2].y = vectorArray[0].y + Mathf.Min(vector3.y, -1f - vector4.y);
                        vectorArray[3].y = vectorArray[0].y + Mathf.Min((float)(vector3.y + vector4.y), (float)-1f);
                        break;

                    default:
                        vectorArray[1].y = vector3.y;
                        vectorArray[2].y = Mathf.Min(vector3.y, -1f - vector4.y);
                        vectorArray[3].y = Mathf.Min((float)(vector3.y + vector4.y), (float)-1f);
                        break;
                }
                vectorArray2[0] = new Vector2(this.mOuterUV.xMin, this.mOuterUV.yMax);
                vectorArray2[1] = new Vector2(this.mInnerUV.xMin, this.mInnerUV.yMax);
                vectorArray2[2] = new Vector2(this.mInnerUV.xMax, this.mInnerUV.yMin);
                vectorArray2[3] = new Vector2(this.mOuterUV.xMax, this.mOuterUV.yMin);
            }
            Color c = base.color;
            c.a *= 255;//base.mPanel.alpha;
            Color32 item = !this.atlas.premultipliedAlpha ? c : NGUITools.ApplyPMA(c);
            for (int i = 0; i < 3; i++)
            {
                int index = i + 1;
                for (int k = 0; k < 3; k++)
                {
                    if ((this.mFillCenter || (i != 1)) || (k != 1))
                    {
                        int num10 = k + 1;
                        verts.Add(new Vector3(vectorArray[index].x, vectorArray[k].y, 0f));
                        verts.Add(new Vector3(vectorArray[index].x, vectorArray[num10].y, 0f));
                        verts.Add(new Vector3(vectorArray[i].x, vectorArray[num10].y, 0f));
                        verts.Add(new Vector3(vectorArray[i].x, vectorArray[k].y, 0f));
                        uvs.Add(new Vector2(vectorArray2[index].x, vectorArray2[k].y));
                        uvs.Add(new Vector2(vectorArray2[index].x, vectorArray2[num10].y));
                        uvs.Add(new Vector2(vectorArray2[i].x, vectorArray2[num10].y));
                        uvs.Add(new Vector2(vectorArray2[i].x, vectorArray2[k].y));
                        cols.Add(item);
                        cols.Add(item);
                        cols.Add(item);
                        cols.Add(item);
                    }
                }
            }
        }
    }
Example #60
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);

        if (mAtlas == null)
        {
            GUILayout.Label("No Atlas selected.", "LODLevelNotifyText");
        }
        else
        {
            bool close = false;
            GUILayout.Label(mAtlas.name + " Sprites", "LODLevelNotifyText");
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            GUILayout.Space(84f);

            string before = NGUISettings.partialSprite;
            string after  = EditorGUILayout.TextField("", before, "SearchTextField");
            NGUISettings.partialSprite = after;

            if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
            {
                NGUISettings.partialSprite = "";
                GUIUtility.keyboardControl = 0;
            }
            GUILayout.Space(84f);
            GUILayout.EndHorizontal();

            Texture2D tex = mAtlas.texture as Texture2D;

            if (tex == null)
            {
                GUILayout.Label("The atlas doesn't have a texture to work with");
                return;
            }

            BetterList <string> sprites = mAtlas.GetListOfSprites(NGUISettings.partialSprite);

            float size    = 80f;
            float padded  = size + 10f;
            int   columns = Mathf.FloorToInt(Screen.width / padded);
            if (columns < 1)
            {
                columns = 1;
            }

            int  offset = 0;
            Rect rect   = new Rect(10f, 0, size, size);

            GUILayout.Space(10f);
            mPos = GUILayout.BeginScrollView(mPos);

            while (offset < sprites.size)
            {
                GUILayout.BeginHorizontal();
                {
                    int col = 0;
                    rect.x = 10f;

                    for (; offset < sprites.size; ++offset)
                    {
                        UIAtlas.Sprite sprite = mAtlas.GetSprite(sprites[offset]);
                        if (sprite == null)
                        {
                            continue;
                        }

                        // Button comes first
                        if (GUI.Button(rect, ""))
                        {
                            float delta = Time.realtimeSinceStartup - mClickTime;
                            mClickTime = Time.realtimeSinceStartup;

                            if (spriteName != sprite.name)
                            {
                                if (mSprite != null)
                                {
                                    NGUIEditorTools.RegisterUndo("Atlas Selection", mSprite);
                                    mSprite.spriteName = sprite.name;
                                    mSprite.MakePixelPerfect();
                                    EditorUtility.SetDirty(mSprite.gameObject);
                                }

                                if (mCallback != null)
                                {
                                    mName = sprite.name;
                                    mCallback(sprite.name);
                                }
                            }
                            else if (delta < 0.5f)
                            {
                                close = true;
                            }
                        }

                        if (Event.current.type == EventType.Repaint)
                        {
                            // On top of the button we have a checkboard grid
                            NGUIEditorTools.DrawTiledTexture(rect, NGUIEditorTools.backdropTexture);

                            Rect uv = sprite.outer;
                            if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                            {
                                uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height);
                            }

                            // Calculate the texture's scale that's needed to display the sprite in the clipped area
                            float scaleX = rect.width / uv.width;
                            float scaleY = rect.height / uv.height;

                            // Stretch the sprite so that it will appear proper
                            float aspect   = (scaleY / scaleX) / ((float)tex.height / tex.width);
                            Rect  clipRect = rect;

                            if (aspect != 1f)
                            {
                                if (aspect < 1f)
                                {
                                    // The sprite is taller than it is wider
                                    float padding = size * (1f - aspect) * 0.5f;
                                    clipRect.xMin += padding;
                                    clipRect.xMax -= padding;
                                }
                                else
                                {
                                    // The sprite is wider than it is taller
                                    float padding = size * (1f - 1f / aspect) * 0.5f;
                                    clipRect.yMin += padding;
                                    clipRect.yMax -= padding;
                                }
                            }

                            GUI.DrawTextureWithTexCoords(clipRect, tex, uv);

                            // Draw the selection
                            if (spriteName == sprite.name)
                            {
                                NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                            }
                        }

                        if (++col >= columns)
                        {
                            ++offset;
                            break;
                        }
                        rect.x += padded;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(padded);
                rect.y += padded;
            }
            GUILayout.EndScrollView();
            if (close)
            {
                Close();
            }
        }
    }