using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.Rendering; namespace COM3D2.MeidoPhotoStudio.Plugin { internal class PropManager { private static bool cubeActive = true; public static bool CubeActive { get => cubeActive; set { if (value != cubeActive) { cubeActive = value; CubeActiveChange?.Invoke(null, EventArgs.Empty); } } } private static bool cubeSmall; public static bool CubeSmall { get => cubeSmall; set { if (value != cubeSmall) { cubeSmall = value; CubeSmallChange?.Invoke(null, EventArgs.Empty); } } } private static event EventHandler CubeActiveChange; private static event EventHandler CubeSmallChange; private List doguList = new List(); private DragType dragTypeOld = DragType.None; private DragType currentDragType = DragType.None; private bool showGizmos = false; private enum DragType { None, Move, Rotate, Scale, Delete, Other } public void Activate() { CubeSmallChange += OnCubeSmall; } public void Deactivate() { foreach (DragDogu dogu in doguList) { GameObject.Destroy(dogu.gameObject); } doguList.Clear(); CubeSmallChange -= OnCubeSmall; } public void Update() { if (Input.GetKeyDown(KeyCode.Space)) { // showGizmos = !showGizmos; // currentDragType = dragTypeOld = DragType.None; // UpdateDragType(); } if (CubeActive && (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.C) || Input.GetKey(KeyCode.D)) ) { currentDragType = DragType.Other; } else { currentDragType = DragType.None; } if (currentDragType != dragTypeOld) UpdateDragType(); dragTypeOld = currentDragType; } private void UpdateDragType() { bool dragPointActive = (currentDragType == DragType.Other); foreach (DragDogu dogu in doguList) { dogu.SetDragProp(showGizmos, dragPointActive, dragPointActive); } } private GameObject GetDeploymentObject() { GameObject go = GameObject.Find("Deployment Object Parent"); if (go == null) go = new GameObject("Deployment Object Parent"); return go; } public void SpawnObject(string assetName) { // TODO: Add a couple more things to ignore list GameObject dogu = null; if (assetName.StartsWith("mirror")) { Material mirrorMaterial = new Material(Shader.Find("Mirror")); dogu = GameObject.CreatePrimitive(PrimitiveType.Plane); Renderer mirrorRenderer = dogu.GetComponent(); mirrorRenderer.material = mirrorMaterial; mirrorRenderer.enabled = true; MirrorReflection2 mirrorReflection = dogu.AddComponent(); mirrorReflection.m_TextureSize = 2048; Vector3 localPosition = new Vector3(0f, 0.96f, 0f); dogu.transform.Rotate(dogu.transform.right, 90f); switch (assetName) { case "mirror1": dogu.transform.localScale = new Vector3(0.2f, 0.4f, 0.2f); break; case "mirror2": dogu.transform.localScale = new Vector3(0.1f, 0.4f, 0.2f); break; case "mirror3": localPosition.y = 0.85f; dogu.transform.localScale = new Vector3(0.03f, 0.18f, 0.124f); break; } dogu.transform.localPosition = localPosition; } else if (assetName.IndexOf(':') >= 0) { string[] assetParts = assetName.Split(':'); GameObject obj = GameMain.Instance.BgMgr.CreateAssetBundle(assetParts[0]); if (obj == null) { obj = Resources.Load("BG/" + assetParts[0]) as GameObject; } GameObject bg = GameObject.Instantiate(obj); int num = int.Parse(assetParts[1]); dogu = bg.transform.GetChild(num).gameObject; dogu.transform.SetParent(null); GameObject.Destroy(bg); bg.SetActive(false); } else { GameObject obj = GameMain.Instance.BgMgr.CreateAssetBundle(assetName); if (obj == null) obj = Resources.Load("Prefab/" + assetName) as GameObject; dogu = GameObject.Instantiate(obj) as GameObject; dogu.transform.localPosition = Vector3.zero; MeshRenderer[] meshRenderers = dogu.GetComponentsInChildren(); for (int i = 0; i < meshRenderers.Length; i++) { if (meshRenderers[i] != null) { meshRenderers[i].shadowCastingMode = ShadowCastingMode.Off; } } Collider collider = dogu.transform.GetComponent(); if (collider != null) collider.enabled = false; foreach (Transform transform in dogu.transform) { collider = transform.GetComponent(); if (collider != null) { collider.enabled = false; } } #region particle system experiment // if (asset.StartsWith("Particle/")) // { // ParticleSystem particleSystem = go.GetComponent(); // if (particleSystem != null) // { // ParticleSystem.MainModule main; // main = particleSystem.main; // main.loop = true; // main.duration = Mathf.Infinity; // ParticleSystem[] particleSystems = particleSystem.GetComponents(); // foreach (ParticleSystem part in particleSystems) // { // ParticleSystem.EmissionModule emissionModule = part.emission; // ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[emissionModule.burstCount]; // emissionModule.GetBursts(bursts); // for (int i = 0; i < bursts.Length; i++) // { // bursts[i].cycleCount = Int32.MaxValue; // } // emissionModule.SetBursts(bursts); // main = part.main; // main.loop = true; // main.duration = Mathf.Infinity; // } // } // } #endregion } if (dogu != null) { // TODO: Figure out why some props aren't centred properly // Doesn't happen in MM but even after copy pasting the code, it doesn't work :/ GameObject deploymentObject = GetDeploymentObject(); GameObject finalDogu = new GameObject(); dogu.transform.SetParent(finalDogu.transform, true); finalDogu.transform.SetParent(deploymentObject.transform, false); finalDogu.transform.position = new Vector3(0f, 0f, 0.5f); GameObject dragPoint = BaseDrag.MakeDragPoint( PrimitiveType.Cube, Vector3.one * 0.12f, BaseDrag.LightBlue ); DragDogu dragDogu = dragPoint.AddComponent(); dragDogu.Initialize(finalDogu); dragDogu.Delete += (s, a) => DeleteDogu(); dragDogu.SetDragProp(showGizmos, false, false); doguList.Add(dragDogu); dragDogu.DragPointScale = dragDogu.BaseScale * (CubeSmall ? 0.4f : 1f); } } private void DeleteDogu() { doguList.RemoveAll(dragDogu => { if (dragDogu.DeleteMe) { GameObject.Destroy(dragDogu.gameObject); return true; } return false; } ); } private void OnCubeSmall(object sender, EventArgs args) { foreach (DragDogu dogu in doguList) { dogu.DragPointScale = dogu.BaseScale * (CubeSmall ? 0.4f : 1f); } } } }