/// <summary>ブロックの初期値を設定する </summary> /// <param name="_blockWorkData"></param> /// <param name="data_id"> データID </param> private void InitBlock(ref BlockWorkData blockWorkData, int data_id, string block_id) { blockWorkData.gameObjectTransform = blockWorkData.gameObject.transform; blockWorkData.rootBlockTransform = blockWorkData.gameObjectTransform.Find("Root"); blockWorkData.blockData = blockWorkData.gameObject.GetComponentInChildren <BlockData>(); blockWorkData.blockData.id = data_id; blockWorkData.directionArrow = blockWorkData.gameObject.GetComponentInChildren <DirectionArrow>(); blockWorkData.renderer = blockWorkData.gameObject.GetComponentInChildren <Renderer>(); if (blockWorkData.renderer == null) { return; } blockWorkData.renderer.sharedMaterial = Instantiate(blockWorkData.renderer.sharedMaterial); blockWorkData.materialPropertyBlock = new MaterialPropertyBlock(); blockWorkData.materialPropertyBlock.SetColor("_Color", Color.white); blockWorkData.renderer.SetPropertyBlock(blockWorkData.materialPropertyBlock); blockWorkData.gameObject.name = block_id; blockWorkData.gameObjectTransform.parent = this.gameObject.transform; blockWorkData.gameObject.SetActive(false); // メシュの取得 MeshFilter meshFileter; meshFileter = blockWorkData.gameObject.GetComponentInChildren <MeshFilter>(); if (meshFileter != null) { blockWorkData.mesh = meshFileter.mesh; } }
/// <summary>ブロックの色を設定する </summary> /// <param name="id">ブロックのID</param> /// <param name="color">色</param> public void SetPartsColor(string id, Color color) { BlockWorkData blockWorkData = _blockWorkData[id]; blockWorkData.materialPropertyBlock.SetColor("_Color", color); blockWorkData.renderer.SetPropertyBlock(blockWorkData.materialPropertyBlock); }
/// <summary> ブロックのステータスを変更 </summary> public override void SetBlockStatus(string id) { if (!base._blockWorkData.ContainsKey(id)) { return; } Vector3 nodePoint = _webframe.listNodePoint[GetDataID(id)]; PartsDispManager.PartsDispStatus partsDispStatus; partsDispStatus.id = id; partsDispStatus.enable = true; if (base.SetBlockStatusCommon(partsDispStatus) == false) { return; } // 表示に必要なパラメータを用意する BlockWorkData blockWorkData = base._blockWorkData[id]; // 姿勢を設定 blockWorkData.gameObjectTransform.position = nodePoint; blockWorkData.gameObjectTransform.localScale = new Vector3(_nodeScale, _nodeScale, _nodeScale); }
/// <summary> /// パーツを変更する /// </summary> public override void ChengeParts() { if (_webframe == null) { Debug.Log("MemberDispManager _webframe == null"); return; } try { BlockWorkData blockWorkData; // データに無いブロックは消す List <string> DeleteKeys = new List <string>(); foreach (string id in base._blockWorkData.Keys) { int i = GetDataID(id); if (!_webframe.ListMemberData.ContainsKey(i)) { try { Destroy(base._blockWorkData[id].renderer.sharedMaterial); Destroy(base._blockWorkData[id].gameObject); } catch { } finally { DeleteKeys.Add(id); } } } foreach (string id in DeleteKeys) { base._blockWorkData.Remove(id); } // 新しいブロックを生成する foreach (int i in _webframe.ListMemberData.Keys) { string id = GetBlockID(i); if (!base._blockWorkData.ContainsKey(id)) { // 新しいオブジェクトを生成する blockWorkData = new BlockWorkData { gameObject = Instantiate(_blockPrefab) }; InitBlock(ref blockWorkData, i, id); base._blockWorkData.Add(id, blockWorkData); } // 座標を修正する SetBlockStatus(id); } } catch (Exception e) { Debug.Log("MemberDispManager ChengeParts" + e.Message); } }
/// <summary> ブロックの矢印を設定する </summary> /// <param name="onoff"></param> private void SetAllowStatus(string id, bool onoff) { BlockWorkData blockWorkData = base._blockWorkData[id]; if (blockWorkData.directionArrow != null) { blockWorkData.directionArrow.EnableRenderer(onoff); } }
/// <summary> /// パーツを作成する /// </summary> public override void CreateParts() { if (_webframe == null) { Debug.Log("ElementDispManager _webframe == null"); return; } try { BlockWorkData blockWorkData; // 前のオブジェクトを消す foreach (string id in base._blockWorkData.Keys) { try { Destroy(base._blockWorkData[id].renderer.sharedMaterial); Destroy(base._blockWorkData[id].gameObject); } catch { } } base._blockWorkData.Clear(); // 新しいオブジェクトを生成する foreach (int i in _webframe.ListMemberData.Keys) { blockWorkData = new BlockWorkData { gameObject = Instantiate(_blockPrefab) }; base._blockWorkData.Add(GetBlockID(i), blockWorkData); } // 新しいオブジェクトのプロパティを設定する foreach (int i in _webframe.ListMemberData.Keys) { var m = _webframe.ListMemberData[i]; var e = m.e; // element no blockWorkData = base._blockWorkData[GetBlockID(i)]; InitBlock(ref blockWorkData, e, GetBlockID(i)); } } catch (Exception e) { Debug.Log("ElementDispManager CreateElements" + e.Message); } }
/// <summary> /// /// </summary> /// <param name="statusBase"></param> /// <returns></returns> protected bool SetBlockStatusCommon(PartsDispStatus partsDispStatus) { if (_blockWorkData.ContainsKey(partsDispStatus.id) == false) { return(false); } BlockWorkData blockWorkData = _blockWorkData[partsDispStatus.id]; // 無効な場合 if (partsDispStatus.enable == false) { if (blockWorkData.gameObject != null) { if (blockWorkData.gameObject.activeSelf) { blockWorkData.gameObject.SetActive(false); } } return(false); } // 有効な場合 if (blockWorkData.gameObject == null) { return(false); } if (!blockWorkData.gameObject.activeSelf) { blockWorkData.gameObject.SetActive(true); } return(true); }
/// <summary> /// /// </summary> public override void SetBlockStatus(string id) { if (!base._blockWorkData.ContainsKey(id)) { return; } int i = GetDataID(id); webframe.PanelData panelData = _webframe.ListPanelData[i]; Dictionary <int, Vector3> ListNodeData = _webframe.listNodePoint; PartsDispStatus partsDispStatus; // パネルの有効をチェック List <int> nodeNo = new List <int>(); partsDispStatus.id = id; partsDispStatus.enable = false; int[] nodeNos = { panelData.no1, panelData.no2, panelData.no3 }; foreach (int no in nodeNos) { if (ListNodeData.ContainsKey(no)) { partsDispStatus.enable = true; nodeNo.Add(no); } } // 3つの頂点が有効でなかったら if (nodeNo.Count < 3) { partsDispStatus.enable = false; return; } // 同じIDがないか検索 for (int j = 0; j < nodeNo.Count; j++) { for (int k = j + 1; k < nodeNo.Count; k++) { if (nodeNo[j] == nodeNo[k]) { partsDispStatus.enable = false; break; } } if (j != nodeNo.Count) { break; } } if (SetBlockStatusCommon(partsDispStatus) == false) { return; } // 頂点位置を再定義する BlockWorkData blockWorkData = base._blockWorkData[id]; PanelBlock panelBlock = blockWorkData.gameObject.GetComponentInChildren <PanelBlock>(); Vector3[] position = new Vector3[nodeNo.Count]; for (int j = 0; j < nodeNo.Count; j++) { Vector3 node = _webframe.listNodePoint[nodeNo[j]]; position[j] = node; } panelBlock.SetPanelPointPosition(position); }