浏览代码

Add laser that stops at walls

/develop/battlefoodcollector
Ervin Teng 4 年前
当前提交
6f510af8
共有 8 个文件被更改,包括 351 次插入844 次删除
  1. 902
      Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/BattleFoodArea.prefab
  2. 13
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/BattleFoodAgent.cs
  3. 97
      Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.mat
  4. 8
      Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.mat.meta
  5. 31
      Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.png
  6. 88
      Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.png.meta
  7. 45
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/Laser.cs
  8. 11
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/Laser.cs.meta

902
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/BattleFoodArea.prefab
文件差异内容过多而无法显示
查看文件

13
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/BattleFoodAgent.cs


public Material badMaterial;
public Material goodMaterial;
public Material frozenMaterial;
public GameObject myLaser;
Laser m_Laser;
public bool contribute;
public bool useVectorObs;
[Tooltip("Use only the frozen flag in vector observations. If \"Use Vector Obs\" " +

agent = this,
};
areaScoring.playerStates.Add(playerState);
m_Laser = GetComponentInChildren<Laser>();
m_Laser.maxLength = m_LaserLength * 25f;
}
public override void CollectObservations(VectorSensor sensor)

if (m_Shoot)
{
var myTransform = transform;
myLaser.transform.localScale = new Vector3(1f, 1f, m_LaserLength);
//m_Laser.transform.localScale = new Vector3(1f, 1f, m_LaserLength);
m_Laser.isFired = true;
var rayDir = 25.0f * myTransform.forward;
Debug.DrawRay(myTransform.position, rayDir, Color.red, 0f, true);
RaycastHit hit;

}
else
{
myLaser.transform.localScale = new Vector3(0f, 0f, 0f);
// m_Laser.transform.localScale = new Vector3(0f, 0f, 0f);
m_Laser.isFired = false;
}
}

Unsatiate();
m_Shoot = false;
m_AgentRb.velocity = Vector3.zero;
myLaser.transform.localScale = new Vector3(0f, 0f, 0f);
m_Laser.isFired = false;
//m_Laser.transform.localScale = new Vector3(0f, 0f, 0f);
transform.position = new Vector3(Random.Range(-m_MyArea.range, m_MyArea.range),
2f, Random.Range(-m_MyArea.range, m_MyArea.range))
+ area.transform.position;

97
Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: laser
m_Shader: {fileID: 211, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: EFFECT_BUMP _ALPHABLEND_ON _EMISSION
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: e452f4aeface5494994b159409f31869, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BlendOp: 0
- _BumpScale: 1
- _CameraFadingEnabled: 0
- _CameraFarFadeDistance: 2
- _CameraNearFadeDistance: 1
- _ColorMode: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DistortionBlend: 0.066
- _DistortionEnabled: 1
- _DistortionStrength: 0.2
- _DistortionStrengthScaled: 0.020000001
- _DstBlend: 1
- _EmissionEnabled: 1
- _FlipbookMode: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _LightingEnabled: 0
- _Metallic: 0
- _Mode: 4
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 0
- _SoftParticlesFarFadeDistance: 1
- _SoftParticlesNearFadeDistance: 0
- _SpecularHighlights: 1
- _SrcBlend: 5
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 1, g: 0, b: 0.7160444, a: 0.6784314}
- _ColorAddSubDiff: {r: -1, g: 0, b: 0, a: 0}
- _EmissionColor: {r: 1, g: 0.042452812, b: 0.8528484, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}

8
Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.mat.meta


fileFormatVersion: 2
guid: 0915314b3292143389c9fe13d159b471
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

31
Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 4.0 KiB

88
Project/Assets/ML-Agents/Examples/FoodCollector/Materials/laser.png.meta


fileFormatVersion: 2
guid: fc6d09884e42d4e8396f2f861500fe49
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: -1
mipBias: -100
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

45
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/Laser.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Laser : MonoBehaviour
{
public bool isFired;
public float maxLength = 25f;
public float width = 0.5f;
public bool animate = false;
LineRenderer laserRenderer;
// Start is called before the first frame update
void Start()
{
laserRenderer = GetComponentInChildren<LineRenderer>();
laserRenderer.SetWidth(width, width);
laserRenderer.material.SetTextureScale("_MainTex", new Vector2(0.05f, 1.0f));
}
// Update is called once per frame
void FixedUpdate()
{
if (isFired)
{
if (animate)
{
laserRenderer.material.SetTextureOffset("_MainTex", new Vector2(-3 * Time.time, 0.0f));
}
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, maxLength))
{
laserRenderer.SetPosition(1, new Vector3(0f, 0f, hit.distance / transform.lossyScale.z));
}
else
{
laserRenderer.SetPosition(1, new Vector3(0f, 0f, maxLength / transform.lossyScale.z));
}
}
else
{
laserRenderer.SetPosition(1, new Vector3(0f, 0f, 0f));
}
}
}

11
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/Laser.cs.meta


fileFormatVersion: 2
guid: d79d84b010fe54a73ad5010ce52370da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存