找回密码
 立即注册
查看: 5786|回复: 97

[源码] 非常简单的小地图包源码

[复制链接]
发表于 2012-11-26 12:10 | 显示全部楼层 |阅读模式
资源信息 Asset Information
资源名称: 非常简单的小地图包源码 (发帖教程)
版本: (版本)
资源等级: 1
资源格式: .rar (链接失效请点击帖子右下方举报通知管理员)
资源大小: 1MB (默认:MB)
下载地址: 站内下载 (购买积分)
点击查看原图
美丽分割线

[code=javascript]@script ExecuteInEditMode()
// radar! by PsychicParrot, adapted from a Blitz3d script found in the public domain online somewhere ..

//Modified by Dastardly Banana to add radar size configuration, different colors for enemies in different states (patrolling or chasing), ability to move radar to either one of 9 preset locations or to custom location.

//some lines are particular to our AI script, you will need to change "EnemyAINew" to the name of your AI script, and change "isChasing" to the boolean within that AI script that is true when the enemy is active/can see the player/is chasing the player.

var blip : Texture; // texture to use when the enemy isn't chasing
var blipChasing : Texture; //When Chasing
var radarBG : Texture;

var centerObject : Transform;
var mapScale = 0.3;
var mapSizePercent = 15;

var checkAIscript : boolean = true;
var enemyTag = "Enemy";

enum radarLocationValues {topLeft, topCenter, topRight, middleLeft, middleCenter, middleRight, bottomLeft, bottomCenter, bottomRight, custom}
var radarLocation : radarLocationValues = radarLocationValues.bottomLeft;

private var mapWidth : float;
private var mapHeight : float;
private var mapCenter : Vector2;
var mapCenterCustom : Vector2;

function Start () {
  setMapLocation();  
}

function OnGUI () {
//  GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 600.0, Screen.height / 450.0, 1));

   // Draw player blip (centerObject)
   bX=centerObject.transform.position.x * mapScale;
   bY=centerObject.transform.position.z * mapScale;  
   GUI.DrawTexture(Rect(mapCenter.x - mapWidth/2,mapCenter.y-mapHeight/2,mapWidth,mapHeight),radarBG);
  
  // Draw blips for Enemies
  DrawBlipsForEnemies();
  
}
  
function drawBlip(go,aTexture){
  
  centerPos=centerObject.position;
  extPos=go.transform.position;
  
  // first we need to get the distance of the enemy from the player
  dist=Vector3.Distance(centerPos,extPos);
   
  dx=centerPos.x-extPos.x; // how far to the side of the player is the enemy?
  dz=centerPos.z-extPos.z; // how far in front or behind the player is the enemy?
  
  // what's the angle to turn to face the enemy - compensating for the player's turning?
  deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
  
  // just basic trigonometry to find the point x,y (enemy's location) given the angle deltay
  bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
  bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
  
  bX=bX*mapScale; // scales down the x-coordinate so that the plot stays within our radar
  bY=bY*mapScale; // scales down the y-coordinate so that the plot stays within our radar
  
  if(dist<=mapWidth*.5/mapScale){
    // this is the diameter of our largest radar circle
     GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,4,4),aTexture);

  }

}

function DrawBlipsForEnemies(){
  //You will need to replace isChasing with a variable from your AI script that is true when         the enemy is chasing the player, or doing watever you want it to be doing when it is red on       the radar.
  
  //You will need to replace "EnemyAINew with the name of your AI script
  
    // Find all game objects tagged Enemy
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag(enemyTag);

    var distance = Mathf.Infinity;
    var position = transform.position;

    // Iterate through them and call drawBlip function
    for (var go : GameObject in gos)  {
          var blipChoice : Texture = blip;
            if(checkAIscript){
          var aiScript : EnemyAI = go.GetComponent("EnemyAI");
        if(aiScript.isChasing)
            blipChoice = blipChasing;
      }
    drawBlip(go,blipChoice);
    }

}

function setMapLocation () {
  mapWidth = Screen.width*mapSizePercent/100.0;
  mapHeight = mapWidth;

  //sets mapCenter based on enum selection
  if(radarLocation == radarLocationValues.topLeft){
    mapCenter = Vector2(mapWidth/2, mapHeight/2);
  } else if(radarLocation == radarLocationValues.topCenter){
    mapCenter = Vector2(Screen.width/2, mapHeight/2);
  } else if(radarLocation == radarLocationValues.topRight){
    mapCenter = Vector2(Screen.width-mapWidth/2, mapHeight/2);
  } else if(radarLocation == radarLocationValues.middleLeft){
    mapCenter = Vector2(mapWidth/2, Screen.height/2);
  } else if(radarLocation == radarLocationValues.middleCenter){
    mapCenter = Vector2(Screen.width/2, Screen.height/2);
  } else if(radarLocation == radarLocationValues.middleRight){
    mapCenter = Vector2(Screen.width-mapWidth/2, Screen.height/2);
  } else if(radarLocation == radarLocationValues.bottomLeft){
    mapCenter = Vector2(mapWidth/2, Screen.height - mapHeight/2);
  } else if(radarLocation == radarLocationValues.bottomCenter){
    mapCenter = Vector2(Screen.width/2, Screen.height - mapHeight/2);
  } else if(radarLocation == radarLocationValues.bottomRight){
    mapCenter = Vector2(Screen.width-mapWidth/2, Screen.height - mapHeight/2);
  } else if(radarLocation == radarLocationValues.custom){
    mapCenter = mapCenterCustom;
  }
  
} [/code]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2012-11-26 15:01 | 显示全部楼层
看看,虽然早就知道了
发表于 2013-3-5 12:36 | 显示全部楼层
{:5_427:}{:5_427:}{:5_427:}
发表于 2013-3-18 09:07 | 显示全部楼层
有  C#版吗
发表于 2013-3-31 16:36 | 显示全部楼层
好像的确很简单的啊
发表于 2013-4-8 10:42 | 显示全部楼层
很不错,谢谢楼主分享!!
发表于 2013-5-2 17:39 | 显示全部楼层
下来看看 谢谢分享!
发表于 2013-5-6 00:48 | 显示全部楼层
谢谢楼主,学习下
发表于 2013-10-29 16:18 | 显示全部楼层

感谢楼主的无私分享!{:soso__11402694654016840197_7:}
发表于 2013-10-30 09:58 | 显示全部楼层
小白对这里的算法不懂能介绍下算法吗
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-3 13:24 , Processed in 0.755403 second(s), 32 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表