예제 #1
0
        public static bool BakeReflectionProbeSnapshot(PlanarReflectionProbe probe)
        {
            var rt           = ReflectionSystem.NewRenderTarget(probe);
            var bakedTexture = probe.bakedTexture as Texture2D;
            var assetPath    = string.Empty;

            if (bakedTexture != null)
            {
                assetPath = AssetDatabase.GetAssetPath(bakedTexture);
            }
            if (string.IsNullOrEmpty(assetPath))
            {
                assetPath = GetBakePath(probe);
            }

            if (bakedTexture == null || string.IsNullOrEmpty(assetPath))
            {
                bakedTexture       = new Texture2D(rt.width, rt.height, TextureFormat.RGBAHalf, true, false);
                probe.bakedTexture = bakedTexture;

                EditorUtility.SetDirty(probe);
            }

            ReflectionSystem.Render(probe, rt);

            var art = RenderTexture.active;

            RenderTexture.active = rt;
            bakedTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0, false);
            RenderTexture.active = art;

            WriteAndImportTexture(assetPath, bakedTexture);

            return(true);
        }
예제 #2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        DropdownAttribute dropdownAttribute = (DropdownAttribute)attribute;
        Type   itemType = dropdownAttribute.Type;
        object listObj  = ReflectionSystem.GetValue(property.serializedObject.targetObject, dropdownAttribute.ListPath);

        Debug.Log(listObj);


        var list = CastWholeList <Object>(listObj, typeof(Object));//FindList(property.serializedObject, dropdownAttribute.ListPath);

        string[] stringArray = ListToStringArray(list);
        Object   obj         = property.objectReferenceValue;

        #region Draw the list dropdown
        GUIContent dropdown = new GUIContent(property.name);

        int SelectedID    = FindSelectedID(list, obj);//Update the selectedID
        int newSelectedID = EditorGUILayout.Popup(dropdown, SelectedID, ListToStringArray(list));
        if (newSelectedID != SelectedID)
        {//changed
            SelectedID = newSelectedID;
            Object selectedObject = (Object)list[SelectedID];
            property.objectReferenceValue = selectedObject;
            //EditorUtility.SetDirty(property.serializedObject.targetObject);//repaint
            Debug.Log($"changed to {property.objectReferenceValue.name}");
        }

        #endregion
    }
 static void DidReloadScripts()
 {
     foreach (var probe in FindObjectsOfType <PlanarReflectionProbe>())
     {
         if (probe.enabled)
         {
             ReflectionSystem.RegisterProbe(probe);
         }
     }
 }
예제 #4
0
        public static bool BakePlanarReflectionProbe(PlanarReflectionProbe probe, string path)
        {
            var rt = ReflectionSystem.NewRenderTarget(probe);

            ReflectionSystem.Render(probe, rt);
            var target = new Texture2D(rt.width, rt.height, TextureFormat.RGBAHalf, false, true);
            var a      = RenderTexture.active;

            RenderTexture.active = rt;
            target.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0, false);
            RenderTexture.active = a;
            rt.Release();

            if (!WriteAndImportTexture(path, target))
            {
                return(false);
            }

            return(true);
        }
예제 #5
0
    public void Run()
    {
        object result = ReflectionSystem.GetValue(this, "testList[0][1]");

        if (result.GetType() == typeof(List <string>))
        {
            List <string> result1 = (List <string>)result;
            foreach (string str in result1)
            {
                Debug.Log($"result1 item: {str}");
            }
        }
        else
        {
            string result2 = (string)ReflectionSystem.GetValue(this, "testList[0][1]");
            Debug.Log($"result2: {result2}");
        }

        Debug.Log($"skillID of the first skill: {result}");
    }
예제 #6
0
        static void DrawGizmos_CaptureFrustrum(PlanarReflectionProbe d)
        {
            var viewerCamera = Camera.current;
            var c            = Gizmos.color;
            var m            = Gizmos.matrix;

            float            nearClipPlane, farClipPlane, aspect, fov;
            Color            backgroundColor;
            CameraClearFlags clearFlags;
            Vector3          capturePosition;
            Quaternion       captureRotation;
            Matrix4x4        worldToCameraRHS, projection;

            ReflectionSystem.CalculateCaptureCameraProperties(d,
                                                              out nearClipPlane, out farClipPlane,
                                                              out aspect, out fov, out clearFlags, out backgroundColor,
                                                              out worldToCameraRHS, out projection,
                                                              out capturePosition, out captureRotation, viewerCamera);

            Gizmos.DrawSphere(capturePosition, HandleUtility.GetHandleSize(capturePosition) * 0.2f);
            Gizmos.color = c;
        }
