随机时间创建车辆修改TODO

master
GamerHJD 3 years ago
parent 0733aff366
commit ceecebd962

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WebConnectSample : MonoBehaviour
{
public Text recTxt;
private void Awake()
{
//注册接收方法
EduCoderTool.WebConnecter.Singleton.dataHandle += ReceiveWebMsg;
}
//接收从平台发送过来的数据
void ReceiveWebMsg(string data)
{
Debug.Log("ReceiveWebMsg:" + data);
recTxt.text = data;
}
//提交成绩一共有3个方法这里展示了常用的提交分数的方法
public void ButtonClick()
{
EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true, 90);
}
}

@ -0,0 +1,105 @@

using UnityEngine;
using System;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace EduCoderTool
{
/*
* web
* @author lz
**/
public class WebConnecter : MonoBehaviour
{
private static WebConnecter instance = null;
/// <summary>
/// 单例
/// </summary>
public static WebConnecter Singleton
{
get
{
if(instance == null)
{
instance = GameObject.FindObjectOfType<WebConnecter>();
if(instance == null)
{
GameObject go = new GameObject("WebConnecter");
instance = go.AddComponent<WebConnecter>();
}
}
return instance;
}
}
//引用jslib的方法
[DllImport("__Internal")]
private static extern void SendMsgToWeb(string str);
//接收数据
public Action<string> dataHandle;
void Awake()
{
if(instance == null)
{
instance = this;
}else
{
Destroy(gameObject);
}
}
/// <summary>
/// 接收web端发送数据
/// </summary>
/// <param name="jsonStr"></param>
public void RecData(string jsonStr)
{
dataHandle?.Invoke(jsonStr);
}
/// <summary>
/// 发送数据到web端
/// </summary>
/// <param name="data"></param>
public void SendDataToWeb(string data)
{
Debug.LogFormat(">>>>>> unity send web data{0}",data);
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
SendMsgToWeb(data);
}
}
public void SendResultToWeb(bool success)
{
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("GameState", success ? "Success" : "Fail");
data.Add("Data", "");
string json = JsonConvert.SerializeObject(data);
SendDataToWeb(json);
}
public void SendResultToWeb(bool success, double score)
{
Dictionary<string, object> data = new Dictionary<string, object>();
data.Add("GameState", success ? "Success" : "Fail");
data.Add("Data", score);
string json = JsonConvert.SerializeObject(data);
SendDataToWeb(json);
}
}
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System">
<type fullname="System.ComponentModel.TypeConverter" preserve="all" />
<!-- <namespace fullname="System.ComponentModel" preserve="all" /> -->
</assembly>
</linker>

@ -0,0 +1,174 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class JsonNetSample : MonoBehaviour
{
public Text Output;
void Start()
{
Output.text = "Start!\n\n";
TestJson();
SerailizeJson();
DeserializeJson();
LinqToJson();
JsonPath();
WriteLine("\nDone!");
}
void WriteLine(string msg)
{
Output.text = Output.text + msg + "\n";
}
public class Product
{
public string Name;
public DateTime ExpiryDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public decimal Price;
public string[] Sizes;
public override bool Equals(object obj)
{
if (obj is Product)
{
Product p = (Product)obj;
return (p.Name == Name && p.ExpiryDate == ExpiryDate && p.Price == Price);
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return (Name ?? string.Empty).GetHashCode();
}
}
[System.Serializable]
public class CharacterListItem
{
public int Id { get; set; }
public string Name { get; set; }
public int Level { get; set; }
public string Class { get; set; }
public string Sex { get; set; }
}
void TestJson()
{
WriteLine("* TestJson");
var json = "{\"Id\":51, \"Name\":\"padre\", \"Level\":0, \"Class\":\"Vampire\", \"Sex\":\"F\"}";
var c = JsonConvert.DeserializeObject<CharacterListItem>(json);
WriteLine(c.Id + " " + c.Name);
}
void SerailizeJson()
{
WriteLine("* SerailizeJson");
Product product = new Product();
product.Name = "Apple";
product.ExpiryDate = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };
string json = JsonConvert.SerializeObject(product);
WriteLine(json);
}
public class Movie
{
public string Name { get; set; }
public string Description { get; set; }
public string Classification { get; set; }
public string Studio { get; set; }
public DateTime? ReleaseDate { get; set; }
public List<string> ReleaseCountries { get; set; }
}
void DeserializeJson()
{
WriteLine("* DeserializeJson");
string json = @"{
'Name': 'Bad Boys',
'ReleaseDate': '1995-4-7T00:00:00',
'Genres': [
'Action',
'Comedy'
]
}";
Movie m = JsonConvert.DeserializeObject<Movie>(json);
string name = m.Name;
WriteLine(name);
}
void LinqToJson()
{
WriteLine("* LinqToJson");
JArray array = new JArray();
array.Add("Manual text");
array.Add(new DateTime(2000, 5, 23));
JObject o = new JObject();
o["MyArray"] = array;
string json = o.ToString();
WriteLine(json);
}
private void JsonPath()
{
WriteLine("* JsonPath");
var o = JObject.Parse(@"{
'Stores': [
'Lambton Quay',
'Willis Street'
],
'Manufacturers': [
{
'Name': 'Acme Co',
'Products': [
{
'Name': 'Anvil',
'Price': 50
}
]
},
{
'Name': 'Contoso',
'Products': [
{
'Name': 'Elbow Grease',
'Price': 99.95
},
{
'Name': 'Headlight Fluid',
'Price': 4
}
]
}
]
}");
JToken acme = o.SelectToken("$.Manufacturers[?(@.Name == 'Acme Co')]");
WriteLine(acme.ToString());
IEnumerable<JToken> pricyProducts = o.SelectTokens("$..Products[?(@.Price >= 50)].Name");
foreach (var item in pricyProducts)
{
WriteLine(item.ToString());
}
}
}

