using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReplayFireBase : ReplaySimpleObject
{
///
/// 回放克隆
///
///
public override void CloneObject(string json)
{
var jsonData = JsonUtility.FromJson(json);
var clonedObj = EntitiesManager.Instance.CreateObj(cloneBase.clonePrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName));
clonedObj.name = jsonData.objectName;//名字即ID
SetBaseGameObject(clonedObj, jsonData);
SetCloneGameObject(clonedObj, json);
SetSpreadFire(clonedObj, jsonData);
SetFireTemperatureRadiation(clonedObj, jsonData);
}
private void SetFireTemperatureRadiation(GameObject clonedObj, FireSpreadData data)
{
if (clonedObj.name == data.name)
{
FireControl ctrl = clonedObj.GetComponent();
ctrl.MyData.temperature = data.temperature;
ctrl.MyData.radiation = data.radiation;
ctrl.MyData.rsw = data.rsw;
ctrl.MyData.pos = data.pos;
ctrl.SetTemperatureText();
ctrl.SetRadiationText();
}
}
private void SetSpreadFire(GameObject clonedObj, FireSpreadData data)
{
if (clonedObj.name == data.name)
{
FireSpreadCtrl ctrl = clonedObj.GetComponent();
ctrl.straightSpread = data.straightSpread;
ctrl.areaSpread = data.areaSpread;
ctrl.aroundSpread = data.aroundSpread;
ctrl.startTime = data.startTime;
ctrl.spreadSpeed = data.spreadSpeed;
ctrl.repeatRate = data.repeatRate;
ctrl.spreadFirePositions = data.spreadFirePositions;
//ctrl.spdFirePositions = data.spdFirePositions;
if (data.spdFirePositions.Count > 0)
{
ctrl.spdFirePositions.Clear();
foreach (var item in data.spdFirePositions)
{
ctrl.spdFirePositions.Add(item.postions);
}
}
ctrl.isSpreading = data.isSpreading;
ctrl.index = data.index;
if (data.hasSpreadPos.Count > 0)
{
if (ctrl.fire == null)
{
ctrl.fire = Resources.Load("Prefab/Diaster/FireSpread");
}
if (data.hasSpreadPos.Count > 0)
{
int index = 1;
foreach (var pos in data.hasSpreadPos)
{
GameObject spreadFire = Instantiate(ctrl.fire, pos, Quaternion.identity,
GameObject.Find("P_AllParent").transform.Find("P_Disaster/P_SpreadFire")) as GameObject;
var spreadedFire = spreadFire.GetComponent();
spreadedFire.SourceId = ctrl.GetComponent().GameObjID;
if (data.straightSpread)
spreadFire.name = "straightSpread" + (index - 1);
else if (data.areaSpread)
spreadFire.name = "areaSpread" + (index - 1);
else
spreadFire.name = "aroundSpread" + (index - 1);
index++;
}
}
}
if (data.isSpreading && ReplaySetting.PlayStatus != PlayStatus.isReplay)
{
StartCoroutine(ctrl.WaitForStart(data.startTime));
}
}
}
//public override void SetProperties(ObjectData objectData)
//{
// base.SetProperties(objectData);
// if (objectData.cloneObjType == CloneObjType.SpreadFire)
// {
// FireSpreadData data = JsonUtility.FromJson(objectData.json);
// foreach (Transform item in transform)
// {
// if (item.name == data.name)
// {
// FireSpreadCtrl ctrl = item.GetComponent();
// ctrl.straightSpread = data.straightSpread;
// ctrl.areaSpread = data.areaSpread;
// ctrl.areaSpread = data.aroundSpread;
// ctrl.startTime = data.startTime;
// ctrl.spreadSpeed = data.spreadSpeed;
// ctrl.repeatRate = data.repeatRate;
// ctrl.spreadFirePositions = data.spreadFirePositions;
// ctrl.spdFirePositions = data.spdFirePositions;
// ctrl.isSpreading = data.isSpreading;
// ctrl.index = data.index;
// if (data.hasSpreadPos.Count > 0)
// {
// if (ctrl.fire == null)
// {
// ctrl.fire = Resources.Load("Prefab/Diaster/FireSpread");
// }
// foreach (var pos in data.hasSpreadPos)
// {
// GameObject spreadFire = Instantiate(ctrl.fire, pos, Quaternion.identity,
// GameObject.Find("P_AllParent").transform.Find("P_Disaster/P_SpreadFire")) as GameObject;
// var spreadedFire = spreadFire.GetComponent();
// spreadedFire.SourceId = ctrl.GetComponent().GameObjID;
// }
// }
// if (data.isSpreading)
// {
// StartCoroutine(ctrl.WaitForStart(data.startTime));
// }
// break;
// }
// }
// }
//}
public override void Clear(IMessage obj)
{
base.Clear(obj);
Transform pfire = GameObject.Find("P_AllParent").transform.Find("P_Disaster/P_SpreadFire");
if (pfire.childCount > 0)
foreach (Transform child in pfire)
{
Destroy(child.gameObject);
}
}
}