// --------------------------------------------------------------------- public string EndCapture(Texture2D[] SpriteTextures) { #if UNITY_WEBPLAYER Debug.LogError("In WEB_PLAYER mode, you cannot run the FXMaker."); Debug.Break(); return(null); #else int nTexSize = m_nResultTextureSize; int nCapSize = m_nResultCaptureSize; int nMaxCount = (nTexSize / nCapSize) * (nTexSize / nCapSize); int nTexHeight = (m_nSaveFrameCount <= nMaxCount / 2 ? nTexSize / 2 : nTexSize); Texture2D spriteTexture = new Texture2D(nTexSize, nTexHeight, TextureFormat.ARGB32, false); int nSaveCount = 0; for (int x = 0; x < spriteTexture.width; x++) { for (int y = 0; y < spriteTexture.height; y++) { spriteTexture.SetPixel(x, y, Color.black); } } for (int n = m_nSkipFrameCount; n < m_nTotalFrameCount; n++, nSaveCount++) { Color[] srcColors = SpriteTextures[n].GetPixels(0); if (m_ShaderType == SHADER_TYPE.ALPHA_BLENDED || m_ShaderType == SHADER_TYPE.ALPHA_BLENDED_MOBILE) { srcColors = NgAtlas.ConvertAlphaTexture(srcColors, true, FXMakerOption.inst.m_AlphaWeightCurve, 1, 1, 1); } spriteTexture.SetPixels(((nSaveCount) % (nTexSize / nCapSize)) * nCapSize, nTexHeight - (((nSaveCount) / (nTexSize / nCapSize) + 1) * nCapSize), nCapSize, nCapSize, srcColors); Object.DestroyImmediate(SpriteTextures[n]); } byte[] bytes = spriteTexture.EncodeToPNG(); string texBasePath; if (FXMakerLayout.m_bDevelopState) { texBasePath = FXMakerMain.inst.GetResourceDir(FXMakerMain.TOOLDIR_TYPE.SPRITE_TOOL); } else { texBasePath = FXMakerMain.inst.GetResourceDir(FXMakerMain.TOOLDIR_TYPE.SPRITE_USER); } string pathTexture = NgTexture.UniqueTexturePath(texBasePath, m_SelectedPrefabName); // save texture File.WriteAllBytes(pathTexture, bytes); AssetDatabase.Refresh(); NgTexture.ReimportTexture(pathTexture, m_bGUITexture, m_wrapMode, m_filterMode, m_anisoLevel, m_nSpriteTextureSizes[(int)m_fSpriteTextureIndex], m_SpriteTextureFormat[(int)m_fSpriteTextureFormatIdx]); Object.DestroyImmediate(spriteTexture); // Create Prefab if (m_bCreatePrefab) { string pathMaterial = CreateMaterial(pathTexture); Material newMat = (Material)AssetDatabase.LoadAssetAtPath(pathMaterial, typeof(Material)); GameObject newPrefab = (GameObject)Instantiate(FXMakerMain.inst.m_FXMakerSpritePrefab); newPrefab.transform.rotation = Quaternion.identity; newPrefab.GetComponent <Renderer>().material = newMat; NcSpriteAnimation spriteCom = newPrefab.GetComponent <NcSpriteAnimation>(); spriteCom.m_bBuildSpriteObj = true; spriteCom.m_nFrameCount = m_nSaveFrameCount; spriteCom.m_fFps = m_nResultFps; spriteCom.m_nTilingX = m_nResultTextureSize / m_nResultCaptureSize; spriteCom.m_nTilingY = (m_nSaveFrameCount <= spriteCom.m_nTilingX * spriteCom.m_nTilingX / 2 ? spriteCom.m_nTilingX / 2 : spriteCom.m_nTilingX); spriteCom.m_PlayMode = m_PlayMode; spriteCom.m_bLoop = m_bLoop; spriteCom.m_nLoopStartFrame = 0; spriteCom.m_nLoopFrameCount = spriteCom.m_nFrameCount; spriteCom.m_nLoopingCount = 0; spriteCom.m_bAutoDestruct = !m_bLoop; NcCurveAnimation curveCom = newPrefab.GetComponent <NcCurveAnimation>(); if (curveCom.GetCurveInfoCount() != 3) { Debug.LogError("FXMakerMain.inst.m_FxmSpritePrefab : curveCom Count Error!!!"); } curveCom.GetCurveInfo(0).m_bEnabled = false; // both curveCom.GetCurveInfo(1).m_bEnabled = false; // fadein curveCom.GetCurveInfo(2).m_bEnabled = false; // fadeout curveCom.m_bAutoDestruct = false; curveCom.m_fDurationTime = spriteCom.GetDurationTime(); if (m_bFadeIn && m_bFadeOut) { curveCom.GetCurveInfo(0).m_bEnabled = true; } else { if (m_bFadeIn) { curveCom.GetCurveInfo(1).m_bEnabled = true; } if (m_bFadeOut) { curveCom.GetCurveInfo(2).m_bEnabled = true; } } string basePath = AssetDatabase.GetAssetPath(FXMakerMain.inst.GetOriginalEffectPrefab()); string prefabPath = UniquePrefabPath(NgFile.TrimFilenameExt(basePath)); GameObject createPrefab = PrefabUtility.CreatePrefab(prefabPath, newPrefab); Destroy(newPrefab); // Create Thumb CreateSpriteThumb(createPrefab, pathTexture); AssetDatabase.SaveAssets(); return(prefabPath); } else { return(pathTexture); } #endif }
public override void OnInspectorGUI() { Rect rect; AddScriptNameField(m_Sel); m_UndoManager.CheckUndo(); m_FxmPopupManager = GetFxmPopupManager(); // test code // if (GUILayout.Button("Pause")) // FxmInfoIndexing.FindInstanceIndexing(m_Sel.transform, false).GetComponent<NcSpriteAnimation>().PauseAnimation(); // if (GUILayout.Button("Resume")) // FxmInfoIndexing.FindInstanceIndexing(m_Sel.transform, false).GetComponent<NcSpriteAnimation>().ResumeAnimation(); // -------------------------------------------------------------- bool bClickButton = false; EditorGUI.BeginChangeCheck(); { // DrawDefaultInspector(); m_Sel.m_fUserTag = EditorGUILayout.FloatField(GetCommonContent("m_fUserTag"), m_Sel.m_fUserTag); m_Sel.m_TextureType = (NcSpriteAnimation.TEXTURE_TYPE)EditorGUILayout.EnumPopup(GetHelpContent("m_TextureType"), m_Sel.m_TextureType); EditorGUILayout.Space(); if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.TileTexture) { if (GUILayout.Button(GetHelpContent("ConvertTo : TrimTexture"))) { m_Sel.m_NcSpriteFrameInfos = NgAtlas.TileToTrimTexture(m_Sel.renderer.sharedMaterial, m_Sel.m_nTilingX, m_Sel.m_nTilingY, 0, m_Sel.m_nFrameCount, 4096); if (m_Sel.m_NcSpriteFrameInfos != null) { m_Sel.m_TextureType = NcSpriteAnimation.TEXTURE_TYPE.TrimTexture; } } if (GUILayout.Button(GetHelpContent("ExportTo : SplitTexture"))) { string path = FXMakerCapture.GetExportSlitDir(); path = NgAtlas.ExportSplitTexture(path, m_Sel.renderer.sharedMaterial.mainTexture, m_Sel.m_nTilingX, m_Sel.m_nTilingY, 0, m_Sel.m_nFrameCount); if (path != "") { Debug.Log(path); EditorUtility.OpenWithDefaultApp(path); } } } else if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.TrimTexture) { if (GUILayout.Button(GetHelpContent("ExportTo : SplitTexture"))) { string path = FXMakerCapture.GetExportSlitDir(); path = NgAtlas.ExportSplitTexture(path, m_Sel.renderer.sharedMaterial.mainTexture, m_Sel.m_NcSpriteFrameInfos); if (path != "") { Debug.Log(path); EditorUtility.OpenWithDefaultApp(path); } } } else if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.SpriteFactory) { } EditorGUILayout.Space(); if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.TileTexture) { m_Sel.m_nTilingX = EditorGUILayout.IntField(GetHelpContent("m_nTilingX"), m_Sel.m_nTilingX); m_Sel.m_nTilingY = EditorGUILayout.IntField(GetHelpContent("m_nTilingY"), m_Sel.m_nTilingY); } else if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.TrimTexture) { m_Sel.m_MeshType = (NcSpriteFactory.MESH_TYPE)EditorGUILayout.EnumPopup(GetHelpContent("m_MeshType"), m_Sel.m_MeshType); m_Sel.m_AlignType = (NcSpriteFactory.ALIGN_TYPE)EditorGUILayout.EnumPopup(GetHelpContent("m_AlignType"), m_Sel.m_AlignType); m_Sel.m_bTrimCenterAlign = EditorGUILayout.Toggle("m_bTrimCenterAlign", m_Sel.m_bTrimCenterAlign); } else if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.SpriteFactory) { m_Sel.m_NcSpriteFactoryPrefab = (GameObject)EditorGUILayout.ObjectField(GetHelpContent("m_NcSpriteFactoryPrefab"), m_Sel.m_NcSpriteFactoryPrefab, typeof(GameObject), false, null); // -------------------------------------------------------------- EditorGUILayout.Space(); rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(m_fButtonHeight)); { if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 2, 0, 1), GetHelpContent("Select SpriteFactory"), (m_FxmPopupManager != null))) { m_FxmPopupManager.ShowSelectPrefabPopup(m_Sel, true, 0); } if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 2, 1, 1), GetHelpContent("Clear SpriteFactory"), (m_Sel.m_NcSpriteFactoryPrefab != null))) { bClickButton = true; m_Sel.m_NcSpriteFactoryPrefab = null; } GUILayout.Label(""); } EditorGUILayout.EndHorizontal(); // -------------------------------------------------------------- if (m_Sel.m_NcSpriteFactoryPrefab != null && m_Sel.m_NcSpriteFactoryPrefab.renderer != null && m_Sel.renderer) { if (m_Sel.m_NcSpriteFactoryPrefab.renderer.sharedMaterial != m_Sel.renderer.sharedMaterial) { m_Sel.UpdateFactoryMaterial(); } } // -------------------------------------------------------------- NcSpriteFactory ncSpriteFactory = (m_Sel.m_NcSpriteFactoryPrefab == null ? null : m_Sel.m_NcSpriteFactoryPrefab.GetComponent <NcSpriteFactory>()); if (ncSpriteFactory != null) { int nSelIndex = EditorGUILayout.IntSlider(GetHelpContent("m_nSpriteFactoryIndex"), m_Sel.m_nSpriteFactoryIndex, 0, ncSpriteFactory.GetSpriteNodeCount() - 1); if (m_Sel.m_nSpriteFactoryIndex != nSelIndex) { m_Sel.SetSpriteFactoryIndex(nSelIndex, false); } } m_Sel.m_MeshType = (NcSpriteFactory.MESH_TYPE)EditorGUILayout.EnumPopup(GetHelpContent("m_MeshType"), m_Sel.m_MeshType); m_Sel.m_AlignType = (NcSpriteFactory.ALIGN_TYPE)EditorGUILayout.EnumPopup(GetHelpContent("m_AlignType"), m_Sel.m_AlignType); m_Sel.m_bTrimCenterAlign = EditorGUILayout.Toggle("m_bTrimCenterAlign", m_Sel.m_bTrimCenterAlign); } m_Sel.m_PlayMode = (NcSpriteAnimation.PLAYMODE)EditorGUILayout.EnumPopup(GetHelpContent("m_PlayMode"), m_Sel.m_PlayMode, GUILayout.MaxWidth(Screen.width)); if (m_Sel.m_PlayMode != NcSpriteAnimation.PLAYMODE.SELECT) { m_Sel.m_fDelayTime = EditorGUILayout.FloatField(GetHelpContent("m_fDelayTime"), m_Sel.m_fDelayTime); } m_Sel.m_nStartFrame = EditorGUILayout.IntField(GetHelpContent("m_nStartFrame"), m_Sel.m_nStartFrame); m_Sel.m_nFrameCount = EditorGUILayout.IntField(GetHelpContent("m_nFrameCount"), m_Sel.m_nFrameCount); if (m_Sel.m_PlayMode == NcSpriteAnimation.PLAYMODE.SELECT) { m_Sel.m_nSelectFrame = EditorGUILayout.IntField(GetHelpContent("m_nSelectFrame"), m_Sel.m_nSelectFrame); } if (m_Sel.m_PlayMode != NcSpriteAnimation.PLAYMODE.RANDOM && m_Sel.m_PlayMode != NcSpriteAnimation.PLAYMODE.SELECT) { bool bOldLoop = m_Sel.m_bLoop; m_Sel.m_bLoop = EditorGUILayout.Toggle(GetHelpContent("m_bLoop"), m_Sel.m_bLoop); if (!bOldLoop && m_Sel.m_bLoop) { m_Sel.m_nLoopStartFrame = 0; m_Sel.m_nLoopFrameCount = m_Sel.m_nFrameCount; m_Sel.m_nLoopingCount = 0; } if (m_Sel.m_bLoop && m_Sel.m_PlayMode == NcSpriteAnimation.PLAYMODE.DEFAULT) { m_Sel.m_nLoopStartFrame = EditorGUILayout.IntField(" nLoopStartFrame", m_Sel.m_nLoopStartFrame); m_Sel.m_nLoopFrameCount = EditorGUILayout.IntField(" nLoopFrameCount", m_Sel.m_nLoopFrameCount); m_Sel.m_nLoopingCount = EditorGUILayout.IntField(" nLoopingCount", m_Sel.m_nLoopingCount); } if (m_Sel.m_bLoop == false || 0 < m_Sel.m_nLoopingCount) { m_Sel.m_bAutoDestruct = EditorGUILayout.Toggle(GetHelpContent("m_bAutoDestruct"), m_Sel.m_bAutoDestruct); } m_Sel.m_fFps = EditorGUILayout.FloatField(GetHelpContent("m_fFps"), m_Sel.m_fFps); } // check SetMinValue(ref m_Sel.m_nTilingX, 1); SetMinValue(ref m_Sel.m_nTilingY, 1); SetMinValue(ref m_Sel.m_fFps, 0.1f); SetMinValue(ref m_Sel.m_fDelayTime, 0); SetMaxValue(ref m_Sel.m_nStartFrame, m_Sel.GetMaxFrameCount() - 1); SetMinValue(ref m_Sel.m_nStartFrame, 0); SetMaxValue(ref m_Sel.m_nFrameCount, m_Sel.GetValidFrameCount()); SetMinValue(ref m_Sel.m_nFrameCount, 1); SetMaxValue(ref m_Sel.m_nSelectFrame, (0 < m_Sel.m_nFrameCount ? m_Sel.m_nFrameCount - 1 : m_Sel.m_nTilingX *m_Sel.m_nTilingY - 1)); SetMinValue(ref m_Sel.m_nSelectFrame, 0); SetMaxValue(ref m_Sel.m_nLoopStartFrame, m_Sel.m_nFrameCount - 1); SetMinValue(ref m_Sel.m_nLoopStartFrame, 0); SetMinValue(ref m_Sel.m_nLoopFrameCount, 0); SetMaxValue(ref m_Sel.m_nLoopFrameCount, m_Sel.m_nFrameCount - m_Sel.m_nLoopStartFrame); SetMinValue(ref m_Sel.m_nLoopingCount, 0); if (m_Sel.m_PlayMode != NcSpriteAnimation.PLAYMODE.RANDOM && m_Sel.m_PlayMode != NcSpriteAnimation.PLAYMODE.SELECT) { EditorGUILayout.TextField(GetHelpContent("DurationTime"), m_Sel.GetDurationTime().ToString()); } // Texture -------------------------------------------------------------- rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(150)); { GUI.Box(rect, ""); GUILayout.Label(""); Rect subRect = rect; // draw texture if (m_Sel.renderer != null && m_Sel.renderer.sharedMaterial != null && m_Sel.renderer.sharedMaterial.mainTexture != null) { int nClickFrameIndex; if (m_Sel.m_TextureType == NcSpriteAnimation.TEXTURE_TYPE.TileTexture) { if (DrawTileTexture(subRect, (m_Sel.m_PlayMode == NcSpriteAnimation.PLAYMODE.SELECT), m_Sel.renderer.sharedMaterial, m_Sel.m_nTilingX, m_Sel.m_nTilingY, m_Sel.m_nStartFrame, m_Sel.m_nFrameCount, m_Sel.m_nSelectFrame, out nClickFrameIndex)) { bClickButton = true; if (bClickButton && m_Sel.m_PlayMode == NcSpriteAnimation.PLAYMODE.SELECT) { m_Sel.m_nSelectFrame = nClickFrameIndex; } } } if (m_Sel.m_TextureType != NcSpriteAnimation.TEXTURE_TYPE.TileTexture) { if (DrawTrimTexture(subRect, (m_Sel.m_PlayMode == NcSpriteAnimation.PLAYMODE.SELECT), m_Sel.renderer.sharedMaterial, m_Sel.m_NcSpriteFrameInfos, m_Sel.m_nStartFrame, m_Sel.m_nFrameCount, m_Sel.m_nSelectFrame, out nClickFrameIndex)) { bClickButton = true; if (bClickButton && m_Sel.m_PlayMode == NcSpriteAnimation.PLAYMODE.SELECT) { m_Sel.m_nSelectFrame = nClickFrameIndex; } } } } } EditorGUILayout.EndHorizontal(); m_UndoManager.CheckDirty(); EditorGUILayout.Space(); // Remove AlphaChannel if (GUILayout.Button(GetHelpContent("Remove AlphaChannel"))) { NgAtlas.ConvertAlphaTexture(m_Sel.renderer.sharedMaterial, false, m_Sel.m_curveAlphaWeight, 1, 1, 1); } // AlphaWeight if ((m_Sel.m_curveAlphaWeight == null || m_Sel.m_curveAlphaWeight.length <= 0) && FXMakerOption.inst != null) { m_Sel.m_curveAlphaWeight = FXMakerOption.inst.m_AlphaWeightCurve; } if (m_Sel.m_curveAlphaWeight != null) { bool bHighLight = m_Sel.m_bNeedRebuildAlphaChannel; if (bHighLight) { FXMakerLayout.GUIColorBackup(FXMakerLayout.m_ColorHelpBox); } if (GUILayout.Button(GetHelpContent("Adjust the alpha channel with AlphaWeight"))) { m_Sel.m_bNeedRebuildAlphaChannel = false; NgAtlas.ConvertAlphaTexture(m_Sel.renderer.sharedMaterial, true, m_Sel.m_curveAlphaWeight, 1, 1, 1); // NgAtlas.ConvertAlphaTexture(m_Sel.renderer.sharedMaterial, m_Sel.m_curveAlphaWeight, m_Sel.m_fRedAlphaWeight, m_Sel.m_fGreenAlphaWeight, m_Sel.m_fBlueAlphaWeight); } if (bHighLight) { FXMakerLayout.GUIColorRestore(); } EditorGUI.BeginChangeCheck(); m_Sel.m_curveAlphaWeight = EditorGUILayout.CurveField(GetHelpContent("m_curveAlphaWeight"), m_Sel.m_curveAlphaWeight); if (EditorGUI.EndChangeCheck()) { m_Sel.m_bNeedRebuildAlphaChannel = true; } // m_Sel.m_fRedAlphaWeight = EditorGUILayout.Slider("", m_Sel.m_fRedAlphaWeight , 0, 1.0f); // m_Sel.m_fGreenAlphaWeight = EditorGUILayout.Slider("", m_Sel.m_fGreenAlphaWeight , 0, 1.0f); // m_Sel.m_fBlueAlphaWeight = EditorGUILayout.Slider("", m_Sel.m_fBlueAlphaWeight , 0, 1.0f); } EditorGUILayout.Space(); } // -------------------------------------------------------------- if ((EditorGUI.EndChangeCheck() || bClickButton) && GetFXMakerMain()) { OnEditComponent(); } // --------------------------------------------------------------------- if (GUI.tooltip != "") { m_LastTooltip = GUI.tooltip; } HelpBox(m_LastTooltip); }