@ -0,0 +1,469 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
m_ObjectHideFlags: 0
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_GIWorkflowMode: 1
m_LightmapsMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 3
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AOMaxDistance: 1
m_Padding: 2
m_CompAOExponent: 0
m_LightmapParameters: {fileID: 0}
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherRayCount: 1024
m_ReflectionCompression: 2
m_LightingDataAsset: {fileID: 0}
m_RuntimeCPUUsage: 25
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
accuratePlacement: 0
minRegionArea: 2
cellSize: 0.16666667
manualCellSize: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &17972762
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 17972763}
- 114: {fileID: 17972764}
m_Layer: 0
m_Name: _SceneObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &17972763
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 17972762}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!114 &17972764
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 17972762}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f30dac2bcee81e4c8d946311b78cad6, type: 3}
m_Name:
m_EditorClassIdentifier:
Output: {fileID: 383421098}
--- !u!1 &383421096
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 224: {fileID: 383421097}
- 222: {fileID: 383421099}
- 114: {fileID: 383421098}
- 114: {fileID: 383421100}
m_Layer: 5
m_Name: Output
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &383421097
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 383421096}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 2126236432}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &383421098
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 383421096}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 12
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Output
--- !u!222 &383421099
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 383421096}
--- !u!114 &383421100
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 383421096}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dcb53c957d1aa0e4e90719924cc27bdc, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &613318430
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 613318435}
- 20: {fileID: 613318434}
- 92: {fileID: 613318433}
- 124: {fileID: 613318432}
- 81: {fileID: 613318431}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &613318431
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613318430}
m_Enabled: 1
--- !u!124 &613318432
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613318430}
m_Enabled: 1
--- !u!92 &613318433
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613318430}
m_Enabled: 1
--- !u!20 &613318434
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613318430}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!4 &613318435
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613318430}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!1 &1098611478
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1098611482}
- 114: {fileID: 1098611481}
- 114: {fileID: 1098611480}
- 114: {fileID: 1098611479}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1098611479
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1098611478}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1997211142, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ForceModuleActive: 0
--- !u!114 &1098611480
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1098611478}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &1098611481
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1098611478}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!4 &1098611482
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1098611478}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
--- !u!1 &2126236428
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 224: {fileID: 2126236432}
- 223: {fileID: 2126236431}
- 114: {fileID: 2126236430}
- 114: {fileID: 2126236429}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2126236429
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2126236428}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &2126236430
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2126236428}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &2126236431
Canvas:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2126236428}
m_Enabled: 1
serializedVersion: 2
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &2126236432
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2126236428}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 383421097}
m_Father: {fileID: 0}
m_RootOrder: 3
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}

Binary file not shown.

@ -0,0 +1,6 @@
mergeInto(LibraryManager.library, {
SendMsgToWeb: function (str) {
SendToWeb(Pointer_stringify(str));
},
});

@ -496,9 +496,9 @@ GameObject:
m_Component:
- component: {fileID: 5940721742220947037}
- component: {fileID: 1317834824}
- component: {fileID: 2997252462601936660}
- component: {fileID: 4806489167474073388}
- component: {fileID: 3733720769268392713}
- component: {fileID: 7591998529861248307}
- component: {fileID: 3545319385294605599}
m_Layer: 0
m_Name: Car_1
m_TagString: Car
@ -537,11 +537,11 @@ NavMeshAgent:
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 30
m_Speed: 20
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 1000
m_StoppingDistance: 0
m_AngularSpeed: 240
m_StoppingDistance: 0.5
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
@ -549,19 +549,6 @@ NavMeshAgent:
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!65 &2997252462601936660
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5940721742220849789}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 3.5188322, y: 1, z: 8.888192}
m_Center: {x: 0.2594161, y: 0.74, z: 6.434096}
--- !u!54 &4806489167474073388
Rigidbody:
m_ObjectHideFlags: 0
@ -574,11 +561,27 @@ Rigidbody:
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!65 &3733720769268392713
--- !u!114 &7591998529861248307
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5940721742220849789}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 03d716b4a7b9eab4e80362dd8f99826f, type: 3}
m_Name:
m_EditorClassIdentifier:
dirveState: 0
drivetime: 0
carId: 0
FrontCar: {fileID: 0}
--- !u!65 &3545319385294605599
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -589,8 +592,8 @@ BoxCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1.7861338, y: 2.6640887, z: 5.044007}
m_Center: {x: 0.39306688, y: 1.3077829, z: -1.2198503}
m_Size: {x: 1.9986902, y: 2.5110102, z: 4.475459}
m_Center: {x: 0.042270362, y: 1.2448773, z: -0.6377603}
--- !u!1 &5940721742220849791
GameObject:
m_ObjectHideFlags: 0