예제 #7
0
    public object[] GetParametersFromTarget()
    {
        string parameterPart = Target.Split(new[] { '(' }, 2)[1];             //"GetName(minecraft, getPlayer(world, uuid))"   ->   "minecraft, getPlayer(world, uuid))"

        parameterPart = parameterPart.Substring(0, parameterPart.Length - 1); //"minecraft, getPlayer(world, uuid))"   ->   "minecraft, getPlayer(world, uuid)"
        string[] stringParameterArray = SplitIgnoringSplitterInBrackets(parameterPart, ',');
        object[] result = new object[stringParameterArray.Length];
        for (int i = 0; i < stringParameterArray.Length; i++)
        {//turrning string array into object array
            string str         = stringParameterArray[i];
            Type   primaryType = DetectPrimaryTypeFromString(str);
            if (primaryType == typeof(string))
            {
                result[i] = str.Substring(1, str.Length - 2);//remove the quotes "
                continue;
            }
            else if (primaryType == typeof(char))
            {
                result[i] = str.Substring(1, str.Length - 2).ToCharArray()[0];//remove the quotes '
                continue;
            }
            else if (primaryType != null)
            {                                              //Parse if it is primary type
                result[i] = ParseToType(str, primaryType); //parse it from "3.53f" to 3.53(float)
                continue;
            }
            else
            {//It is not primary type, try object value
                object objValue = ReflectionSystem.GetValue(Master, str);
                if (objValue != null)
                {//it is object
                    result[i] = objValue;
                    continue;
                }
            }
            result[i] = null;
        }
        return(result);
    }
        static void DrawGizmos_CaptureFrustrum(PlanarReflectionProbeUI s, PlanarReflectionProbe d)
        {
            var viewerCamera = Camera.current;
            var c            = Gizmos.color;
            var m            = Gizmos.matrix;

            float            nearClipPlane, farClipPlane, aspect, fov;
            Color            backgroundColor;
            CameraClearFlags clearFlags;
            Vector3          capturePosition;
            Quaternion       captureRotation;
            Matrix4x4        worldToCameraRHS, projection;

            ReflectionSystem.CalculateCaptureCameraProperties(d,
                                                              out nearClipPlane, out farClipPlane,
                                                              out aspect, out fov, out clearFlags, out backgroundColor,
                                                              out worldToCameraRHS, out projection,
                                                              out capturePosition, out captureRotation, viewerCamera);

#if false
            // TODO: fix frustrum drawing

            var viewProj    = projection * worldToCameraRHS;
            var invViewProj = viewProj.inverse;

            var near = new[]
            {
                new Vector3(-1, -1, -1),
                new Vector3(-1, 1, -1),
                new Vector3(1, 1, -1),
                new Vector3(1, -1, -1),
            };

            var far = new[]
            {
                new Vector3(-1, -1, 1),
                new Vector3(-1, 1, 1),
                new Vector3(1, 1, 1),
                new Vector3(1, -1, 1),
            };

            for (var i = 0; i < near.Length; ++i)
            {
                var p = invViewProj * new Vector4(near[i].x, near[i].y, near[i].z, 1);
                var w = Mathf.Abs(p.w);
                near[i].Set(p.x / w, p.y / w, p.z / w);
            }

            for (var i = 0; i < far.Length; ++i)
            {
                var p = invViewProj * new Vector4(far[i].x, far[i].y, far[i].z, 1);
                var w = Mathf.Abs(p.w);
                far[i].Set(p.x / w, p.y / w, p.z / w);
            }

            Gizmos.color = k_GizmoCamera;
            for (var i = 0; i < 4; ++i)
            {
                Gizmos.DrawLine(near[i], near[(i + 1) % 4]);
                Gizmos.DrawLine(far[i], far[(i + 1) % 4]);
                Gizmos.DrawLine(near[i], far[i]);
            }
            Gizmos.matrix = m;
#endif

            Gizmos.DrawSphere(capturePosition, HandleUtility.GetHandleSize(capturePosition) * 0.2f);
            Gizmos.color = c;
        }
예제 #9
0
    public void TestMethodReflection()
    {
        object result = ReflectionSystem.GetValue(this, "SkillDatabase.Instance.FindSkillByID(\"GrassballSkill\").Cooldown");

        Debug.Log($"result: {result.ToString()}");
    }
예제 #10
0
 static public void Start()
 {
     ReflectionSystem.Prerun();
 }