public override void SetIndex(int index) { base.SetIndex(index); Renderer renderer = TargetObject.GetComponent <Renderer>(); if (renderer != null) { renderer.material = Current; } }
/// <summary> /// get the material to assign textures to /// </summary> override protected void Awake() { base.Awake(); Renderer renderer = TargetObject.GetComponent <Renderer>(); if (renderer != null) { mMaterial = renderer.material; } else { Debug.LogError("CycleTexture requires a renderer and material on the assigned GameObject!"); Destroy(this); } }
//========================================================================================= /// <summary> /// メッシュのワールド座標/法線/接線を返す(エディタ設定用) /// </summary> /// <param name="wposList"></param> /// <param name="wnorList"></param> /// <param name="wtanList"></param> /// <returns>頂点数</returns> public override int GetEditorPositionNormalTangent( out List <Vector3> wposList, out List <Vector3> wnorList, out List <Vector3> wtanList ) { wposList = new List <Vector3>(); wnorList = new List <Vector3>(); wtanList = new List <Vector3>(); if (Application.isPlaying) { if (Status.IsDispose) { return(0); } if (IsMeshUse() == false || TargetObject == null) { return(0); } Vector3[] posArray = new Vector3[VertexCount]; Vector3[] norArray = new Vector3[VertexCount]; Vector3[] tanArray = new Vector3[VertexCount]; MagicaPhysicsManager.Instance.Mesh.CopyToRenderMeshWorldData(MeshIndex, TargetObject.transform, posArray, norArray, tanArray); wposList = new List <Vector3>(posArray); wnorList = new List <Vector3>(norArray); wtanList = new List <Vector3>(tanArray); return(VertexCount); } else { if (TargetObject == null) { return(0); } var ren = TargetObject.GetComponent <Renderer>(); MeshUtility.CalcMeshWorldPositionNormalTangent(ren, sharedMesh, out wposList, out wnorList, out wtanList); return(wposList.Count); } }
/// <summary> /// Select the color from the Array and apply it. /// </summary> /// <param name="index"></param> public override void SetIndex(int index) { base.SetIndex(index); mTargetColor = Array[Index]; if (mColorTransition == null) { Renderer renderer = TargetObject.GetComponent <Renderer>(); if (renderer != null) { mMaterial = renderer.material; } mMaterial.color = mTargetColor; } else { mColorTransition.StartTransition(mTargetColor); } }
void CreateMandoragora() { if (CreateFlg) { int count = 0; for (int y = 0; CounterY > y; y++) { for (int x = 0; CounterX > x; x++) { if (count < CatchMandoragoraCreate) { GameObject TargetObject; TargetObject = Instantiate(Mandragora, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity); TargetObject.name = "ReleaseMandragora" + count; TargetObject.GetComponent <MandragoraCreate>().SetPosition(x, y, CounterX, CounterY); count++; } } } CreateFlg = false; } }
/// <summary> /// ターゲットレンダラーの共有メッシュを取得する /// </summary> /// <returns></returns> private Mesh GetTargetSharedMesh() { if (TargetObject == null) { return(null); } var ren = TargetObject.GetComponent <Renderer>(); if (ren == null) { return(null); } if (ren is SkinnedMeshRenderer) { var sren = ren as SkinnedMeshRenderer; return(sren.sharedMesh); } else { meshFilter = TargetObject.GetComponent <MeshFilter>(); return(meshFilter.sharedMesh); } }
protected override void Start() { mColorTransition = TargetObject.GetComponent <ColorTransition>(); base.Start(); }
/// <summary> /// 初期化 /// </summary> protected override void OnInit() { base.OnInit(); if (status.IsInitError) { return; } // レンダラーチェック if (TargetObject == null) { status.SetInitError(); return; } var ren = TargetObject.GetComponent <Renderer>(); if (ren == null) { status.SetInitError(); return; } if (MeshData.VerifyData() != Define.Error.None) { status.SetInitError(); return; } VertexCount = MeshData.VertexCount; TriangleCount = MeshData.TriangleCount; // クローンメッシュ作成 // ここではメッシュは切り替えない mesh = null; if (ren is SkinnedMeshRenderer) { var sren = ren as SkinnedMeshRenderer; skinMeshRenderer = sren; // メッシュクローン mesh = GameObject.Instantiate(sharedMesh); #if !UNITY_EDITOR_OSX // MacではMetal関連でエラーが発生するので対応(エディタ環境のみ) mesh.MarkDynamic(); #endif originalBones = sren.bones; // クローンメッシュ初期化 // srenのボーンリストはここで配列を作成し最後にレンダラーのトランスフォームを追加する var blist = new List <Transform>(originalBones); blist.Add(ren.transform); // レンダラートランスフォームを最後に追加 boneList = blist.ToArray(); var bindlist = new List <Matrix4x4>(sharedMesh.bindposes); bindlist.Add(Matrix4x4.identity); // レンダラーのバインドポーズを最後に追加 mesh.bindposes = bindlist.ToArray(); } else { // メッシュクローン mesh = GameObject.Instantiate(sharedMesh); #if !UNITY_EDITOR_OSX // MacではMetal関連でエラーが発生するので対応(エディタ環境のみ) mesh.MarkDynamic(); #endif meshFilter = TargetObject.GetComponent <MeshFilter>(); Debug.Assert(meshFilter); } oldUse = false; // 共有メッシュのuid int uid = sharedMesh.GetInstanceID(); // 共有メッシュのIDを使う bool first = MagicaPhysicsManager.Instance.Mesh.IsEmptySharedRenderMesh(uid); // メッシュ登録 MeshIndex = MagicaPhysicsManager.Instance.Mesh.AddRenderMesh( uid, MeshData.isSkinning, MeshData.baseScale, MeshData.VertexCount, IsSkinning ? boneList.Length - 1 : 0, // レンダラーのボーンインデックス #if UNITY_2018 IsSkinning ? MeshData.VertexCount : 0 // ボーンウエイト数=頂点数 #else IsSkinning ? sharedMesh.GetAllBoneWeights().Length : 0 #endif ); // レンダーメッシュの共有データを一次元配列にコピーする if (first) { MagicaPhysicsManager.Instance.Mesh.SetRenderSharedMeshData( MeshIndex, IsSkinning, mesh.vertices, mesh.normals, mesh.tangents, #if UNITY_2018 IsSkinning ? mesh.boneWeights : null #else sharedMesh.GetBonesPerVertex(), sharedMesh.GetAllBoneWeights() #endif ); } // レンダーメッシュ情報確定 // すべてのデータが確定してから実行しないと駄目なもの MagicaPhysicsManager.Instance.Mesh.UpdateMeshState(MeshIndex); // 法線/接線再計算モード設定 SetRecalculateNormalAndTangentMode(); }
/// <summary> /// 拷贝指引的目标控件 /// </summary> public void CopyTargetObj() { if (TargetObject == null) { return; } CopyObj = UnityEngine.GameObject.Instantiate(TargetObject) as GameObject; var toggle = CopyObj.GetComponent <Toggle>(); if (toggle != null) { toggle.group = null; } CopyTrans = CopyObj.transform; // 需要特殊处理的MonoBehaviour var spec_list = SGameEngine.Pool <MonoBehaviour> .List.New(); // 把非UI控件的MonoBehaviour销毁掉 var remove_list = SGameEngine.Pool <MonoBehaviour> .List.New(); var db_guide_copy_behavior = DBManager.Instance.GetDB <DBGuideCopyBehavior>(); foreach (var com in CopyObj.GetComponentsInChildren <MonoBehaviour>(true)) { // 处理特殊的组件 TargetModelInfo target_model_info = com as TargetModelInfo; if (target_model_info != null) { spec_list.Add(target_model_info); continue; } // 因为UIItemNewSlot采用了延迟加载图标,直接拷贝会图标丢失,需要把UIItemNewSlot也拷贝进来并进行加载工作 UIItemNewSlot slot = com as UIItemNewSlot; if (slot != null) { UIItemNewSlot source_slot = TargetObject.GetComponentInChildren <UIItemNewSlot>(); if (source_slot != null) { slot.ItemInfo = source_slot.ItemInfo; slot.SetUI(); if (slot.ItemInfo != null && GoodsHelper.GetGoodsType(slot.ItemInfo.type_idx) == GameConst.GIVE_TYPE_SOUL) { slot.CanShowCircleBkg = true; slot.SetColor(false); slot.SetBgImageVisiable(false); slot.SetEffectRootVisiable(false); } } continue; } // ui控件的基类 if (com == null || com is ICanvasElement || com is Selectable) { continue; } // 其他需要添加的组件 string class_name = com.GetType().Name; if (db_guide_copy_behavior.ContainType(class_name)) { continue; } //有Alpha渐变时直接设为不透明 TweenAlpha tween = com as TweenAlpha; if (tween != null) { tween.value = 1; } // 剩余的组件添加到remove_list remove_list.Add(com); } for (int i = remove_list.Count - 1; i >= 0; i--) { //包含序列帧特效的GameObject直接删掉,因为有特效重叠不同步的问题,物品除外 if (remove_list[i] is UGUIFrameAnimation) { if (remove_list[i].transform.parent != null && remove_list[i].transform.parent.parent != null) { if (remove_list[i].transform.parent.parent.GetComponent <UIItemNewSlot>() == null) { UnityEngine.Object.DestroyImmediate(remove_list[i].gameObject); } } } else { UnityEngine.Object.DestroyImmediate(remove_list[i]); } } SGameEngine.Pool <MonoBehaviour> .List.Free(remove_list); var canvas = CopyObj.GetComponent <Canvas>(); if (canvas != null) { UnityEngine.Object.DestroyImmediate(canvas); } CopyObj.SetActive(false); CopyTrans.SetParent(Wnd.TargetTmpRoot); var local_pos = CopyTrans.localPosition; local_pos.z = 0f; CopyTrans.localPosition = local_pos; RectTransform copy_trans = CopyTrans.GetComponent <RectTransform>(); RectTransform traget_trans = TargetObject.GetComponent <RectTransform>(); UGUIMath.SetWidgetSize(copy_trans, traget_trans); CopyObj.SetActive(true); // 可能traget_trans的父亲节点有缩放 var rect_corner = new Vector3[4]; copy_trans.GetWorldCorners(rect_corner); float copy_rect_size_x = rect_corner[2].x - rect_corner[0].x; traget_trans.GetWorldCorners(rect_corner); float target_size_x = rect_corner[2].x - rect_corner[0].x; float scale = 1; if (copy_rect_size_x != 0) { scale = target_size_x / copy_rect_size_x; } Vector3 ori_scale = CopyTrans.localScale; CopyTrans.localScale = new Vector3(ori_scale.x * scale, ori_scale.y * scale, ori_scale.z * scale); for (int i = spec_list.Count - 1; i >= 0; i--) { var com = spec_list[i]; //StartLoadModel 函数中播放模型动作在object隐藏时会不生效,需延后调用 TargetModelInfo target_model_info = com as TargetModelInfo; if (target_model_info != null) { target_model_info.StartLoadModel(); } } SGameEngine.Pool <MonoBehaviour> .List.Free(spec_list); }