@ -301,8 +301,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0d93344fc2790284596792db22128688, type: 3}
m_Name:
m_EditorClassIdentifier:
carList:
carTypeList:
- {fileID: 5940721742220849789, guid: bbdc5196bcc157d41aba8cb142fcab97, type: 3}
CarID: 0
--- !u!114 &1209346
MonoBehaviour:
m_ObjectHideFlags: 0
@ -315,6 +316,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 79dc71e0c891d124e92cbab5841bb6ee, type: 3}
m_Name:
m_EditorClassIdentifier:
timer: 0
carSys: {fileID: 0}
roadSys: {fileID: 0}
infoWnd: {fileID: 1153381226}
@ -22975,7 +22977,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 349456147}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -511.4, y: 0, z: 396.3}
m_LocalPosition: {x: -506.3, y: 0, z: 391}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1887045569}
@ -65301,7 +65303,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 974038968}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -756.7, y: 0, z: 362.47}
m_LocalPosition: {x: -751.5, y: 0, z: 362.47}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1887045569}
@ -108179,7 +108181,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1631646058}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -746.2, y: 0, z: 376.1}
m_LocalPosition: {x: -746.2, y: 0, z: 374.4}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1887045569}
@ -135837,7 +135839,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1976475614}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -757.19, y: 0, z: 368.88}
m_LocalPosition: {x: -753.7, y: 0, z: 368.88}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1887045569}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Const
{
//行车安全距离
public static float SafeDistance = 12f;
//安全检测开始时间
public static float SafeCheckTime = 2f;
//车辆转弯速度
public static float CarTurnSpeed = 5f;
//刷车最小/最大时间
public static int RefreshCarminTime = 3;
public static int RefreshCarmaxTime = 11;
/// <summary>
/// 索引法随机
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <returns></returns>
public static int[] GetIndexRandomNum(int minValue, int maxValue)
{
System.Random random = new System.Random();
int sum = Mathf.Abs(maxValue - minValue);//计算数组范围
int site = sum;//设置索引范围
int[] index = new int[sum];
int[] result = new int[sum];
int temp = 0;
for (int i = minValue; i < maxValue; i++)
{
index[temp] = i;
temp++;
}
for (int i = 0; i < sum; i++)
{
int id = random.Next(0, site - 1);
result[i] = index[id];
index[id] = index[site - 1];//因id随机到的数已经获取到了用最后的一个数来替换它
site--;//缩小索引范围
}
return result;
}
}

@ -4,6 +4,9 @@ using UnityEngine;
public class GameRoot : MonoBehaviour
{
public PETimer pt;
public float timer = 0;
public static GameRoot Instance = null;
[HideInInspector]
public CarSys carSys;
@ -24,11 +27,21 @@ public class GameRoot : MonoBehaviour
roadSys = GetComponent<RoadSys>();
roadSys.Init();
pt = new PETimer();
}
private void Update()
{
carSys.CreatCar(1);//每n秒随机出发点创建汽车
pt.Update();
carSys.CreatCar();//每n秒随机出发点创建汽车
roadSys.RoadStateUpdate(3);//每n秒检测路段状态
}
}

@ -14,8 +14,14 @@ public class CarSys : MonoBehaviour
//计时器
private float timer = 0f;
//车辆种类列表
public GameObject[] carList;
public GameObject[] carTypeList;
//已生成车辆列表
//public List<GameObject> carList=new List<GameObject>(200);
[HideInInspector]
public Dictionary<int, GameObject> carList = new Dictionary<int, GameObject>();
//
public int CarID = 0;
private bool canCreat = true;
//移动点列表
private Dictionary<string, Transform> MoveList = new Dictionary<string, Transform>();
@ -61,7 +67,7 @@ public class CarSys : MonoBehaviour
Transform moveListParent = null;
MoveList.TryGetValue(lineName,out moveListParent);
Drive drive = agent.GetComponent<Drive>();
if (moveListParent != null)
{
Transform[] moveList=new Transform[moveListParent.childCount];
@ -69,27 +75,55 @@ public class CarSys : MonoBehaviour
for (int i = 0; i < moveListParent.childCount; i++)
{
moveList[i] = moveListParent.GetChild(i);
//路径方向
Vector3 Dir = (moveList[i].transform.position - drive.transform.position).normalized;
if (moveList[i] != null)
{
float t = 0;
//向移动列表支点移动
agent.speed = 20;
agent.SetDestination(moveList[i].position);
//携程检测距离与路况
while (true)
{
//*********************//
//**********重要***********//
yield return new WaitForSeconds(0.02f);
float distance = Vector3.Distance(agent.transform.position, moveList[i].position);
drive.drivetime += Time.deltaTime;
//前方车辆安全距离检测
if (drive.drivetime > Const.SafeCheckTime)
{
if(distance <= 40f)
drive.isnormalDrive = CheckFrontCar(drive) ? false : true;
}
if(drive.isnormalDrive == false)
{
agent.speed = 10;
agent.velocity = Vector3.zero;
continue;
}
if (distance <= 0.4f) {
float distance = Vector3.Distance(agent.transform.position, moveList[i].position);
//终点检测
if (distance <= 0.4f)
{
agent.velocity= Vector3.zero;
t = 0;
break;
}
//弯道减速
if (distance <= 20f&&distance>0.4f)
{
drive.dirveState = DriveState.Turn;
agent.velocity = Dir* 15;
}
else
{
drive.dirveState = DriveState.Line;
t += Time.deltaTime * Const.CarTurnSpeed;
agent.velocity = Vector3.Lerp(Vector3.zero,Dir*20,t);
}
}
@ -98,6 +132,7 @@ public class CarSys : MonoBehaviour
}
//回收车辆
carList.Remove(drive.carId);
Destroy(agent.gameObject);
GameRoot.Instance.infoWnd.SetCarText(-1);
}
@ -107,38 +142,110 @@ public class CarSys : MonoBehaviour
}
//汽车生成函数
public void CreatCar(float time)
{
//计时
timer += Time.deltaTime;
if (timer < time)
public IEnumerator RandomTimeCreatCar(float time,Transform parent)
{
return;
if (timer < time) {
canCreat = false;
}
else
{
canCreat = true;
timer = 0;
}
//随机获取出生点
Transform parent = null;
int pointIndex= Random.Range(1, BornList.Count);
BornList.TryGetValue("0" + pointIndex.ToString(),out parent);
//随机创建车辆种类
if (parent != null)
{
int carIndex = Random.Range(0, carList.Length-1);
if (canCreat == false) yield break;
//Debug.Log(time);
yield return new WaitForSeconds(time);
// 随机创建车辆种类
int carIndex = Random.Range(0, carTypeList.Length - 1);
//实例化车辆
GameObject car = GameObject.Instantiate(carList[carIndex],parent.position,Quaternion.identity,parent);
GameObject car = GameObject.Instantiate(carTypeList[carIndex], parent.position, Quaternion.identity, parent);
car.transform.localEulerAngles = parent.localEulerAngles;
//car驾驶类赋值
Drive drive = car.GetComponent<Drive>();
drive.carId = CarID;
carList.Add(CarID, drive.gameObject);
CarID++;
if (drive.carId != 0)
{
GameObject go = null;
carList.TryGetValue(drive.carId - 1, out go);
drive.FrontCar = go;
}
//统计数量更新
GameRoot.Instance.infoWnd.SetCarText(1);//+1
//执行寻路AI
NavMeshAgent agent = car.GetComponent<NavMeshAgent>();
if (agent != null)
{
StartCoroutine(CarMove(parent.name,agent));
StartCoroutine(CarMove(parent.name, agent));
}
}
int temp = 0;
//汽车生成函数
public void CreatCar()
{
//计时
timer += Time.deltaTime;
//随机获取出生点
Transform parent = null;
int pointIndex= Random.Range(1, BornList.Count);
BornList.TryGetValue("0" + pointIndex.ToString(),out parent);
//创建车辆
if (parent != null)
{
int t = Random.Range(Const.RefreshCarminTime,Const.RefreshCarmaxTime);
if (t == temp) return;
temp = t;
StartCoroutine(RandomTimeCreatCar(t,parent));
}
}
//检测前方车辆
public bool CheckFrontCar(Drive drive)
{
if (drive.FrontCar==null) return false;
if (Vector3.Distance(drive.transform.position, drive.FrontCar.transform.position) < Const.SafeDistance)
{
return true;
}
return false;
#region MyRegion
//for (int i = 0; i < carList.Count; i++)
//{
// Vector3 target = carList[i].transform.position;
// Vector3 dir = target - drive.transform.position;
// drive.dot = Vector3.Dot(drive.transform.forward.normalized,dir.normalized);
// //判断是否前方有小于安全距离的车辆
// if (Vector3.Dot(drive.transform.forward.normalized, dir.normalized) > Mathf.Cos(Mathf.PI/6) && Vector3.Distance(target, drive.transform.position) <= Const.SafeDistance)
// {
// Debug.Log(drive.gameObject.name);
// return true;
// }
// else
// {
// continue;
// }
//}
//return false;
#endregion
}
}

@ -78,15 +78,15 @@ public class RoadSys : MonoBehaviour
{
int numble = item.Value;//监控的车辆数量
if (numble >= 0 && numble <= 6)//绿色状态
if (numble >= 0 && numble <= 5)//绿色状态
{
state_object.GetComponent<MeshRenderer>().material.color = Color.green;
}
else if(numble > 6 && numble <= 12)//黄色状态
else if(numble > 5 && numble <= 10)//黄色状态
{
state_object.GetComponent<MeshRenderer>().material.color = Color.yellow;
}
else if (numble > 12 )//红色拥堵
else if (numble > 10 )//红色拥堵
{
state_object.GetComponent<MeshRenderer>().material.color = Color.red;
}

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum DriveState
{
Line = 0,
Turn
}
public class Drive : MonoBehaviour
{
public bool isnormalDrive = true;
public DriveState dirveState = DriveState.Line;
[HideInInspector]
public float drivetime = 0f;
public int carId = 0;
public GameObject FrontCar=null;
}

@ -1,29 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DriveState : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
Debug.Log("1");
}
private void OnTriggerExit(Collider other)
{
}
}

@ -0,0 +1,47 @@
/****************************************************
EntityBase.cs
Plane
: 1785275942@qq.com
2019/03/19 6:40
*****************************************************/
using System.Collections.Generic;
using UnityEngine;
public abstract class EntityBase {
public AniState currentAniState = AniState.None;
public StateMgr stateMgr = null;
private string name;
public string Name {
get {
return name;
}
set {
name = value;
}
}
public void Move() {
stateMgr.ChangeStatus(this, AniState.Move, null);
}
}

@ -0,0 +1,25 @@
/****************************************************
IState.cs
Plane
: 1785275942@qq.com
2019/03/19 6:38
*****************************************************/
public interface IState {
void Enter(EntityBase entity, params object[] args);//可变参数
void Process(EntityBase entity, params object[] args);
void Exit(EntityBase entity, params object[] args);
}
public enum AniState {
None,
Born,
Idle,
Move,
Attack,
Hit,
Die
}

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveState : IState
{
public void Enter(EntityBase entity, params object[] args)
{
throw new System.NotImplementedException();
}
public void Exit(EntityBase entity, params object[] args)
{
throw new System.NotImplementedException();
}
public void Process(EntityBase entity, params object[] args)
{
throw new System.NotImplementedException();
}
}

@ -0,0 +1,36 @@
/****************************************************
StateMgr.cs
Plane
: 1785275942@qq.com
2019/03/15 9:08
*****************************************************/
using UnityEngine;
using System.Collections.Generic;
public class StateMgr : MonoBehaviour {
private Dictionary<AniState, IState> fsm = new Dictionary<AniState, IState>();
public void Init() {
//fsm.Add(AniState.Born, new StateBorn());
}
public void ChangeStatus(EntityBase entity, AniState targetState, params object[] args) {
if (entity.currentAniState == targetState) {
return;
}
if (fsm.ContainsKey(targetState)) {
if (entity.currentAniState != AniState.None) {
fsm[entity.currentAniState].Exit(entity, args);
}
fsm[targetState].Enter(entity, args);
fsm[targetState].Process(entity, args);
}
}
}

@ -0,0 +1,577 @@
/****************************************************
PETimer.cs
Plane
: 1785275942@qq.com
2019/01/24 8:26
*****************************************************/
using System;
using System.Collections.Generic;
using System.Timers;
public class PETimer {
private Action<string> taskLog;
private Action<Action<int>, int> taskHandle;
private static readonly string lockTid = "lockTid";
private DateTime startDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
private double nowTime;
private Timer srvTimer;
private int tid;
private List<int> tidLst = new List<int>();
private List<int> recTidLst = new List<int>();
private static readonly string lockTime = "lockTime";
private List<PETimeTask> tmpTimeLst = new List<PETimeTask>();
private List<PETimeTask> taskTimeLst = new List<PETimeTask>();
private List<int> tmpDelTimeLst = new List<int>();
private int frameCounter;
private static readonly string lockFrame = "lockFrame";
private List<PEFrameTask> tmpFrameLst = new List<PEFrameTask>();
private List<PEFrameTask> taskFrameLst = new List<PEFrameTask>();
private List<int> tmpDelFrameLst = new List<int>();
public PETimer(int interval = 0) {
tidLst.Clear();
recTidLst.Clear();
tmpTimeLst.Clear();
taskTimeLst.Clear();
tmpFrameLst.Clear();
taskFrameLst.Clear();
if (interval != 0) {
srvTimer = new Timer(interval) {
AutoReset = true
};
srvTimer.Elapsed += (object sender, ElapsedEventArgs args) => {
Update();
};
srvTimer.Start();
}
}
public void Update() {
CheckTimeTask();
CheckFrameTask();
DelTimeTask();
DelFrameTask();
if (recTidLst.Count > 0) {
lock (lockTid) {
RecycleTid();
}
}
}
private void DelTimeTask() {
if (tmpDelTimeLst.Count > 0) {
lock (lockTime) {
for (int i = 0; i < tmpDelTimeLst.Count; i++) {
bool isDel = false;
int delTid = tmpDelTimeLst[i];
for (int j = 0; j < taskTimeLst.Count; j++) {
PETimeTask task = taskTimeLst[j];
if (task.tid == delTid) {
isDel = true;
taskTimeLst.RemoveAt(j);
recTidLst.Add(delTid);
//LogInfo("Del taskTimeLst ID:" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
break;
}
}
if (isDel)
continue;
for (int j = 0; j < tmpTimeLst.Count; j++) {
PETimeTask task = tmpTimeLst[j];
if (task.tid == delTid) {
tmpTimeLst.RemoveAt(j);
recTidLst.Add(delTid);
//LogInfo("Del tmpTimeLst ID:" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
break;
}
}
}
tmpDelTimeLst.Clear();
}
}
}
private void DelFrameTask() {
if (tmpDelFrameLst.Count > 0) {
lock (lockFrame) {
for (int i = 0; i < tmpDelFrameLst.Count; i++) {
bool isDel = false;
int delTid = tmpDelFrameLst[i];
for (int j = 0; j < taskFrameLst.Count; j++) {
PEFrameTask task = taskFrameLst[j];
if (task.tid == delTid) {
isDel = true;
taskFrameLst.RemoveAt(j);
recTidLst.Add(delTid);
break;
}
}
if (isDel)
continue;
for (int j = 0; j < tmpFrameLst.Count; j++) {
PEFrameTask task = tmpFrameLst[j];
if (task.tid == delTid) {
tmpFrameLst.RemoveAt(j);
recTidLst.Add(delTid);
break;
}
}
}
tmpDelFrameLst.Clear();
}
}
}
private void CheckTimeTask() {
if (tmpTimeLst.Count > 0) {
lock (lockTime) {
//加入缓存区中的定时任务
for (int tmpIndex = 0; tmpIndex < tmpTimeLst.Count; tmpIndex++) {
taskTimeLst.Add(tmpTimeLst[tmpIndex]);
}
tmpTimeLst.Clear();
}
}
//遍历检测任务是否达到条件
nowTime = GetUTCMilliseconds();
for (int index = 0; index < taskTimeLst.Count; index++) {
PETimeTask task = taskTimeLst[index];
if (nowTime.CompareTo(task.destTime) < 0) {
continue;
}
else {
Action<int> cb = task.callback;
try {
if (taskHandle != null) {
taskHandle(cb, task.tid);
}
else {
if (cb != null) {
cb(task.tid);
}
}
}
catch (Exception e) {
LogInfo(e.ToString());
}
//移除已经完成的任务
if (task.count == 1) {
taskTimeLst.RemoveAt(index);
index--;
recTidLst.Add(task.tid);
}
else {
if (task.count != 0) {
task.count -= 1;
}
task.destTime += task.delay;
}
}
}
}
private void CheckFrameTask() {
if (tmpFrameLst.Count > 0) {
lock (lockFrame) {
//加入缓存区中的定时任务
for (int tmpIndex = 0; tmpIndex < tmpFrameLst.Count; tmpIndex++) {
taskFrameLst.Add(tmpFrameLst[tmpIndex]);
}
tmpFrameLst.Clear();
}
}
frameCounter += 1;
//遍历检测任务是否达到条件
for (int index = 0; index < taskFrameLst.Count; index++) {
PEFrameTask task = taskFrameLst[index];
if (frameCounter < task.destFrame) {
continue;
}
else {
Action<int> cb = task.callback;
try {
if (taskHandle != null) {
taskHandle(cb, task.tid);
}
else {
if (cb != null) {
cb(task.tid);
}
}
}
catch (Exception e) {
LogInfo(e.ToString());
}
//移除已经完成的任务
if (task.count == 1) {
taskFrameLst.RemoveAt(index);
index--;
recTidLst.Add(task.tid);
}
else {
if (task.count != 0) {
task.count -= 1;
}
task.destFrame += task.delay;
}
}
}
}
#region TimeTask
public int AddTimeTask(Action<int> callback, double delay, PETimeUnit timeUnit = PETimeUnit.Millisecond, int count = 1) {
if (timeUnit != PETimeUnit.Millisecond) {
switch (timeUnit) {
case PETimeUnit.Second:
delay = delay * 1000;
break;
case PETimeUnit.Minute:
delay = delay * 1000 * 60;
break;
case PETimeUnit.Hour:
delay = delay * 1000 * 60 * 60;
break;
case PETimeUnit.Day:
delay = delay * 1000 * 60 * 60 * 24;
break;
default:
LogInfo("Add Task TimeUnit Type Error...");
break;
}
}
int tid = GetTid(); ;
nowTime = GetUTCMilliseconds();
lock (lockTime) {
tmpTimeLst.Add(new PETimeTask(tid, callback, nowTime + delay, delay, count));
}
return tid;
}
public void DeleteTimeTask(int tid) {
lock (lockTime) {
tmpDelTimeLst.Add(tid);
//LogInfo("TmpDel ID:" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
}
/*
bool exist = false;
for (int i = 0; i < taskTimeLst.Count; i++) {
PETimeTask task = taskTimeLst[i];
if (task.tid == tid) {
//taskTimeLst.RemoveAt(i);
for (int j = 0; j < tidLst.Count; j++) {
if (tidLst[j] == tid) {
//tidLst.RemoveAt(j);
break;
}
}
exist = true;
break;
}
}
if (!exist) {
for (int i = 0; i < tmpTimeLst.Count; i++) {
PETimeTask task = tmpTimeLst[i];
if (task.tid == tid) {
//tmpTimeLst.RemoveAt(i);
for (int j = 0; j < tidLst.Count; j++) {
if (tidLst[j] == tid) {
//tidLst.RemoveAt(j);
break;
}
}
exist = true;
break;
}
}
}
return exist;
*/
}
public bool ReplaceTimeTask(int tid, Action<int> callback, float delay, PETimeUnit timeUnit = PETimeUnit.Millisecond, int count = 1) {
if (timeUnit != PETimeUnit.Millisecond) {
switch (timeUnit) {
case PETimeUnit.Second:
delay = delay * 1000;
break;
case PETimeUnit.Minute:
delay = delay * 1000 * 60;
break;
case PETimeUnit.Hour:
delay = delay * 1000 * 60 * 60;
break;
case PETimeUnit.Day:
delay = delay * 1000 * 60 * 60 * 24;
break;
default:
LogInfo("Replace Task TimeUnit Type Error...");
break;
}
}
nowTime = GetUTCMilliseconds();
PETimeTask newTask = new PETimeTask(tid, callback, nowTime + delay, delay, count);
bool isRep = false;
for (int i = 0; i < taskTimeLst.Count; i++) {
if (taskTimeLst[i].tid == tid) {
taskTimeLst[i] = newTask;
isRep = true;
break;
}
}
if (!isRep) {
for (int i = 0; i < tmpTimeLst.Count; i++) {
if (tmpTimeLst[i].tid == tid) {
tmpTimeLst[i] = newTask;
isRep = true;
break;
}
}
}
return isRep;
}
#endregion
#region FrameTask
public int AddFrameTask(Action<int> callback, int delay, int count = 1) {
int tid = GetTid();
lock (lockTime) {
tmpFrameLst.Add(new PEFrameTask(tid, callback, frameCounter + delay, delay, count));
}
return tid;
}
public void DeleteFrameTask(int tid) {
lock (lockFrame) {
tmpDelFrameLst.Add(tid);
}
/*
bool exist = false;
for (int i = 0; i < taskFrameLst.Count; i++) {
PEFrameTask task = taskFrameLst[i];
if (task.tid == tid) {
//taskFrameLst.RemoveAt(i);
for (int j = 0; j < tidLst.Count; j++) {
if (tidLst[j] == tid) {
//tidLst.RemoveAt(j);
break;
}
}
exist = true;
break;
}
}
if (!exist) {
for (int i = 0; i < tmpFrameLst.Count; i++) {
PEFrameTask task = tmpFrameLst[i];
if (task.tid == tid) {
//tmpFrameLst.RemoveAt(i);
for (int j = 0; j < tidLst.Count; j++) {
if (tidLst[j] == tid) {
//tidLst.RemoveAt(j);
break;
}
}
exist = true;
break;
}
}
}
return exist;
*/
}
public bool ReplaceFrameTask(int tid, Action<int> callback, int delay, int count = 1) {
PEFrameTask newTask = new PEFrameTask(tid, callback, frameCounter + delay, delay, count);
bool isRep = false;
for (int i = 0; i < taskFrameLst.Count; i++) {
if (taskFrameLst[i].tid == tid) {
taskFrameLst[i] = newTask;
isRep = true;
break;
}
}
if (!isRep) {
for (int i = 0; i < tmpFrameLst.Count; i++) {
if (tmpFrameLst[i].tid == tid) {
tmpFrameLst[i] = newTask;
isRep = true;
break;
}
}
}
return isRep;
}
#endregion
public void SetLog(Action<string> log) {
taskLog = log;
}
public void SetHandle(Action<Action<int>, int> handle) {
taskHandle = handle;
}
public void Reset() {
tid = 0;
tidLst.Clear();
recTidLst.Clear();
tmpTimeLst.Clear();
taskTimeLst.Clear();
tmpFrameLst.Clear();
taskFrameLst.Clear();
taskLog = null;
srvTimer.Stop();
}
public int GetYear() {
return GetLocalDateTime().Year;
}
public int GetMonth() {
return GetLocalDateTime().Month;
}
public int GetDay() {
return GetLocalDateTime().Day;
}
public int GetWeek() {
return (int)GetLocalDateTime().DayOfWeek;
}
public DateTime GetLocalDateTime() {
DateTime dt = TimeZone.CurrentTimeZone.ToLocalTime(startDateTime.AddMilliseconds(nowTime));
return dt;
}
public double GetMillisecondsTime() {
return nowTime;
}
public string GetLocalTimeStr() {
DateTime dt = GetLocalDateTime();
string str = GetTimeStr(dt.Hour) + ":" + GetTimeStr(dt.Minute) + ":" + GetTimeStr(dt.Second);
return str;
}
#region Tool Methonds
private int GetTid() {
lock (lockTid) {
tid += 1;
//安全代码,以防万一
while (true) {
if (tid == int.MaxValue) {
tid = 0;
}
bool used = false;
for (int i = 0; i < tidLst.Count; i++) {
if (tid == tidLst[i]) {
used = true;
break;
}
}
if (!used) {
tidLst.Add(tid);
break;
}
else {
tid += 1;
}
}
}
return tid;
}
private void RecycleTid() {
for (int i = 0; i < recTidLst.Count; i++) {
int tid = recTidLst[i];
for (int j = 0; j < tidLst.Count; j++) {
if (tidLst[j] == tid) {
tidLst.RemoveAt(j);
break;
}
}
}
recTidLst.Clear();
}
private void LogInfo(string info) {
if (taskLog != null) {
taskLog(info);
}
}
private double GetUTCMilliseconds() {
TimeSpan ts = DateTime.UtcNow - startDateTime;
return ts.TotalMilliseconds;
}
private string GetTimeStr(int time) {
if (time < 10) {
return "0" + time;
}
else {
return time.ToString();
}
}
#endregion
class PETimeTask {
public int tid;
public Action<int> callback;
public double destTime;//单位:毫秒
public double delay;
public int count;
public PETimeTask(int tid, Action<int> callback, double destTime, double delay, int count) {
this.tid = tid;
this.callback = callback;
this.destTime = destTime;
this.delay = delay;
this.count = count;
}
}
class PEFrameTask {
public int tid;
public Action<int> callback;
public int destFrame;
public int delay;
public int count;
public PEFrameTask(int tid, Action<int> callback, int destFrame, int delay, int count) {
this.tid = tid;
this.callback = callback;
this.destFrame = destFrame;
this.delay = delay;
this.count = count;
}
}
}
public enum PETimeUnit {
Millisecond,
Second,
Minute,
Hour,
Day
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PETimer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("PETimer")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("ef27c6d9-9cf9-48fc-9f4f-e219483fed47")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1 @@
Build from CQ at 2021/12/22 17:08:15

@ -0,0 +1,236 @@
body{
margin:0px;
padding:0px;
position: absolute;
height:100%;
width:100%;
background-size:cover;
font-style: regular;
font-family:"Myriad Pro", Myriad,"Helvetica Neue", Helvetica, Arial, sans-serif;
background-color:#f0f0f1;
}
.webgl-content,#loadingBlock,#errorBrowserBlock{
padding:0px;
position:absolute;
height:100vh;
width:100vw;
background-color:#ffffff;
}
#gameContainer, canvas {
position: absolute;
height: 100%;
width: 100%;
background-color: #f0f0f1;
}
#fullScreenButton{
height:30px;
width:30px;
position:absolute;
z-index:1;
bottom:5px;
right:5px;
background-color:transparent;
background-image:url("../img/fullScreen_on.png");
background-size:30px 30px;
border:none;
cursor: pointer;
}
.subtitle{
color:#333333;
font-size:16px;
padding-bottom:3vh;
padding-top: 3vh;
display: block;
height:15vh;
width:40vw;
margin:auto;
text-align: center;
}
.logo{
height:8vh;
width:auto;
display: block;
margin:auto;
margin-top:10%;
}
#loadingBlock,#errorBrowserBlock{
background-image:url("../img/background.png");
background-size:cover;
}
#emptyBar{
background: url("../img/progressEmpty.png") no-repeat right;
float: right;
width: 60%;
height: 100%;
display: inline-block;
}
#fullBar{
background: url("../img/progressFull.png") no-repeat right;
float: left;
width: 40%;
height: 100%;
display: inline-block;
}
#progressBar,#warningBrowserBlock,#warningMobileBlock,#errorContent{
height:25vh;
width:40vw;
margin:auto;
text-align: center;
}
#progressBar{
height:8vh;
color:#999999;
font-size:18px;
}
#warningBrowserBlock,#warningMobileBlock,#errorContent{
margin-top:15vh;
color:#666666;
font-size:2.3vh;
}
.browserIcons{
display: inline-flex;
margin-top:2vh;
}
.browserIcons a{
width:150px;
}
#errorContent{
font-size:3vh;
margin-top:5vh;
}
.centered{
height: 100%;
max-width:770px;
margin-left:auto;
margin-right:auto;
}
/* When aspect-ratio is smaller than 4/3*/
/*@media (max-aspect-ratio: 4/3){
.webgl-content{
-webkit-transform: translate(0%, 0%); transform: translate(0%, 0%);
-webkit-box-shadow: 0px 0px 29px 0px rgba(0,0,0,0.15);
-moz-box-shadow: 0px 0px 29px 0px rgba(0,0,0,0.15);
box-shadow: 0px 0px 29px 0px rgba(0,0,0,0.15);
}
.keepRatio{
width:100%;
padding-top: 75%;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.webgl-content,#loadingBlock,#errorBrowserBlock{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.logo{
width:25vw;
height:auto;
margin-top:1vh;
}
.subtitle{
font-size:2vw;
height:10vw;
padding-bottom:1vw;
padding-top: 1vw;
}
.subtitle,#progressBar,#warningBrowserBlock,#warningMobileBlock,#errorContent{
width:80vw;
}
#progressBar{
height:6vw;
margin-top: 2vw;
font-size:3vw;
}
#emptyBar,#fullBar{
height: 2vw;
}
#warningBrowserBlock,#warningMobileBlock,#errorContent{
margin-top:3vw;
font-size:2vw;
}
.browserIcons{
margin-top:1vw;
}
.browserIcons a{
width:15vw;
}
.browserIcons a img{
width:8vw;
}
.webgl-content,#loadingBlock,#errorBrowserBlock{
border:1px solid #c6c9ca;
width:calc(100% - 2px);
height:auto;
}
}*/
/* When aspect-ratio is bigger than 16/9*/
@media (min-aspect-ratio: 16/9){
body{
display:flex;
flex-wrap:wrap;
justify-content:space-between;
}
.keepRatio{
width:178vh;
height:100%;
margin:0 auto;
}
.webgl-content,#gameContainer,canvas,#loadingBlock,#errorBrowserBlock{
width: inherit;
}
.webgl-content{
-webkit-box-shadow: 0px 0px 29px 0px rgba(0,0,0,0.15);
-moz-box-shadow: 0px 0px 29px 0px rgba(0,0,0,0.15);
box-shadow: 0px 0px 29px 0px rgba(0,0,0,0.15);
}
.subtitle,#progressBar,#warningBrowserBlock,#warningMobileBlock,#errorContent{
width:100vh;
}
.webgl-content,#loadingBlock,#errorBrowserBlock{
border:1px solid #c6c9ca;
height:calc(100% - 2px);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

@ -0,0 +1,160 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>%UNITY_CUSTOM_MYTAG%</title>
<link rel="shortcut icon" href="TemplateData/img/favicon.ico">
<link rel="stylesheet" href="TemplateData/css/style.css">
<script src="Build/UnityLoader.js"></script>
<script>
/*function ToggleFullScreen() {
var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
(document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
(document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
(document.msFullscreenElement && document.msFullscreenElement !== null);
var element = document.body.getElementsByClassName("webgl-content")[0];
if (!isInFullScreen) {
document.getElementById("fullScreenButton").style.backgroundImage="url('TemplateData/img/fullScreen_off.png')";
return (element.requestFullscreen ||
element.webkitRequestFullscreen ||
element.mozRequestFullScreen ||
element.msRequestFullscreen).call(element);
}
else {
document.getElementById("fullScreenButton").style.backgroundImage="url('TemplateData/img/fullScreen_on.png')";
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}*/
function CheckCompatibility(gameInstance, onsuccess, onerror)
{
if (!UnityLoader.SystemInfo.hasWebGL) {
document.getElementById("errorBrowserBlock").style.display = "inherit";
onerror();
} else if (UnityLoader.SystemInfo.mobile) {
document.getElementById("warningMobileBlock").style.display = "inherit";
onsuccess();
} else if (["Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1) {
document.getElementById("warningBrowserBlock").style.display = "inherit";
onsuccess();
} else {
onsuccess();
}
}
function RuntimeInitialized(){
}
function UnityProgress(gameInstance, progress) {
if (!gameInstance.Module)
return;
document.getElementById("loadingBlock").style.display = "inherit";
document.getElementById("fullBar").style.width = (100 * progress) + "%";
document.getElementById("emptyBar").style.width = (100 * (1 - progress)) + "%";
if (progress == 1)
{
setTimeout(function(){ document.getElementById("loadingBlock").style.display = "none"; }, 3000);
}
}
var gameInstance = UnityLoader.instantiate("gameContainer", "%UNITY_WEBGL_BUILD_URL%", {
onProgress: UnityProgress,
compatibilityCheck:CheckCompatibility,
Module: {
//TOTAL_MEMORY: 268435456,
onRuntimeInitialized:RuntimeInitialized,
},
});
//注册web端消息监听
window.addEventListener('message',receiveMessage,false);
function receiveMessage(event){
console.log("receive web message ",event.data);
gameInstance.SendMessage("WebConnecter","RecData",event.data);
}
//发送消息给web端
function SendToWeb(param){
console.log("receive unity message ",param);
window.parent.postMessage(param,'*');
}
</script>
</head>
<body>
<div class="keepRatio">
<div class="webgl-content">
<!--<button id="fullScreenButton" onclick="ToggleFullScreen()"></button>-->
<div id="gameContainer"></div>
</div>
<div id="loadingBlock">
<img class="logo" src="TemplateData/img/Logo.png"></img>
<span class="subtitle"> <br>
头歌为可编程的虚拟仿真课程提供开发和运行环境。
</span>
<div id="progressBar">
<div>加载中...</div><br>
<div class="centered">
<div id="emptyBar"></div>
<div id="fullBar"></div>
</div>
</div>
<div id="warningBrowserBlock" style="display:none;">
<div class="warningBrowserText">
Your browser may not be compatible with this website. For an optimal experience, we suggest you to download one of this popular web browsers.
</div>
<div class="browserIcons">
<a href="https://www.mozilla.org/firefox" target="_blank"><img src="TemplateData/img/browser-firefox.png" alt="Firefox browser"></a>
<a href="https://www.google.com/chrome" target="_blank"><img src="TemplateData/img/browser-chrome.png" alt="Chrome browser"></a>
<a href="https://www.apple.com/safari/" target="_blank"><img src="TemplateData/img/browser-safari.png" alt="Safari browser"></a>
</div>
</div>
<div id="warningMobileBlock" style="display:none;">
<div class="warningBrowserText">
Please note that Unity WebGL is not currently supported on mobiles.
</div>
</div>
</div>
<div id="errorBrowserBlock" style="display:none;">
<img class="logo" src="TemplateData/img/Logo.png"></img>
<span class="subtitle">
<br>
头歌为可编程的虚拟仿真课程提供开发和运行环境。
</span>
<div id="errorContent">
<div id="errorBrowserText">
Your browser does not support WebGL. <br> You can download one of this popular web browsers.
</div>
<div class="browserIcons">
<a href="https://www.mozilla.org/firefox" target="_blank"><img src="TemplateData/img/browser-firefox.png" alt="Firefox browser"></a>
<a href="https://www.google.com/chrome" target="_blank"><img src="TemplateData/img/browser-chrome.png" alt="Chrome browser"></a>
<a href="https://www.apple.com/safari/" target="_blank"><img src="TemplateData/img/browser-safari.png" alt="Safari browser"></a>
</div>
</div>
</div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Loading…
Cancel
Save